response_to_data example

$params = $request->get_params();

    if ( '/oembed/1.0/embed' !== $request->get_route() || 'GET' !== $request->get_method() ) {
        return $served;
    }

    if ( ! isset( $params['format'] ) || 'xml' !== $params['format'] ) {
        return $served;
    }

    // Embed links inside the request.     $data = $server->response_to_data( $result, false );

    if ( ! class_exists( 'SimpleXMLElement' ) ) {
        status_header( 501 );
        die( get_status_header_desc( 501 ) );
    }

    $result = _oembed_create_xml( $data );

    // Bail if there's no XML.     if ( ! $result ) {
        status_header( 501 );
        
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,
            );
        }

        $served = apply_filters( 'rest_pre_serve_request', false, $result$request$this );

        if ( ! $served ) {
            if ( 'HEAD' === $request->get_method() ) {
                return null;
            }

            // Embed links inside the request.             $embed  = isset( $_GET['_embed'] ) ? rest_parse_embed_param( $_GET['_embed'] ) : false;
            $result = $this->response_to_data( $result$embed );

            /** * Filters the REST API response. * * Allows modification of the response data after inserting * embedded data (if any) and before echoing the response data. * * @since 4.8.1 * * @param array $result Response data to send to the client. * @param WP_REST_Server $server Server instance. * @param WP_REST_Request $request Request used to generate the response. */
Home | Imprint | This part of the site doesn't use cookies.