WP_REST_Sidebars_Controller
- Since
- 5.8.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php:19
Core class used to manage a site's sidebars.
Compatibility
- WordPress
- since 5.8.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 3
Every hook that fires from inside WP_REST_Sidebars_Controller, in the order it appears in the class, grouped by the method that fires it.
Properties · 1
$widgets_retrievedboolprotected- Tracks whether retrieve_widgets() has been called in the current request.
Methods · 15
- __construct()Sidebars controller constructor.
- register_routes()Registers the controllers routes.
- get_items_permissions_check()Checks if a given request has access to get sidebars.
- get_items()Retrieves the list of sidebars (active or inactive).
- get_item_permissions_check()Checks if a given request has access to get a single sidebar.
- check_read_permission()Checks if a sidebar can be read publicly.
- get_item()Retrieves one sidebar from the collection.
- update_item_permissions_check()Checks if a given request has access to update sidebars.
- update_item()Updates a sidebar.
- do_permissions_check()Checks if the user has permissions to make the request.
- get_sidebar()Retrieves the registered sidebar with the given id.
- retrieve_widgets()Looks for "lost" widgets once per request.
- prepare_item_for_response()Prepares a single sidebar output for response.
- prepare_links()Prepares links for the sidebar.
- get_item_schema()Retrieves the block type' schema, conforming to JSON Schema.
Source code
class WP_REST_Sidebars_Controller extends WP_REST_Controller { /** * Tracks whether {@see retrieve_widgets()} has been called in the current request. * * @since 5.9.0 * @var bool */ protected $widgets_retrieved = false; /** * Sidebars controller constructor. * * @since 5.8.0 */ public function __construct() { $this->namespace = 'wp/v2'; $this->rest_base = 'sidebars'; } /** * Registers the controllers routes. * * @since 5.8.0 */ public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), ), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'id' => array( 'description' => __( 'The id of a registered sidebar' ), 'type' => 'string', ), 'context' => $this->get_context_param( array( 'default' => 'view' ) ), ), ), array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_item' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); } /** * Checks if a given request has access to get sidebars. * * @since 5.8.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */ public function get_items_permissions_check( $request ) { $this->retrieve_widgets(); foreach ( wp_get_sidebars_widgets() as $id => $widgets ) {Changelog
Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.