WP_REST_Menu_Items_Controller::prepare_item_for_response() – Prepares a single post output for response.

You appear to be a bot. Output may be restricted

Description

Prepares a single post output for response.

Usage

$WP_REST_Response = WP_REST_Menu_Items_Controller::prepare_item_for_response( $item, $request );

Parameters

$item
( WP_Post ) required – Post object.
$request
( WP_REST_Request ) required – Request object.

Returns

WP_REST_Response Response object.

Source

File name: wordpress/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php


Lines:

1 to 100 of 188
  public function prepare_item_for_response( $item, $request ) {
    // Base fields for every post.
    $fields    = $this->get_fields_for_response( $request );
    $menu_item = $this->get_nav_menu_item( $item->ID );
    $data      = array();

    if ( rest_is_field_included( 'id', $fields ) ) {
      $data['id'] = $menu_item->ID;
    }

    if ( rest_is_field_included( 'title', $fields ) ) {
      $data['title'] = array();
    }

    if ( rest_is_field_included( 'title.raw', $fields ) ) {
      $data['title']['raw'] = $menu_item->title;
    }

    if ( rest_is_field_included( 'title.rendered', $fields ) ) {
      add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );

      
/** This filter is documented in wp-includes/post-template.php */
      $title = apply_filters( 'the_title', $menu_item->title, $menu_item->ID );

      $data['title']['rendered'] = $title;

      remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) );
    }

    if ( rest_is_field_included( 'status', $fields ) ) {
      $data['status'] = $menu_item->post_status;
    }

    if ( rest_is_field_included( 'url', $fields ) ) {
      $data['url'] = $menu_item->url;
    }

    if ( rest_is_field_included( 'attr_title', $fields ) ) {
      // Same as post_excerpt.
      $data['attr_title'] = $menu_item->attr_title;
    }

    if ( rest_is_field_included( 'description', $fields ) ) {
      // Same as post_content.
      $data['description'] = $menu_item->description;
    }

    if ( rest_is_field_included( 'type', $fields ) ) {
      $data['type'] = $menu_item->type;
    }

    if ( rest_is_field_included( 'type_label', $fields ) ) {
      $data['type_label'] = $menu_item->type_label;
    }

    if ( rest_is_field_included( 'object', $fields ) ) {
      $data['object'] = $menu_item->object;
    }

    if ( rest_is_field_included( 'object_id', $fields ) ) {
      // It is stored as a string, but should be exposed as an integer.
      $data['object_id'] = absint( $menu_item->object_id );
    }

    if ( rest_is_field_included( 'parent', $fields ) ) {
      // Same as post_parent, exposed as an integer.
      $data['parent'] = (int) $menu_item->menu_item_parent;
    }

    if ( rest_is_field_included( 'menu_order', $fields ) ) {
      // Same as post_parent, exposed as an integer.
      $data['menu_order'] = (int) $menu_item->menu_order;

 View on GitHub View on Trac