[wp-hackers] 2.8, add_submenu_page and class functions

Chris Jean gaarai at gaarai.com
Thu Jun 11 18:24:58 GMT 2009


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


More information about the wp-hackers mailing list