WordPress.org

Make WordPress Core

Ticket #35666: 35666-2.diff

File 35666-2.diff, 2.2 KB (added by stephenharris, 6 years ago)

Alternative patch for allowing a header status to be set

  • src/wp-includes/functions.php

    diff --git src/wp-includes/functions.php src/wp-includes/functions.php
    index 0e720ee..9634ed4 100644
    function _wp_json_prepare_data( $data ) { 
    30313031 * Send a JSON response back to an Ajax request.
    30323032 *
    30333033 * @since 3.5.0
     3034 * @since 4.6.0 The `$status_code` parameter was added
    30343035 *
    30353036 * @param mixed $response Variable (usually an array or object) to encode as JSON,
    30363037 *                        then print and die.
    30373038 */
    3038 function wp_send_json( $response ) {
     3039function wp_send_json( $response, $status_code = 200 ) {
    30393040        @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
     3041        status_header( (int) $status_code );
    30403042        echo wp_json_encode( $response );
    30413043        if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
    30423044                wp_die();
    function wp_send_json( $response ) { 
    30483050 * Send a JSON response back to an Ajax request, indicating success.
    30493051 *
    30503052 * @since 3.5.0
     3053 * @since 4.6.0 The `$status_code` parameter was added
    30513054 *
    30523055 * @param mixed $data Data to encode as JSON, then print and die.
    30533056 */
    3054 function wp_send_json_success( $data = null ) {
     3057function wp_send_json_success( $data = null, $status_code = 200 ) {
    30553058        $response = array( 'success' => true );
    30563059
    30573060        if ( isset( $data ) )
    30583061                $response['data'] = $data;
    30593062
    3060         wp_send_json( $response );
     3063        wp_send_json( $response, $status_code );
    30613064}
    30623065
    30633066/**
    function wp_send_json_success( $data = null ) { 
    30713074 * @since 3.5.0
    30723075 * @since 4.1.0 The `$data` parameter is now processed if a {@see WP_Error}
    30733076 *              object is passed in.
     3077 * @since 4.6.0 The `$status_code` parameter was added
    30743078 *
    3075  * @param mixed $data Data to encode as JSON, then print and die.
     3079 * @param mixed $data        Data to encode as JSON, then print and die.
     3080 * @param int   $status_code HTTP status code.
    30763081 */
    3077 function wp_send_json_error( $data = null ) {
     3082function wp_send_json_error( $data = null, $status_code = 200 ) {
    30783083        $response = array( 'success' => false );
    30793084
    30803085        if ( isset( $data ) ) {
    function wp_send_json_error( $data = null ) { 
    30923097                }
    30933098        }
    30943099
    3095         wp_send_json( $response );
     3100        wp_send_json( $response, $status_code );
    30963101}
    30973102
    30983103/**