Created
April 21, 2012 13:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?