Add_Menu_Page不在基于类的插件中显示菜单

时间:2019-03-10 作者:Eli

class Cosmo_Games {



public function __construct() {

        add_action(\'admin_menu\', array($this, \'create_plugin_settings_page\'));
    }

    public function create_plugin_settings_page() {
        $page_title = \'Game Settings\';
        $menu_title = \'Games Plugin\';
        $cabability = \'manage_options\';
        $slug = \'cg_settings\';
        $callback = array($this, \'plugin_settings_page_content\');
        $icon = \'dashicons-admin-plugins\';
        $position = 100;
        add_menu_page($page_title, $menu_title, $capability, $slug, $callback, $icon, $position);
    }

    public function plugin_settings_page_content() {
        ?>

        <div class="wrap">
            <h2>My Awesome Settings Page</h2>
            <form method="post" action="options.php">
                <?php
                    settings_fields( \'cg_settings\' );
                    do_settings_sections( \'smashing_fields\' );
                    submit_button();
                ?>
            </form>
        </div> 

        <?php
    }

}

new Cosmo_Games();
由于某些原因,游戏插件页面没有显示在仪表板中。有人知道我做错了什么吗?

1 个回复
最合适的回答,由SO网友:Dave Romsey 整理而成

上有一个拼写错误$capability 参数:

$cabability=\'manage\\u options\';

为了完整起见,下面是工作代码:

class Cosmo_Games {
    public function __construct() {
        add_action(\'admin_menu\', array($this, \'create_plugin_settings_page\'));
    }

    public function create_plugin_settings_page() {
        $page_title = \'Game Settings\';
        $menu_title = \'Games Plugin\';
        $capability = \'manage_options\';
        $slug = \'cg_settings\';
        $callback = array($this, \'plugin_settings_page_content\');
        $icon = \'dashicons-admin-plugins\';
        $position = 100;
        add_menu_page($page_title, $menu_title, $capability, $slug, $callback, $icon, $position);
    }

    public function plugin_settings_page_content() { ?>
        <div class="wrap">
            <h2>My Awesome Settings Page</h2>
            <form method="post" action="options.php">
                <?php
                    settings_fields( \'cg_settings\' );
                    do_settings_sections( \'smashing_fields\' );
                    submit_button();
                ?>
            </form>
        </div><?php
    }
}

new Cosmo_Games();  

相关推荐

Nginx/wordpress站点-增加php.ini max_ecution_time=600不起作用

我正在WordPress网站上测试我的PHP限制,并不断获得504网关超时。我正在更改php中的max\\u execution\\u时间。ini以反映600的值。然后重新启动,当我测试PHP限制时,它会给我一个504网关超时。在检查php-i时,我得到以下结果;最大执行时间=>0=>0ini文件指向/etc/php/7.0/cli,这就是我正在配置的文件。联系他们声明的支持;该命令检查整个php ini设置,而不是应用程序。网关错误可能是由于配置设置中的错误造成的。尝试验证配置文件并检查错误