我想从我的插件中的一个单独的文件添加我的短代码,由WP插件Boilerplate生成。我有以下代码:
在类-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(){
$shortcodes_class = new PLUGIN_NAME_Shortcodes( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_shortcode( 'event-create', $shortcodes_class, 'event_create' );
}
在类-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'] ) );
}
}
在课堂上PLUGIN_NAME-Shortcodes.php:
public static function event_create(){
echo "Hello, world!";
}
然后,当我查看包含标记[event-create]的网页时,收到错误消息do_shortcode_tag was called incorrectly. Attempting to parse a shortcode without a valid callback: event-create
我做错了什么?