Passing Arguments to Widget

  1. kenneth.howe

    It'd be great to be able to pass arguments to a widget. So, I already did it. In wp-includes/widgets.php:

    Replace the WP_Widget_Factory->register function:

    function register($widget_class, $args) {
    		$this->widgets[$widget_class] = & new $widget_class($args);

    Replace the register_widget function (around line 428):

    function register_widget($widget_class, $args) {
    	global $wp_widget_factory;
    	$wp_widget_factory->register($widget_class, $args);

    It'd be great if WordPress added this to the abilities so we can update our installation as new releases are added.

    Posted: 6 years ago #
  2. Ipstenu (Mika Epstein)
    Lead Plugin Wrangler

    To what end are you thinking of using the arguments? I'm curious to see your use case.

    Posted: 6 years ago #
  3. Gundars

    Clever, but I would like to see example in code as well.

    Posted: 6 years ago #
  4. Tien Nguyen

    Cool man. This will help we create bulk widgets with 1 class declaration. Good work.

    Posted: 2 years ago #
  5. Tien Nguyen

    Finally, this is my solution:

    global $wp_widget_factory;
    $wp_widget_factory->widgets[$id] = new WP_Custom_Widget($args);
    Posted: 2 years ago #

RSS feed for this topic


You must log in to post.

  • Rating

    3 Votes
  • Status

    This idea is under consideration