• Hello Community,

    I need to pass some Params to “my_callback”:
    <?php add_meta_box( $id, $title, ‘my_callback’, $page, $context, $priority ); ?>

    First try was something like this:

    function my_callback() {
    global $params;
    }
    
    function add_my_meta_box() {
    global $param;
    $param = 'somevalue';
    add_meta_box( $id, $title, <strong>'my_callback'</strong>, $page, $context, $priority );
    }

    Did not work…

    Next try was to wrap it up in a Class to pass the params like
    $this->param = 'somevalue';
    Good plan, but when it came to my_callback, I tried something like

    'my_class::my_callback' or
    array ($this, 'my_callback') or
    '$this->my_callback()'

    Yes, I know, some things I tried are stupid, but I did… so what…

    I finally came up with

    $_SESSION['MYPARAM'] = 'somevalue';

    At least, it works. But I don′t like it.
    Is there any way to pass params to my_callback, or use add_meta_box from within a class?

    Thanks in advance!

    Best regards

    Udo

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter udo-kupsch

    (@udo-kupsch)

    Found it.
    The Problem was not in the script, but about 1 meter in front of my monitor.
    If anyone else has this problem, try this:
    <?php add_meta_box( id, title, array(&$this, 'new_meta_boxes'), page, context, priority); ?>

    Shame on me for not knowing how to set a classmethod as callback…

    I’m having trouble wrapping my head around this…

    Lets say I have the following:

    add_meta_box( $id, $title, $callback=’display_box’, $page, $context, $priority );

    function display_box(){
    //Stuff happens here…
    }

    and I want to pass an object to display_box called $box. How would I do that?

    I tried replacing the callback with array(&$box,’display_box’) but that didn’t work. Error log says “First argument is expected to be a valid callback” aka a string?

    See https://www.ads-software.com/support/topic/379614 for how to do this since v2.8.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add_meta_box : Pass Params to Callback?’ is closed to new replies.