Changeset 52184 for trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php
- Timestamp:
- 11/16/2021 05:07:43 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php
r52079 r52184 340 340 'menu-item-url' => $menu_item_obj->url, 341 341 'menu-item-description' => $menu_item_obj->description, 342 'menu-item-content' => $menu_item_obj->menu_item_content,343 342 'menu-item-attr-title' => $menu_item_obj->attr_title, 344 343 'menu-item-target' => $menu_item_obj->target, … … 361 360 'menu-item-url' => '', 362 361 'menu-item-description' => '', 363 'menu-item-content' => '',364 362 'menu-item-attr-title' => '', 365 363 'menu-item-target' => '', … … 407 405 } elseif ( ! empty( $request['title']['raw'] ) ) { 408 406 $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'];418 407 } 419 408 } … … 461 450 } 462 451 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 468 452 if ( $error->has_errors() ) { 469 453 return $error; … … 565 549 // It is stored as a string, but should be exposed as an integer. 566 550 $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 );584 551 } 585 552 … … 782 749 'description' => __( 'The family of objects originally represented, such as "post_type" or "taxonomy".' ), 783 750 'type' => 'string', 784 'enum' => array( 'taxonomy', 'post_type', 'post_type_archive', 'custom' , 'block'),751 'enum' => array( 'taxonomy', 'post_type', 'post_type_archive', 'custom' ), 785 752 'context' => array( 'view', 'edit', 'embed' ), 786 753 'default' => 'custom', … … 858 825 'minimum' => 0, 859 826 '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 ),885 827 ); 886 828
Note: See TracChangeset
for help on using the changeset viewer.