Make WordPress Core

Ticket #51293: 51293.diff

File 51293.diff, 2.1 KB (added by Hareesh Pillai, 3 years ago)

Refreshed the patch against trunk. Also, changed the $option parameter in the PR to $options to maintain consistency with wp_json_encode.

  • src/wp-includes/functions.php

     
    40784078 * @param mixed $response    Variable (usually an array or object) to encode as JSON,
    40794079 *                           then print and die.
    40804080 * @param int   $status_code The HTTP status code to output.
     4081 * @param int   $options Optional. Options to be passed to json_encode(). Default 0.
    40814082 */
    4082 function wp_send_json( $response, $status_code = null ) {
     4083function wp_send_json( $response, $status_code = null, $options = 0 ) {
    40834084        if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
    40844085                _doing_it_wrong(
    40854086                        __FUNCTION__,
     
    41004101                }
    41014102        }
    41024103
    4103         echo wp_json_encode( $response );
     4104        echo wp_json_encode( $response, $options );
    41044105
    41054106        if ( wp_doing_ajax() ) {
    41064107                wp_die(
     
    41234124 *
    41244125 * @param mixed $data        Data to encode as JSON, then print and die.
    41254126 * @param int   $status_code The HTTP status code to output.
     4127 * @param int   $options Optional. Options to be passed to json_encode(). Default 0.
    41264128 */
    4127 function wp_send_json_success( $data = null, $status_code = null ) {
     4129function wp_send_json_success( $data = null, $status_code = null, $options = 0 ) {
    41284130        $response = array( 'success' => true );
    41294131
    41304132        if ( isset( $data ) ) {
     
    41314133                $response['data'] = $data;
    41324134        }
    41334135
    4134         wp_send_json( $response, $status_code );
     4136        wp_send_json( $response, $status_code, $options );
    41354137}
    41364138
    41374139/**
     
    41484150 *
    41494151 * @param mixed $data        Data to encode as JSON, then print and die.
    41504152 * @param int   $status_code The HTTP status code to output.
     4153 * @param int   $options Optional. Options to be passed to json_encode(). Default 0.
    41514154 */
    4152 function wp_send_json_error( $data = null, $status_code = null ) {
     4155function wp_send_json_error( $data = null, $status_code = null, $options = 0 ) {
    41534156        $response = array( 'success' => false );
    41544157
    41554158        if ( isset( $data ) ) {
     
    41704173                }
    41714174        }
    41724175
    4173         wp_send_json( $response, $status_code );
     4176        wp_send_json( $response, $status_code, $options );
    41744177}
    41754178
    41764179/**