1
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?

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();  
  • Happens to all of us. :) Took me longer than I'd like to admit to notice it. – Dave Romsey Mar 10 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.