REST API: Remove experimental block menu item types.

The menu items REST API controller was added in [52079]. This included functionality to add a "block" menu item type. This functionality is experimental and not currently used in WordPress core, so should be removed. 

Props noisysocks.
See #40878.


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


git-svn-id: http://core.svn.wordpress.org/trunk@51776 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
spacedmonkey 2021-11-16 17:09:00 +00:00
parent 1966c81a18
commit b9ee5a4b29
3 changed files with 3 additions and 68 deletions

View File

@ -406,11 +406,10 @@ function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {
/** /**
* Save the properties of a menu item or create a new one. * Save the properties of a menu item or create a new one.
* *
* The menu-item-title, menu-item-description, menu-item-attr-title, and menu-item-content are expected * The menu-item-title, menu-item-description and menu-item-attr-title are expected
* to be pre-slashed since they are passed directly to APIs that expect slashed data. * to be pre-slashed since they are passed directly to APIs that expect slashed data.
* *
* @since 3.0.0 * @since 3.0.0
* @since 5.9.0 Added the menu-item-content parameter.
* *
* @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan. * @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan.
* @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item. * @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item.
@ -449,7 +448,6 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
'menu-item-attr-title' => '', 'menu-item-attr-title' => '',
'menu-item-target' => '', 'menu-item-target' => '',
'menu-item-classes' => '', 'menu-item-classes' => '',
'menu-item-content' => '',
'menu-item-xfn' => '', 'menu-item-xfn' => '',
'menu-item-status' => '', 'menu-item-status' => '',
'menu-item-post-date' => '', 'menu-item-post-date' => '',
@ -574,7 +572,6 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
update_post_meta( $menu_item_db_id, '_menu_item_classes', $args['menu-item-classes'] ); update_post_meta( $menu_item_db_id, '_menu_item_classes', $args['menu-item-classes'] );
update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] ); update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] );
update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw( $args['menu-item-url'] ) ); update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw( $args['menu-item-url'] ) );
update_post_meta( $menu_item_db_id, '_menu_item_content', $args['menu-item-content'] );
if ( 0 == $menu_id ) { if ( 0 == $menu_id ) {
update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() ); update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() );
@ -913,10 +910,6 @@ function wp_setup_nav_menu_item( $menu_item ) {
$menu_item->title = ( '' === $menu_item->post_title ) ? $original_title : $menu_item->post_title; $menu_item->title = ( '' === $menu_item->post_title ) ? $original_title : $menu_item->post_title;
} elseif ( 'block' === $menu_item->type ) {
$menu_item->type_label = __( 'Block' );
$menu_item->title = $menu_item->post_title;
$menu_item->menu_item_content = ! isset( $menu_item->menu_item_content ) ? get_post_meta( $menu_item->ID, '_menu_item_content', true ) : $menu_item->menu_item_content;
} else { } else {
$menu_item->type_label = __( 'Custom Link' ); $menu_item->type_label = __( 'Custom Link' );
$menu_item->title = $menu_item->post_title; $menu_item->title = $menu_item->post_title;

View File

@ -339,7 +339,6 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
'menu-item-title' => $menu_item_obj->title, 'menu-item-title' => $menu_item_obj->title,
'menu-item-url' => $menu_item_obj->url, 'menu-item-url' => $menu_item_obj->url,
'menu-item-description' => $menu_item_obj->description, 'menu-item-description' => $menu_item_obj->description,
'menu-item-content' => $menu_item_obj->menu_item_content,
'menu-item-attr-title' => $menu_item_obj->attr_title, 'menu-item-attr-title' => $menu_item_obj->attr_title,
'menu-item-target' => $menu_item_obj->target, 'menu-item-target' => $menu_item_obj->target,
'menu-item-classes' => $menu_item_obj->classes, 'menu-item-classes' => $menu_item_obj->classes,
@ -360,7 +359,6 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
'menu-item-title' => '', 'menu-item-title' => '',
'menu-item-url' => '', 'menu-item-url' => '',
'menu-item-description' => '', 'menu-item-description' => '',
'menu-item-content' => '',
'menu-item-attr-title' => '', 'menu-item-attr-title' => '',
'menu-item-target' => '', 'menu-item-target' => '',
'menu-item-classes' => array(), 'menu-item-classes' => array(),
@ -409,15 +407,6 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
} }
} }
// Nav menu content.
if ( ! empty( $schema['properties']['content'] ) && isset( $request['content'] ) ) {
if ( is_string( $request['content'] ) ) {
$prepared_nav_item['menu-item-content'] = $request['content'];
} elseif ( isset( $request['content']['raw'] ) ) {
$prepared_nav_item['menu-item-content'] = $request['content']['raw'];
}
}
$error = new WP_Error(); $error = new WP_Error();
// Check if object id exists before saving. // Check if object id exists before saving.
@ -460,11 +449,6 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
} }
} }
// If menu item is type block, then content is required.
if ( 'block' === $prepared_nav_item['menu-item-type'] && empty( $prepared_nav_item['menu-item-content'] ) ) {
$error->add( 'rest_content_required', __( 'The content is required when using a block menu item type.' ), array( 'status' => 400 ) );
}
if ( $error->has_errors() ) { if ( $error->has_errors() ) {
return $error; return $error;
} }
@ -566,23 +550,6 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
$data['object_id'] = absint( $menu_item->object_id ); $data['object_id'] = absint( $menu_item->object_id );
} }
if ( rest_is_field_included( 'content', $fields ) ) {
$data['content'] = array();
}
if ( rest_is_field_included( 'content.raw', $fields ) ) {
$data['content']['raw'] = $menu_item->menu_item_content;
}
if ( rest_is_field_included( 'content.rendered', $fields ) ) {
/** This filter is documented in wp-includes/post-template.php */
$data['content']['rendered'] = apply_filters( 'the_content', $menu_item->menu_item_content );
}
if ( rest_is_field_included( 'content.block_version', $fields ) ) {
$data['content']['block_version'] = block_version( $menu_item->menu_item_content );
}
if ( rest_is_field_included( 'parent', $fields ) ) { if ( rest_is_field_included( 'parent', $fields ) ) {
// Same as post_parent, exposed as an integer. // Same as post_parent, exposed as an integer.
$data['parent'] = (int) $menu_item->menu_item_parent; $data['parent'] = (int) $menu_item->menu_item_parent;
@ -781,7 +748,7 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
$schema['properties']['type'] = array( $schema['properties']['type'] = array(
'description' => __( 'The family of objects originally represented, such as "post_type" or "taxonomy".' ), 'description' => __( 'The family of objects originally represented, such as "post_type" or "taxonomy".' ),
'type' => 'string', 'type' => 'string',
'enum' => array( 'taxonomy', 'post_type', 'post_type_archive', 'custom', 'block' ), 'enum' => array( 'taxonomy', 'post_type', 'post_type_archive', 'custom' ),
'context' => array( 'view', 'edit', 'embed' ), 'context' => array( 'view', 'edit', 'embed' ),
'default' => 'custom', 'default' => 'custom',
); );
@ -859,31 +826,6 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
'default' => 0, 'default' => 0,
); );
$schema['properties']['content'] = array(
'description' => __( 'HTML content to display for this block menu item.' ),
'context' => array( 'view', 'edit', 'embed' ),
'type' => array( 'string', 'object' ),
'properties' => array(
'raw' => array(
'description' => __( 'HTML content, as it exists in the database.' ),
'type' => 'string',
'context' => array( 'edit' ),
),
'rendered' => array(
'description' => __( 'HTML content, transformed for display.' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'block_version' => array(
'description' => __( 'Version of the block format used in the HTML content.' ),
'type' => 'integer',
'context' => array( 'edit' ),
'readonly' => true,
),
),
);
$schema['properties']['target'] = array( $schema['properties']['target'] = array(
'description' => __( 'The target attribute of the link element for this menu item.' ), 'description' => __( 'The target attribute of the link element for this menu item.' ),
'type' => 'string', 'type' => 'string',

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.9-alpha-52183'; $wp_version = '5.9-alpha-52184';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.