WordPress at Your Fingertips
function is not described

WP_REST_Widget_Types_Controller::get_widgets() protected WP 5.8.0

Normalize array of widgets.

{} It's a 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.

Code of WP_REST_Widget_Types_Controller::get_widgets() WP 5.8.1

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;
	}

	return $widgets;
}