rest_parse_embed_param example

$request = new WP_REST_Request( $method$path_parts['path'] );
    if ( ! empty( $path_parts['query'] ) ) {
        parse_str( $path_parts['query']$query_params );
        $request->set_query_params( $query_params );
    }

    $response = rest_do_request( $request );
    if ( 200 === $response->status ) {
        $server = rest_get_server();
        /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
        $response = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response )$server$request );
        $embed    = $request->has_param( '_embed' ) ? rest_parse_embed_param( $request['_embed'] ) : false;
        $data     = (array) $server->response_to_data( $response$embed );

        if ( 'OPTIONS' === $method ) {
            $memo[ $method ][ $path ] = array(
                'body'    => $data,
                'headers' => $response->headers,
            );
        } else {
            $memo[ $path ] = array(
                'body'    => $data,
                'headers' => $response->headers,
            );

        $result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $result )$this$request );

        // Wrap the response in an envelope if asked for.         if ( isset( $_GET['_envelope'] ) ) {
            $embed  = isset( $_GET['_embed'] ) ? rest_parse_embed_param( $_GET['_embed'] ) : false;
            $result = $this->envelope_response( $result$embed );
        }

        // Send extra data from response objects.         $headers = $result->get_headers();
        $this->send_headers( $headers );

        $code = $result->get_status();
        $this->set_status( $code );

        /** * Filters whether the REST API request has already been served. * * Allow sending the request manually - by returning true, the API result * will not be sent to the client. * * @since 4.4.0 * * @param bool $served Whether the request has already been served. * Default false. * @param WP_HTTP_Response $result Result to send to the client. Usually a `WP_REST_Response`. * @param WP_REST_Request $request Request used to generate the response. * @param WP_REST_Server $server Server instance. */
Home | Imprint | This part of the site doesn't use cookies.