【问题标题】:wordpress plugin : call to undefined function add_menu_page() using oop phpwordpress 插件:使用 oop php 调用未定义的函数 add_menu_page()
【发布时间】:2023-03-07 22:36:01
【问题描述】:

你好,我是 wordpress 插件开发的新手,我最近使用程序 php 在我的仪表板中添加了一个菜单页面,它运行良好,但是当我跳转到 oop php 时,我遇到了这个问题“致命错误:未捕获的错误:调用未定义的函数 add_menu_page() " 我也遇到过同样的问题,但没有帮助我

`class abc_adding_page{
    public function addingpage(){
        add_menu_page('abcba_products' ,'abcba_products' ,'manage_options' ,'abcba_products', function(){} ,'dashicons-store' ,110);
        return $this ;
}
    public function hooking(){
        add_action('admin_menu' ,  array($this ,'addingpage'));
    }
    }

 $x = new abc_adding_page();

 $x->addingpage()->hooking();

【问题讨论】:

    标签: php wordpress wordpress-plugin-creation


    【解决方案1】:

    您不需要运行addingpage 方法。 WordPress 适用于钩子。只需添加一个钩子,当该功能的所有函数加载完成时,钩子的回调就会在需要的时间内运行。

    class abc_adding_page{
        public function addingpage(){
            add_menu_page('abcba_products' ,'abcba_products' ,'manage_options' ,'abcba_products', function(){} ,'dashicons-store' ,110);
        }
        public function hooking(){
            add_action('admin_menu' ,  array($this ,'addingpage'));
        }
    }
    
    $x = new abc_adding_page();
    
    $x->hooking();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-01
      • 2020-04-24
      • 2014-02-13
      • 2016-06-24
      • 1970-01-01
      • 1970-01-01
      • 2012-10-31
      • 2020-01-08
      相关资源
      最近更新 更多