WordPress-Plugin-Boilerplate
WordPress-Plugin-Boilerplate copied to clipboard
Added shortcode support
This is an old suggestion that follows this boilerplate's model.
I can confirm that this (net of the 3 commits) works VERY well. I am now using it in production. I highly recommend the merge into master.
My suggestion is to add the following:
class-plugin-name.php in define_public_hooks
// Create a short code for the plugin's user in the form: [my_shortcode]
$this->loader->add_shortcode( 'my_shortcode', $plugin_public, 'public_shortcode' );
class-plugin-name-public.php
public function public_shortcode( $atts, $content = null ) {
ob_start();
include_once( 'partials/'.$this->plugin_name.'-public-display.php' );
return ob_get_clean();
}
I literally wrote something like this in mine to allow render of templates in the admin and public. I will make a Pull Request, later on it makes rendering easier
Love this, tho does it follow the recommended practice of registering the shortcode on the init action hook? Seems this may register it earlier?
https://developer.wordpress.org/plugins/shortcodes/basic-shortcodes/#in-a-plugin
This has been added to development branch of new, actively maintained fork https://github.com/TukuToi/better-wp-plugin-boilerplate Pending testing. The Source was taken from https://github.com/DevinVinson/WordPress-Plugin-Boilerplate/pull/549