https://github.com/reduxframework/widget-overload
register a widget with arguments
https://github.com/reduxframework/widget-overload
Last synced: about 2 months ago
JSON representation
register a widget with arguments
- Host: GitHub
- URL: https://github.com/reduxframework/widget-overload
- Owner: reduxframework
- Created: 2014-12-06T04:19:42.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-12-06T04:28:58.000Z (over 10 years ago)
- Last Synced: 2025-01-13T10:51:51.875Z (3 months ago)
- Size: 141 KB
- Stars: 0
- Watchers: 9
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
widget-overload
===============register a widget with arguments
Extends the WP_Widget_Factory class by overloading the register method to allow for the passing params.
Place the following in your widget PHP file.
```php
class Extend_WP_Widget_Factory extends WP_Widget_Factory {
function register($widget_class, $param = null) {
$this->widgets[$widget_class] = new $widget_class($param);
}
}
```Register the widget as follows:
```php
add_action ( 'widgets_init', 'load_widget' , 0 );function load_widget () {
$param = array('one' => 'value one', 'two' => 'value 2');$extend = new Extend_WP_Widget_Factory();
$extend->register('MyWidgetName', $param);
}
```Then to use it:
```php
class MyWidgetName extends WP_Widget {public function MyWidgetName ($param) {
extract ($param);
echo $one;
echo $two;// do widget set up here, etc, etc.
}
}
```