0

Situation

I got a class where i add a meta box to the post edit screen.

EDIT: This is the working version now

/**
 * Calls the class on the post edit screen
 */
function call_someClass() 
{
    return new someClass();
}
if ( is_admin() )
    add_action( 'load-post.php', 'call_someClass' );

/** 
 * The Class
 */
class someClass
{
    public function __construct()
    {
        add_action( 'add_meta_boxes', array( &$this, 'add_meta_box' ) );
    }

    /**
     * Adds the meta box container
     */
    public function add_meta_box( /* $args */ )
    {
        add_meta_box( 
             'post_format_box'
            ,__( 'Post Format Content', self::LANG )
            ,array( &$this, 'render' )
            ,'post' 
            ,'advanced'
            ,'high'
        );
    }


    /**
     * Render Meta Box content
     */
    public function render( /* $args */ ) 
    {
        return '<h1>TEST ME NOW</h1>';
    }
}

Problem

The meta box is showing, and the meta box callback functions output get's rendered inside my meta box... but inside an error message. Seems that i'm too tired to get around this:

Error Message (exact display as in the meta box)

Warning: call_user_func() expects parameter 1 to be a valid callback, function ' TEST ME NOW ' not found or invalid function name in R:\development\xampp\htdocs\wordpress\wp-admin\includes\template.php on line 963

1 Answer 1

4

Using classes like you are, your callback function is implemented wrong:

add_meta_box( 
             'post_format_box'
            ,__( 'Post Format Content', self::LANG )
            ,@$this->render()
            ,'post' 
            ,'advanced'
            ,'high'
        );

Should be:

add_meta_box( 
             'post_format_box'
            ,__( 'Post Format Content', self::LANG )
            ,array($this, 'render')
            ,'post' 
            ,'advanced'
            ,'high'
        );
1
  • omg. thanks. working all day inside the class and ... so (...) +1 & solution.
    – kaiser
    Apr 14, 2011 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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