2.8, add_submenu_page and class functions

View: New views
3 Messages — Rating Filter:   Alert me  

2.8, add_submenu_page and class functions

by Daniel Cameron-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey guys, it's been too long :)

I'm running into some issues when I want to use add_submenu_page with  
something like:
        array( $this, 'displayThisPage' ) )
for the function.

Strangely, the top menu works fine (since it's shared) but any  
subsequent sub_pages get an error[1].

For example,

add_menu_page( __( 'Options' ), __( 'Options' ), 'read', 'test',  
array( $this, 'displayBasePage' ) );
add_submenu_page( 'test', __( 'Test Description' ), __( 'Test  
Description' ), 'read', 'test', array( $this, 'displayBasePage' ) );
add_submenu_page( 'test', __( 'Sub Description' ), __( 'Sub  
Description' ), 'read', 'sub', array( $this, 'displaySubPage' ) );

If I wrap what's above inside an action of:



Cheers.



[1]
Warning: call_user_func_array() [function.call-user-func-array]: First  
argument is expected to be a valid callback, 'Array' was given in /
FULL/PATH/wp-includes/plugin.php on line 339




--


// Dan Cameron
SproutVenture // grow your business
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: 2.8, add_submenu_page and class functions

by chrisbliss18 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't see any problems with the code itself. The problem could be due
to another problem in the code elsewhere. Would you be able to send a
failing version of the code my way for me to test?

FYI: I recommend that you use the form of "array( &$this, 'function' )"
when passing an object's function. Passing $this by reference allows
PHP4 to play nicely. Otherwise, you'll run into really odd issues on PHP4.

Chris Jean
http://gaarai.com/
http://wp-roadmap.com/
http://dnsyogi.com/



Dan Cameron wrote:

> Hey guys, it's been too long :)
>
> I'm running into some issues when I want to use add_submenu_page with
> something like:
>     array( $this, 'displayThisPage' ) )
> for the function.
>
> Strangely, the top menu works fine (since it's shared) but any
> subsequent sub_pages get an error[1].
>
> For example,
>
> add_menu_page( __( 'Options' ), __( 'Options' ), 'read', 'test',
> array( $this, 'displayBasePage' ) );
> add_submenu_page( 'test', __( 'Test Description' ), __( 'Test
> Description' ), 'read', 'test', array( $this, 'displayBasePage' ) );
> add_submenu_page( 'test', __( 'Sub Description' ), __( 'Sub
> Description' ), 'read', 'sub', array( $this, 'displaySubPage' ) );
>
> If I wrap what's above inside an action of:
>
>
>
> Cheers.
>
>
>
> [1]
> Warning: call_user_func_array() [function.call-user-func-array]: First
> argument is expected to be a valid callback, 'Array' was given in
> /FULL/PATH/wp-includes/plugin.php on line 339
>
>
>
>
_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers

Re: 2.8, add_submenu_page and class functions

by Daniel Cameron-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> The problem could be due to another problem in the code elsewhere.

Figures, something very small made the me think it was something it  
clearly wasn't. Turns out I had:

add_action ( '_admin_menu'

Strange how the underscore worked fine in 2.7 but 2.8 bombed and made  
me think it was something mroe complicated than a simple mistake on my  
part.

Thanks.


_______________________________________________
wp-hackers mailing list
wp-hackers@...
http://lists.automattic.com/mailman/listinfo/wp-hackers