WP_REST_Server::get_response_links PHP Méthode

    public static function get_response_links($response)
    {
        $links = $response->get_links();
        if (empty($links)) {
            return array();
        }
        // Convert links to part of the data.
        $data = array();
        foreach ($links as $rel => $items) {
            $data[$rel] = array();
            foreach ($items as $item) {
                $attributes = $item['attributes'];
                $attributes['href'] = $item['href'];
                $data[$rel][] = $attributes;
            }
        }
        return $data;
    }

Usage Example

 /**
  * Prepare a response for inserting into a collection.
  *
  * @param WP_REST_Response $response Response object.
  * @return array Response data, ready for insertion into collection data.
  */
 public function prepare_response_for_collection($response)
 {
     if (!$response instanceof WP_REST_Response) {
         return $response;
     }
     $data = (array) $response->get_data();
     $links = WP_REST_Server::get_response_links($response);
     if (!empty($links)) {
         $data['_links'] = $links;
     }
     return $data;
 }