WordPress.org

Ready to get started?Download WordPress

Forums

add parameters to the $callback function in wp_add_dashboard_widget (2 posts)

  1. saggybawlz
    Member
    Posted 4 years ago #

    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?

  2. miradev
    Member
    Posted 4 years ago #

    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>";
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.