Support » Plugins » add parameters to the $callback function in wp_add_dashboard_widget

  • Is it possible to add parameters to the name of the callback function used in wp_add_dashboard_widget() function.

    I have wp_add_dashboard_widget($widgetName, $widgetTitle, ‘widgetContent’, ‘widgetSetup’);

    I need to pass some parameters to the widgetContent() function. How can this be done?

Viewing 1 replies (of 1 total)
  • I’ve also been looking to see if there is a proper way of doing this.

    I came up with something bodgy that doesn’t scale well (beware typos, as I’m typing this from memory):

    class WidgetHandler{
      var $option;
      function WidgetHandler($option = array()){
        $this->option = (object)$option;
      }
    
      function extra_dashboard_widget_one(){
        real_dashboard_callback_function($this->option);
      }
    }
    
    add_action('wp_dashboard_setup', 'my_dashboard_widgets'){
      $someoptions = (object)array('mysetting'=>'myval');
      $bodgyWidget = new WidgetHandler($someoptions);
      wp_add_dashboard_widget('extra_dashboard_widget_one', 'Widget One',  array(&$bodgyWidget, 'extra_dashboard_widget_one'));
    }
    
    function real_dashboard_callback_function($option){
      $foo = print_r($option,1);
      echo "<pre>$foo</pre>";
    }

Viewing 1 replies (of 1 total)
  • The topic ‘add parameters to the $callback function in wp_add_dashboard_widget’ is closed to new replies.