WP_Widget_Factory::register
Registers a widget subclass.
Method of the class: WP_Widget_Factory{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WP_Widget_Factory = new WP_Widget_Factory(); $WP_Widget_Factory->register( $widget );
- $widget(string|WP_Widget) (required)
- Either the name of a
WP_Widgetsubclass or an instance of aWP_Widgetsubclass.
Changelog
| Since 2.8.0 | Introduced. |
| Since 4.6.0 | Updated the $widget parameter to also accept a WP_Widget instance object instead of simply a WP_Widget subclass name. |
| Since 7.1.1 | The key for an instance is prefixed so that it is never cast to an integer. |
WP_Widget_Factory::register() WP Widget Factory::register code WP 7.1.2
public function register( $widget ) {
if ( $widget instanceof WP_Widget ) {
$this->widgets[ self::INSTANCE_KEY_PREFIX . spl_object_id( $widget ) ] = $widget;
} else {
$this->widgets[ $widget ] = new $widget();
}
}