WP_REST_Server::response_to_data PHP Метод

response_to_data() публичный метод

Converts a response to data to send.
С версии: 4.4.0
public response_to_data ( WP_REST_Response $response, boolean $embed ) : array
$response WP_REST_Response Response object.
$embed boolean Whether links should be embedded.
Результат array { Data with sub-requests embedded. @type array [$_links] Links. @type array [$_embedded] Embeddeds. }
    public function response_to_data($response, $embed)
    {
        $data = $response->get_data();
        $links = $this->get_compact_response_links($response);
        if (!empty($links)) {
            // Convert links to part of the data.
            $data['_links'] = $links;
        }
        if ($embed) {
            // Determine if this is a numeric array.
            if (wp_is_numeric_array($data)) {
                $data = array_map(array($this, 'embed_links'), $data);
            } else {
                $data = $this->embed_links($data);
            }
        }
        return $data;
    }

Usage Example

 /**
  * Converts a response to data to send.
  *
  * @param \WP_REST_Response $response Response object.
  * @param bool              $embed    Whether links should be embedded.
  *
  * @return array {
  *     Data with sub-requests embedded.
  *
  *     @type array [$_links]    Links.
  *     @type array [$_embedded] Embeddeds.
  * }
  */
 public function response_to_data($response, $embed)
 {
     $data = parent::response_to_data($response, $embed);
     $server = $this;
     /**
      * Filter return value for \CustomizeRESTResources\WP_Customize_REST_Server::response_to_data()
      *
      * @param array $data Data.
      * @param array $args {
      *     Filter args.
      *
      *     @type \WP_REST_Server   $server   The server.
      *     @type \WP_REST_Response $response The response.
      *     @type bool              $embed    Whether to embed.
      * }
      */
     $data = apply_filters('customize_rest_server_response_data', $data, compact('server', 'response', 'embed'));
     return $data;
 }
All Usage Examples Of WP_REST_Server::response_to_data