Object of class GBL_Extras could not be be converted to string

I try to get my plugin for WordPress working but I stand in front of a wall.

My Problem is that if I finally call my class GBL_Extras the error occured:

Read More

Catchable fatal error: Object of class GBL_Extras could not be converted to string in /wp-includes/functions.php on line 1592

I don’t figure out why this is happen. If I delete the add_submenu_page methods the class render correctly, but I didn’t do a mistake there.
If read many other articles about same problems but I can’t adapt their problem with this error to my project.

Is there anyone who can bring a little bit light in the darkness?

My Code:

<?php       
// don't load directly
if ( ! defined( 'ABSPATH' ) ) {
    die( '-1' );
}

if ( ! class_exists( 'GBL_Extras' ) ) {
    class GBL_Extras {  
        private static $_instance;

        private function __construct() {
            // Add hooks
            add_action( 'network_admin_menu', array( $this, 'init' ));
        }

        public static function getInstance() {
            if ( ! ( self::$_instance instanceof self ) ) {
                self::$_instance = new self();
            }

            return self::$_instance;
        }

        public function init() {            
            add_menu_page( 'Extrawünsche', 'Extrawünsche', 'manage_options', 'gbl_extras_settings');
            add_submenu_page( 'gbl_extras_settings', 'Alle Extrawünsche', 'Alle Extrawünsche', 'manage_options', array( $this, 'backendRenderExtras'));
            add_submenu_page( 'gbl_extras_settings', 'Kategorien', 'Kategorien', 'manage_options', 'gbl_extras_categories', array( $this, 'backendRenderCategories'));
        }

        public function backendRenderExtras() {
            ?>
            <div class="wrap">
                <div id="icon-users" class="icon32"><br/></div>
                <h2>Extrawünsche</h2>
            </div>
            <?php
        }

        public function backendRenderCategories() {
            ?>
            <div class="wrap">
                <h2>Kategorien</h2>
            </div>
            <?php
        }
    }
    $gbl_manager = GBL_Extras::getInstance();
}

?>

Related posts

1 comment

  1. Looks like your first add_submenu_page() call is missing the $menu_slug argument. Compare the end of the two calls:

    'manage_options', array( $this, 'backendRenderExtras'));
    

    and

    'manage_options', 'gbl_extras_categories', array( $this, 'backendRenderCategories'));
    

    The second one looks correct.

Comments are closed.