WP_Widget_Factory::register()publicWP 2.8.0

Registers a widget subclass.

Method of the class: WP_Widget_Factory{}

No Hooks.


null. Nothing (null).


$WP_Widget_Factory = new WP_Widget_Factory();
$WP_Widget_Factory->register( $widget );
$widget(string|WP_Widget) (required)
Either the name of a WP_Widget subclass or an instance of a WP_Widget subclass.


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.

WP_Widget_Factory::register() code WP 6.4.3

public function register( $widget ) {
	if ( $widget instanceof WP_Widget ) {
		$this->widgets[ spl_object_hash( $widget ) ] = $widget;
	} else {
		$this->widgets[ $widget ] = new $widget();