Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Created April 21, 2012 13:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codearachnid/2437027 to your computer and use it in GitHub Desktop.
Save codearachnid/2437027 to your computer and use it in GitHub Desktop.
Extend the WP_Widget_Factory class by overloading the register method to allow for passing params
<?php
/*
*
* Extends the WP_Widget_Factory class by overloading the register method to allow for passing params
*
*/
Class Extend_WP_Widget_Factory extends WP_Widget_Factory {
// Overload register($widget_class) with ability to pass parameters into widgets
function register($widget_class, $param = null) {
$this->widgets[$widget_class] = new $widget_class($param);
}
}
Copy link

ghost commented Sep 24, 2014

This is exactly what I want to do, has 3 widgets which differ only by name, while everything else is equal. I tried your code and it seems to work, it's ok to steal it and use in my function.php without something goes wrong in wordpress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment