WP_REST_Menu_Items_Controller::prepare_links() – Prepares links for the request.

You appear to be a bot. Output may be restricted

Description

Prepares links for the request.

Usage

$array = WP_REST_Menu_Items_Controller::prepare_links( $post );

Parameters

$post
( WP_Post ) required – Post object.

Returns

array Links for the given post.

Source

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


Lines:

1 to 30 of 30
  protected function prepare_links( $post ) {
    $links     = parent::prepare_links( $post );
    $menu_item = $this->get_nav_menu_item( $post->ID );

    if ( empty( $menu_item->object_id ) ) {
      return $links;
    }

    $path = '';
    $type = '';
    $key  = $menu_item->type;
    if ( 'post_type' === $menu_item->type ) {
      $path = rest_get_route_for_post( $menu_item->object_id );
      $type = get_post_type( $menu_item->object_id );
    } elseif ( 'taxonomy' === $menu_item->type ) {
      $path = rest_get_route_for_term( $menu_item->object_id );
      $type = get_term_field( 'taxonomy', $menu_item->object_id );
    }

    if ( $path && $type ) {
      $links['https://api.w.org/menu-item-object'][] = array(
        'href'       => rest_url( $path ),
        $key         => $type,
        'embeddable' => true,
      );
    }

    return $links;
  }
 

 View on GitHub View on Trac