WP_Widget_Factory::register( string|WP_Widget $widget )

In this article

Registers a widget subclass.

Parameters

$widgetstring|WP_Widgetrequired
Either the name of a WP_Widget subclass or an instance of a WP_Widget subclass.

Source

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

Changelog

VersionDescription
4.6.0Updated the $widget parameter to also accept a WP_Widget instance object instead of simply a WP_Widget subclass name.
2.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.