Make WordPress Core


Ignore:
Timestamp:
11/16/2021 05:07:43 PM (3 years ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php

    r52079 r52184  
    340340                'menu-item-url'         => $menu_item_obj->url,
    341341                'menu-item-description' => $menu_item_obj->description,
    342                 'menu-item-content'     => $menu_item_obj->menu_item_content,
    343342                'menu-item-attr-title'  => $menu_item_obj->attr_title,
    344343                'menu-item-target'      => $menu_item_obj->target,
     
    361360                'menu-item-url'         => '',
    362361                'menu-item-description' => '',
    363                 'menu-item-content'     => '',
    364362                'menu-item-attr-title'  => '',
    365363                'menu-item-target'      => '',
     
    407405            } elseif ( ! empty( $request['title']['raw'] ) ) {
    408406                $prepared_nav_item['menu-item-title'] = $request['title']['raw'];
    409             }
    410         }
    411 
    412         // Nav menu content.
    413         if ( ! empty( $schema['properties']['content'] ) && isset( $request['content'] ) ) {
    414             if ( is_string( $request['content'] ) ) {
    415                 $prepared_nav_item['menu-item-content'] = $request['content'];
    416             } elseif ( isset( $request['content']['raw'] ) ) {
    417                 $prepared_nav_item['menu-item-content'] = $request['content']['raw'];
    418407            }
    419408        }
     
    461450        }
    462451
    463         // If menu item is type block, then content is required.
    464         if ( 'block' === $prepared_nav_item['menu-item-type'] && empty( $prepared_nav_item['menu-item-content'] ) ) {
    465             $error->add( 'rest_content_required', __( 'The content is required when using a block menu item type.' ), array( 'status' => 400 ) );
    466         }
    467 
    468452        if ( $error->has_errors() ) {
    469453            return $error;
     
    565549            // It is stored as a string, but should be exposed as an integer.
    566550            $data['object_id'] = absint( $menu_item->object_id );
    567         }
    568 
    569         if ( rest_is_field_included( 'content', $fields ) ) {
    570             $data['content'] = array();
    571         }
    572 
    573         if ( rest_is_field_included( 'content.raw', $fields ) ) {
    574             $data['content']['raw'] = $menu_item->menu_item_content;
    575         }
    576 
    577         if ( rest_is_field_included( 'content.rendered', $fields ) ) {
    578             /** This filter is documented in wp-includes/post-template.php */
    579             $data['content']['rendered'] = apply_filters( 'the_content', $menu_item->menu_item_content );
    580         }
    581 
    582         if ( rest_is_field_included( 'content.block_version', $fields ) ) {
    583             $data['content']['block_version'] = block_version( $menu_item->menu_item_content );
    584551        }
    585552
     
    782749            'description' => __( 'The family of objects originally represented, such as "post_type" or "taxonomy".' ),
    783750            'type'        => 'string',
    784             'enum'        => array( 'taxonomy', 'post_type', 'post_type_archive', 'custom', 'block' ),
     751            'enum'        => array( 'taxonomy', 'post_type', 'post_type_archive', 'custom' ),
    785752            'context'     => array( 'view', 'edit', 'embed' ),
    786753            'default'     => 'custom',
     
    858825            'minimum'     => 0,
    859826            'default'     => 0,
    860         );
    861 
    862         $schema['properties']['content'] = array(
    863             'description' => __( 'HTML content to display for this block menu item.' ),
    864             'context'     => array( 'view', 'edit', 'embed' ),
    865             'type'        => array( 'string', 'object' ),
    866             'properties'  => array(
    867                 'raw'           => array(
    868                     'description' => __( 'HTML content, as it exists in the database.' ),
    869                     'type'        => 'string',
    870                     'context'     => array( 'edit' ),
    871                 ),
    872                 'rendered'      => array(
    873                     'description' => __( 'HTML content, transformed for display.' ),
    874                     'type'        => 'string',
    875                     'context'     => array( 'view', 'edit' ),
    876                     'readonly'    => true,
    877                 ),
    878                 'block_version' => array(
    879                     'description' => __( 'Version of the block format used in the HTML content.' ),
    880                     'type'        => 'integer',
    881                     'context'     => array( 'edit' ),
    882                     'readonly'    => true,
    883                 ),
    884             ),
    885827        );
    886828
Note: See TracChangeset for help on using the changeset viewer.