Question

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

Was it helpful?

Solution

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'
        );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top