--- a/wp/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php Fri Sep 05 18:40:08 2025 +0200
@@ -17,7 +17,7 @@
class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
/**
- * Get the nav menu item, if the ID is valid.
+ * Gets the nav menu item, if the ID is valid.
*
* @since 5.9.0
*
@@ -57,7 +57,7 @@
* @since 5.9.0
*
* @param WP_REST_Request $request Full details about the request.
- * @return bool|WP_Error True if the request has read access for the item, WP_Error object otherwise.
+ * @return bool|WP_Error True if the request has read access for the item, WP_Error object or false otherwise.
*/
public function get_item_permissions_check( $request ) {
$permission_check = parent::get_item_permissions_check( $request );
@@ -77,7 +77,7 @@
* @since 5.9.0
*
* @param WP_REST_Request $request Full details about the request.
- * @return bool|WP_Error Whether the current user has permission.
+ * @return true|WP_Error True if the request has read access for the item, WP_Error object otherwise.
*/
protected function check_has_read_only_access( $request ) {
if ( current_user_can( 'edit_theme_options' ) ) {
@@ -107,7 +107,6 @@
* @since 5.9.0
*
* @param WP_REST_Request $request Full details about the request.
- *
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
@@ -199,7 +198,6 @@
* @since 5.9.0
*
* @param WP_REST_Request $request Full details about the request.
- *
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function update_item( $request ) {
@@ -488,7 +486,7 @@
*
* @since 5.9.0
*
- * @param WP_Post $item Post object.
+ * @param WP_Post $item Post object.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response Response object.
*/
@@ -612,16 +610,18 @@
// Wrap the data in a response object.
$response = rest_ensure_response( $data );
- $links = $this->prepare_links( $item );
- $response->add_links( $links );
+ if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+ $links = $this->prepare_links( $item );
+ $response->add_links( $links );
- if ( ! empty( $links['self']['href'] ) ) {
- $actions = $this->get_available_actions( $item, $request );
+ if ( ! empty( $links['self']['href'] ) ) {
+ $actions = $this->get_available_actions( $item, $request );
- $self = $links['self']['href'];
+ $self = $links['self']['href'];
- foreach ( $actions as $rel ) {
- $response->add_link( $rel, $self );
+ foreach ( $actions as $rel ) {
+ $response->add_link( $rel, $self );
+ }
}
}
@@ -676,7 +676,7 @@
}
/**
- * Retrieve Link Description Objects that should be added to the Schema for the posts collection.
+ * Retrieves Link Description Objects that should be added to the Schema for the posts collection.
*
* @since 5.9.0
*
@@ -710,6 +710,10 @@
* @return array Item schema data.
*/
public function get_item_schema() {
+ if ( $this->schema ) {
+ return $this->add_additional_fields_schema( $this->schema );
+ }
+
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => $this->post_type,
@@ -745,7 +749,7 @@
);
$schema['properties']['type_label'] = array(
- 'description' => __( 'Name of type.' ),
+ 'description' => __( 'The singular label used to describe this type of menu item.' ),
'type' => 'string',
'context' => array( 'view', 'edit', 'embed' ),
'readonly' => true,
@@ -792,7 +796,7 @@
),
'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array(
- 'sanitize_callback' => function ( $value ) {
+ 'sanitize_callback' => static function ( $value ) {
return array_map( 'sanitize_html_class', wp_parse_list( $value ) );
},
),
@@ -842,13 +846,6 @@
),
);
- $schema['properties']['type_label'] = array(
- 'description' => __( 'The singular label used to describe this type of menu item.' ),
- 'context' => array( 'view', 'edit', 'embed' ),
- 'type' => 'string',
- 'readonly' => true,
- );
-
$schema['properties']['url'] = array(
'description' => __( 'The URL to which this menu item points.' ),
'type' => 'string',
@@ -860,7 +857,7 @@
return true;
}
- if ( esc_url_raw( $url ) ) {
+ if ( sanitize_url( $url ) ) {
return true;
}
@@ -880,7 +877,7 @@
),
'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array(
- 'sanitize_callback' => function ( $value ) {
+ 'sanitize_callback' => static function ( $value ) {
return array_map( 'sanitize_html_class', wp_parse_list( $value ) );
},
),
@@ -921,7 +918,9 @@
$schema['links'] = $schema_links;
}
- return $this->add_additional_fields_schema( $schema );
+ $this->schema = $schema;
+
+ return $this->add_additional_fields_schema( $this->schema );
}
/**
@@ -998,6 +997,8 @@
}
}
+ $query_args['update_menu_item_cache'] = true;
+
return $query_args;
}