Make WordPress Core

Ticket #47834: 47834.diff

File 47834.diff, 1.7 KB (added by lkf_tanzt, 5 years ago)

I’ve prepared a diff-file for the second suggestion.

  • src/wp-includes/rest-api/class-wp-rest-server.php

    diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php
    index de09c6c52e..f050cfbaae 100644
    a b class WP_REST_Server { 
    406406                                return null;
    407407                        }
    408408
    409                         $result = wp_json_encode( $result );
     409                        /**
     410                         * Filters whether the result should be json encoded.
     411                         *
     412                         * Allows disabling json encoding of the result just before sending the response.
     413                         * This can be useful if a content type other than application/json should be used to provide the resource.
     414                         * For example:
     415                         * - text/calendar iCalendar / ics files according to RFC 5545
     416                         * - text/vcard Business Card information RFC 6350
     417                         * - application/pdf PDF file content
     418                         *
     419                         * The header field must be set in your resource handler by calling header("Content-Type", "...")
     420                         * on your response object.
     421                         *
     422                         * @since 5.3.0
     423                         *
     424                         * @param boolean          $do_encode Whether the result content should be passed to wp_json_encode() or not.
     425                         *                                             Default true
     426                         * @param WP_HTTP_Response $result    Result to send to the client. Usually a string or object.
     427                         * @param WP_REST_Request  $request   Request used to generate the response.
     428                         * @param WP_REST_Server   $this      Server instance.
     429                         */
     430                        $do_json_encode = apply_filters( 'rest_do_json_encode', true, $result, $request, $this );
     431                        if ( $do_json_encode ) {
     432                                $result = wp_json_encode( $result );
     433                        }
    410434
    411435                        $json_error_message = $this->get_json_last_error();
    412436                        if ( $json_error_message ) {