WP_REST_Widget_Types_Controller::get_widgets()protectedWP 5.8.0

Normalize array of widgets.

Method of the class: WP_REST_Widget_Types_Controller{}

No Hooks.

Return

Array. Array of widgets.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_widgets();

Notes

  • Global. WP_Widget_Factory. $wp_widget_factory
  • Global. Array. $wp_registered_widgets The list of registered widgets.

Changelog

Since 5.8.0 Introduced.

WP_REST_Widget_Types_Controller::get_widgets() code WP 6.6.2

protected function get_widgets() {
	global $wp_widget_factory, $wp_registered_widgets;

	$widgets = array();

	foreach ( $wp_registered_widgets as $widget ) {
		$parsed_id     = wp_parse_widget_id( $widget['id'] );
		$widget_object = $wp_widget_factory->get_widget_object( $parsed_id['id_base'] );

		$widget['id']       = $parsed_id['id_base'];
		$widget['is_multi'] = (bool) $widget_object;

		if ( isset( $widget['name'] ) ) {
			$widget['name'] = html_entity_decode( $widget['name'], ENT_QUOTES, get_bloginfo( 'charset' ) );
		}

		if ( isset( $widget['description'] ) ) {
			$widget['description'] = html_entity_decode( $widget['description'], ENT_QUOTES, get_bloginfo( 'charset' ) );
		}

		unset( $widget['callback'] );

		$classname = '';
		foreach ( (array) $widget['classname'] as $cn ) {
			if ( is_string( $cn ) ) {
				$classname .= '_' . $cn;
			} elseif ( is_object( $cn ) ) {
				$classname .= '_' . get_class( $cn );
			}
		}
		$widget['classname'] = ltrim( $classname, '_' );

		$widgets[ $widget['id'] ] = $widget;
	}

	ksort( $widgets );

	return $widgets;
}