• Resolved GuerrillaCode

    (@guerrillacode)


    Hello. I am having an issue with add_menu_page(). My Page output is not showing, where it should be I am getting an error:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /home/content/45/8909445/html/clients/ereading/wp-includes/plugin.php on line 470

    I know add_action() uses PHP’s native call_user_func_array() so I guess that might have something to do with it. Below is my code for creating the menu page and the page output function (Currently I just wanted to echo some text):

    public static function register_wpidSwiper_menu_page() {
                add_menu_page('iDangerous Swiper Slides', 'Homepage Slides', 'manage_options',
                        'wp_idangerous_swiper', array( $this, 'admin_page_output'),
                            plugins_url( 'wp-idangerous-swiper/img/swiper-icon.png' ));
            }
    
            public function admin_page_output() {
                //Create markup for admin page
                echo "Hello iDangerous Swiper";
            }

    I am calling this in my classes constructor:

    public function __construct() {
                add_action( 'admin_menu', array( $this, 'register_wpidSwiper_menu_page' ) );
            }

    My menu item appears in the side menu, with my custom icon, but when I click to go to the page the page displays the error I mentioned above instead of the string I echo in my admin_page_output() method.

    Anyone know where this is going wrong for me?

    Thanks!
    Isaac

Viewing 1 replies (of 1 total)
  • Thread Starter GuerrillaCode

    (@guerrillacode)

    Okay, I fixed my own error.

    The problem was that I was using a static method, and inside a static function $this does not exist.

    Simply had to make the function non-static like so:

    public function register_wpidSwiper_menu_page() {
        //code here
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Trouble with add_menu_page function’ is closed to new replies.