78 * |
78 * |
79 * @param WP_REST_Request $request Full details about the request. |
79 * @param WP_REST_Request $request Full details about the request. |
80 * @return true|WP_Error True if the request has read access for the item, WP_Error object otherwise. |
80 * @return true|WP_Error True if the request has read access for the item, WP_Error object otherwise. |
81 */ |
81 */ |
82 protected function check_has_read_only_access( $request ) { |
82 protected function check_has_read_only_access( $request ) { |
|
83 /** |
|
84 * Filters whether the current user has read access to menu items via the REST API. |
|
85 * |
|
86 * @since 6.8.0 |
|
87 * |
|
88 * @param bool $read_only_access Whether the current user has read access to menu items |
|
89 * via the REST API. |
|
90 * @param WP_REST_Request $request Full details about the request. |
|
91 * @param WP_REST_Controller $this The current instance of the controller. |
|
92 */ |
|
93 $read_only_access = apply_filters( 'rest_menu_read_access', false, $request, $this ); |
|
94 if ( $read_only_access ) { |
|
95 return true; |
|
96 } |
|
97 |
83 if ( current_user_can( 'edit_theme_options' ) ) { |
98 if ( current_user_can( 'edit_theme_options' ) ) { |
84 return true; |
99 return true; |
85 } |
100 } |
86 |
101 |
87 if ( current_user_can( 'edit_posts' ) ) { |
102 if ( current_user_can( 'edit_posts' ) ) { |
100 array( 'status' => rest_authorization_required_code() ) |
115 array( 'status' => rest_authorization_required_code() ) |
101 ); |
116 ); |
102 } |
117 } |
103 |
118 |
104 /** |
119 /** |
105 * Creates a single post. |
120 * Creates a single nav menu item. |
106 * |
121 * |
107 * @since 5.9.0 |
122 * @since 5.9.0 |
108 * |
123 * |
109 * @param WP_REST_Request $request Full details about the request. |
124 * @param WP_REST_Request $request Full details about the request. |
110 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
125 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
265 |
280 |
266 return rest_ensure_response( $response ); |
281 return rest_ensure_response( $response ); |
267 } |
282 } |
268 |
283 |
269 /** |
284 /** |
270 * Deletes a single menu item. |
285 * Deletes a single nav menu item. |
271 * |
286 * |
272 * @since 5.9.0 |
287 * @since 5.9.0 |
273 * |
288 * |
274 * @param WP_REST_Request $request Full details about the request. |
289 * @param WP_REST_Request $request Full details about the request. |
275 * @return WP_REST_Response|WP_Error True on success, or WP_Error object on failure. |
290 * @return WP_REST_Response|WP_Error True on success, or WP_Error object on failure. |
480 */ |
495 */ |
481 return apply_filters( 'rest_pre_insert_nav_menu_item', $prepared_nav_item, $request ); |
496 return apply_filters( 'rest_pre_insert_nav_menu_item', $prepared_nav_item, $request ); |
482 } |
497 } |
483 |
498 |
484 /** |
499 /** |
485 * Prepares a single post output for response. |
500 * Prepares a single nav menu item output for response. |
486 * |
501 * |
487 * @since 5.9.0 |
502 * @since 5.9.0 |
488 * |
503 * |
489 * @param WP_Post $item Post object. |
504 * @param WP_Post $item Post object. |
490 * @param WP_REST_Request $request Request object. |
505 * @param WP_REST_Request $request Request object. |
508 $data['title']['raw'] = $menu_item->title; |
523 $data['title']['raw'] = $menu_item->title; |
509 } |
524 } |
510 |
525 |
511 if ( rest_is_field_included( 'title.rendered', $fields ) ) { |
526 if ( rest_is_field_included( 'title.rendered', $fields ) ) { |
512 add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); |
527 add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); |
|
528 add_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); |
513 |
529 |
514 /** This filter is documented in wp-includes/post-template.php */ |
530 /** This filter is documented in wp-includes/post-template.php */ |
515 $title = apply_filters( 'the_title', $menu_item->title, $menu_item->ID ); |
531 $title = apply_filters( 'the_title', $menu_item->title, $menu_item->ID ); |
516 |
532 |
517 $data['title']['rendered'] = $title; |
533 $data['title']['rendered'] = $title; |
518 |
534 |
519 remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); |
535 remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); |
|
536 remove_filter( 'private_title_format', array( $this, 'protected_title_format' ) ); |
520 } |
537 } |
521 |
538 |
522 if ( rest_is_field_included( 'status', $fields ) ) { |
539 if ( rest_is_field_included( 'status', $fields ) ) { |
523 $data['status'] = $menu_item->post_status; |
540 $data['status'] = $menu_item->post_status; |
524 } |
541 } |