Why are my shortcodes not working in the plugin boilerplate?

I would like to add my shortcodes from a separate file within my plugin, generated by the WP Plugin Boilerplate. I have the following codes:

in class-PLUGIN_NAME.php:

public function __construct() {
if ( defined( ‘PLUGIN_NAME_VERSION’ ) ) {
$this->version = PLUGIN_NAME_VERSION;
} else {
$this->version = ‘1.0.0’;
}
$this->plugin_name = ‘PLUGIN_NAME’;

$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_public_hooks();
$this->define_shortcodes();

}

private function define_shortcodes(){

$plugin_shortcodes = new PLUGIN_NAME_Shortcodes( $this->get_plugin_name(), $this->get_version() );

$this->loader->add_shortcode( ‘event-create’, $plugin_shortcodes, ‘event_create’ );

}

in class-PLUGIN-NAME-loader.php

protected $shortcodes;

public function add_shortcode( $tag, $component, $callback) {
$this->shortcodes = $this->add( $this->shortcodes, $tag, $component, $callback );
}

public function run() {
foreach ( $this->shortcodes as $hook ) {
add_shortcode( $hook[‘hook’], array( $hook[‘component’], $hook[‘callback’] ) );
}
}

And in class-PLUGIN_NAME-Shortcodes.php:

public static function event_create(){
echo “Hello, world!”;
}

Then when I view a page that contains the tag [event-create], I get an error saying do_shortcode_tag was called incorrectly. Attempting to parse a shortcode without a valid callback: event-create

What am I doing wrong?

Read more here:: Why are my shortcodes not working in the plugin boilerplate?

Leave a Reply

Your email address will not be published. Required fields are marked *