Skip to content

Commit

Permalink
REST API: Add widget endpoints
Browse files Browse the repository at this point in the history
Adds the sidebars, widgets and widget-types REST API endpoints from the
Gutenberg plugin.

Fixes #41683.
Props TimothyBlynJacobs.

Built from https://develop.svn.wordpress.org/trunk@50993


git-svn-id: http://core.svn.wordpress.org/trunk@50602 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
noisysocks committed May 25, 2021
1 parent 2b7ad8a commit 2a4e1e0
Show file tree
Hide file tree
Showing 24 changed files with 2,151 additions and 5 deletions.
18 changes: 18 additions & 0 deletions wp-includes/class-wp-widget-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,22 @@ public function _register_widgets() {
$this->widgets[ $key ]->_register();
}
}

/**
* Returns the registered WP_Widget object for the given widget type.
*
* @since 5.8.0
*
* @param string $id_base Widget type ID.
* @return WP_Widget|null
*/
public function get_widget_object( $id_base ) {
foreach ( $this->widgets as $widget_object ) {
if ( $widget_object->id_base === $id_base ) {
return $widget_object;
}
}

return null;
}
}
3 changes: 3 additions & 0 deletions wp-includes/default-widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@

/** WP_Widget_Custom_HTML class */
require_once ABSPATH . WPINC . '/widgets/class-wp-widget-custom-html.php';

/** WP_Widget_Block class */
require_once ABSPATH . WPINC . '/widgets/class-wp-widget-block.php';
12 changes: 12 additions & 0 deletions wp-includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,18 @@ function create_initial_rest_routes() {
$controller = new WP_REST_Plugins_Controller();
$controller->register_routes();

// Sidebars.
$controller = new WP_REST_Sidebars_Controller();
$controller->register_routes();

// Widget Types.
$controller = new WP_REST_Widget_Types_Controller();
$controller->register_routes();

// Widgets.
$controller = new WP_REST_Widgets_Controller();
$controller->register_routes();

// Block Directory.
$controller = new WP_REST_Block_Directory_Controller();
$controller->register_routes();
Expand Down
Loading

0 comments on commit 2a4e1e0

Please sign in to comment.