$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - Add_menu_page not displaying the menu in class based plugin|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - Add_menu_page not displaying the menu in class based plugin

matteradmin8PV0评论
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();

For some reason the Games Plugin page is not displaying in the dashboard. Anyone know what I'm doing wrong?

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();

For some reason the Games Plugin page is not displaying in the dashboard. Anyone know what I'm doing wrong?

Share Improve this question asked Mar 10, 2019 at 21:01 EliEli 691 gold badge2 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

There's a spelling error on the $capability parameter:

$cabability = 'manage_options';

Here's the working code for the sake of completeness:

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();  
Post a comment

comment list (0)

  1. No comments so far