WordPress-Plugin-Boilerplate icon indicating copy to clipboard operation
WordPress-Plugin-Boilerplate copied to clipboard

Added shortcode support

Open garretthunter opened this issue 7 years ago • 4 comments

This is an old suggestion that follows this boilerplate's model.

garretthunter avatar Feb 26 '18 04:02 garretthunter

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();
}

FreedomRings avatar Feb 28 '18 05:02 FreedomRings

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

dojoVader avatar Mar 14 '18 10:03 dojoVader

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

jscottsf avatar Oct 04 '18 18:10 jscottsf

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

smileBeda avatar Jul 05 '21 14:07 smileBeda