[英]wordpress plugin : Call to undefined function add_menu_page()
I am working on a wordpress plugin and i decided to use OOP instead of functional programming,however;I am receiving this weird error:我正在研究 wordpress 插件,我决定使用 OOP 而不是函数式编程,但是;我收到了这个奇怪的错误:
Error Message:错误信息:
Call to undefined function add_menu_page() while am pretty sure everything is working as intended调用未定义的 function add_menu_page() 虽然我很确定一切都按预期工作
The Code:编码:
class bdmin{
public function __construct(){
add_action('admin_menu', $this->create_admin_menu());
}
public function create_admin_menu(){
// Create NEW top-level menu
add_menu_page('bdmin Settings', 'bdmin Settings', 'administrator', __FILE__, array( &$this, 'create_admin_page'));
// Register our Settings
add_action( 'admin_init', $this->register_admin_settings() );
}
}
and i initiate the code with $admin = new bdmin();
我用
$admin = new bdmin();
启动代码
Best Regards此致
This should remove the error:这应该消除错误:
<?php
if(!empty($value['id'])) {
class bdmin{
public function __construct(){
add_action('admin_menu', $this->create_admin_menu());
}
public function create_admin_menu(){
// Create NEW top-level menu
add_menu_page('bdmin Settings', 'bdmin Settings', 'administrator', __FILE__, array( &$this, 'create_admin_page'));
// Register our Settings
add_action( 'admin_init', $this->register_admin_settings() );
}
}
}
?>
To solve this problem all I needed to do is invoke a function named add_action
with these parameters.为了解决这个问题,我需要做的就是使用这些参数调用一个名为
add_action
的 function。
add_action('admin_menu', array( &$this , 'create_admin_menu'));
Make sure you include the header file at the top so you can make WP function calls确保在顶部包含 header 文件,以便进行 WP function 调用
<?php require('{correct_path}/wp-blog-header.php');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.