问题描述
我正在尝试为 wordpress 编写一个插件。我是从这个视频开始的。 Boilerplate Wordpress Plugin Development Tutorials
第34课写了前端部分,但是当我激活插件时,所有页面的内容都消失了。我该怎么办?
当我将以下几行转换为注释时,问题就解决了。如果我这样做,我无法控制插件特定页面。
$this->loader->add_filter( 'page_template',$plugin_public,'our_own_custom_page_template');
add_shortcode("render-my-content",array($plugin_public,"load_book_tool_content"));
$this->loader->add_action("wp_ajax_public_ajax_request","handle_ajax_request_public");
$this->loader->add_action("wp_ajax_nopriv_public_ajax_request","handle_ajax_request_public");
所有代码
private function define_public_hooks() {
$plugin_public = new collocation_Public( $this->get_plugin_name(),$this->get_version() );
$this->loader->add_action( 'wp_enqueue_scripts','enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts','enqueue_scripts' );
// filter for page template
// Problem line is here... add_filter('page_template')
$this->loader->add_filter( 'page_template','our_own_custom_page_template');
add_shortcode("render-my-content","load_book_tool_content"));
// this is for login case
$this->loader->add_action("wp_ajax_public_ajax_request","handle_ajax_request_public");
// this is for not logged in
$this->loader->add_action("wp_ajax_nopriv_public_ajax_request","handle_ajax_request_public");
}
public function our_own_custom_page_template(){
global $post;
if($post->post_name == "book_tool"){
$page_template = BOOKS_MANAGEMENT_TOOL_PLUGIN_PATH."public/partials/book-tool-layout.PHP";
}
return $page_template;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)