WordPress和对待定义涵数add

I recently got into WordPress plugin development and I would like to add a menu page (the links in the left hand side menu). Previous SO questions and the WordPress codex say that it's as simple as calling:

add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );

However when I try this in my plugin setup file it tells me that the function is undefined:

PHP Fatal error: Call to undefined function add_menu_page()

This seems like a very simple thing to do according to the documentation but I am totally baffled. Any help would be really appreciated :)

处理计划方案

I don't know how your code looks but this is how I just tested and it worked:

add_action('admin_menu', 'my_menu');
function my_menu() {
 add_menu_page('My Page Title', 'My Menu Title', 'manage_options', 'my-page-slug', 'my_function');
function my_function() {
 echo 'Hello world!';

Take a look here


我非常近刚开始科学研究WordPress软件,我觉得加上一个莱单网页页面(左边莱单中的连接)。以前的SO难题和WordPress Codex都说它如同启用一样简易:



 add_menu_page($ page_title,$ menu_title,$ capability, $ menu_slug,$ function,$ icon_url,$ position); 


可是,当我们在软件安裝文档中试着应用此涵数时,它告知我该涵数待定义:



 PHP致命性不正确:启用待定义涵数add_menu_page()


依据文本文档,这好像是一件十分简易的事儿,但我彻底觉得疑惑。一切协助将不敌感谢:)


处理计划方案

我不会了解您的编码看上去怎样,但就是我不久开展的检测和它合理:



 add_action('admin_menu','my_menu'); 

涵数my_menu(){
add_menu_page(我的网页页面题目,我的莱单题目, manage_options, my-page-slug, my_function);
}

function my_function(){
echo‘Hello world!’;
}


在这里里看一下