equal
deleted
inserted
replaced
259 * @since 5.8.0 |
259 * @since 5.8.0 |
260 * |
260 * |
261 * @return true|WP_Error True if the request has read access, WP_Error object otherwise. |
261 * @return true|WP_Error True if the request has read access, WP_Error object otherwise. |
262 */ |
262 */ |
263 protected function do_permissions_check() { |
263 protected function do_permissions_check() { |
264 // Verify if the current user has edit_theme_options capability. |
264 /* |
265 // This capability is required to access the widgets screen. |
265 * Verify if the current user has edit_theme_options capability. |
|
266 * This capability is required to access the widgets screen. |
|
267 */ |
266 if ( ! current_user_can( 'edit_theme_options' ) ) { |
268 if ( ! current_user_can( 'edit_theme_options' ) ) { |
267 return new WP_Error( |
269 return new WP_Error( |
268 'rest_cannot_manage_widgets', |
270 'rest_cannot_manage_widgets', |
269 __( 'Sorry, you are not allowed to manage widgets on this site.' ), |
271 __( 'Sorry, you are not allowed to manage widgets on this site.' ), |
270 array( 'status' => rest_authorization_required_code() ) |
272 array( 'status' => rest_authorization_required_code() ) |
316 public function prepare_item_for_response( $item, $request ) { |
318 public function prepare_item_for_response( $item, $request ) { |
317 global $wp_registered_sidebars, $wp_registered_widgets; |
319 global $wp_registered_sidebars, $wp_registered_widgets; |
318 |
320 |
319 // Restores the more descriptive, specific name for use within this method. |
321 // Restores the more descriptive, specific name for use within this method. |
320 $raw_sidebar = $item; |
322 $raw_sidebar = $item; |
321 $id = $raw_sidebar['id']; |
323 |
322 $sidebar = array( 'id' => $id ); |
324 $id = $raw_sidebar['id']; |
|
325 $sidebar = array( 'id' => $id ); |
323 |
326 |
324 if ( isset( $wp_registered_sidebars[ $id ] ) ) { |
327 if ( isset( $wp_registered_sidebars[ $id ] ) ) { |
325 $registered_sidebar = $wp_registered_sidebars[ $id ]; |
328 $registered_sidebar = $wp_registered_sidebars[ $id ]; |
326 |
329 |
327 $sidebar['status'] = 'active'; |
330 $sidebar['status'] = 'active'; |
337 $sidebar['name'] = $raw_sidebar['name']; |
340 $sidebar['name'] = $raw_sidebar['name']; |
338 $sidebar['description'] = ''; |
341 $sidebar['description'] = ''; |
339 $sidebar['class'] = ''; |
342 $sidebar['class'] = ''; |
340 } |
343 } |
341 |
344 |
|
345 if ( wp_is_block_theme() ) { |
|
346 $sidebar['status'] = 'inactive'; |
|
347 } |
|
348 |
342 $fields = $this->get_fields_for_response( $request ); |
349 $fields = $this->get_fields_for_response( $request ); |
343 if ( rest_is_field_included( 'widgets', $fields ) ) { |
350 if ( rest_is_field_included( 'widgets', $fields ) ) { |
344 $sidebars = wp_get_sidebars_widgets(); |
351 $sidebars = wp_get_sidebars_widgets(); |
345 $widgets = array_filter( |
352 $widgets = array_filter( |
346 isset( $sidebars[ $sidebar['id'] ] ) ? $sidebars[ $sidebar['id'] ] : array(), |
353 isset( $sidebars[ $sidebar['id'] ] ) ? $sidebars[ $sidebar['id'] ] : array(), |
366 $data = $this->add_additional_fields_to_object( $data, $request ); |
373 $data = $this->add_additional_fields_to_object( $data, $request ); |
367 $data = $this->filter_response_by_context( $data, $context ); |
374 $data = $this->filter_response_by_context( $data, $context ); |
368 |
375 |
369 $response = rest_ensure_response( $data ); |
376 $response = rest_ensure_response( $data ); |
370 |
377 |
371 $response->add_links( $this->prepare_links( $sidebar ) ); |
378 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { |
|
379 $response->add_links( $this->prepare_links( $sidebar ) ); |
|
380 } |
372 |
381 |
373 /** |
382 /** |
374 * Filters the REST API response for a sidebar. |
383 * Filters the REST API response for a sidebar. |
375 * |
384 * |
376 * @since 5.8.0 |
385 * @since 5.8.0 |