diff --git src/wp-includes/functions.php src/wp-includes/functions.php
index 0e720ee..a88e9bd 100644
|
|
|
function _wp_json_prepare_data( $data ) { |
| 3031 | 3031 | * Send a JSON response back to an Ajax request. |
| 3032 | 3032 | * |
| 3033 | 3033 | * @since 3.5.0 |
| | 3034 | * @since 4.6.0 If provided, sets the header status to `$response['status_code']` |
| 3034 | 3035 | * |
| 3035 | 3036 | * @param mixed $response Variable (usually an array or object) to encode as JSON, |
| 3036 | 3037 | * then print and die. |
| 3037 | 3038 | */ |
| 3038 | 3039 | function wp_send_json( $response ) { |
| 3039 | 3040 | @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); |
| | 3041 | if ( isset( $response['status_code'] ) ) { |
| | 3042 | status_header( (int) $response['status_code'] ); |
| | 3043 | unset( $response['status_code'] ); |
| | 3044 | } |
| 3040 | 3045 | echo wp_json_encode( $response ); |
| 3041 | 3046 | if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
| 3042 | 3047 | wp_die(); |
| … |
… |
function wp_send_json( $response ) { |
| 3048 | 3053 | * Send a JSON response back to an Ajax request, indicating success. |
| 3049 | 3054 | * |
| 3050 | 3055 | * @since 3.5.0 |
| | 3056 | * @since 4.6.0 The `$status_code` parameter was added |
| 3051 | 3057 | * |
| 3052 | 3058 | * @param mixed $data Data to encode as JSON, then print and die. |
| 3053 | 3059 | */ |
| 3054 | | function wp_send_json_success( $data = null ) { |
| 3055 | | $response = array( 'success' => true ); |
| | 3060 | function wp_send_json_success( $data = null, $status_code = 200 ) { |
| | 3061 | $response = array( 'success' => true, 'status_code' => (int) $status_code ); |
| 3056 | 3062 | |
| 3057 | 3063 | if ( isset( $data ) ) |
| 3058 | 3064 | $response['data'] = $data; |
| … |
… |
function wp_send_json_success( $data = null ) { |
| 3071 | 3077 | * @since 3.5.0 |
| 3072 | 3078 | * @since 4.1.0 The `$data` parameter is now processed if a {@see WP_Error} |
| 3073 | 3079 | * object is passed in. |
| | 3080 | * @since 4.6.0 The `$status_code` parameter was added |
| 3074 | 3081 | * |
| 3075 | | * @param mixed $data Data to encode as JSON, then print and die. |
| | 3082 | * @param mixed $data Data to encode as JSON, then print and die. |
| | 3083 | * @param int $status_code HTTP status code. |
| 3076 | 3084 | */ |
| 3077 | | function wp_send_json_error( $data = null ) { |
| 3078 | | $response = array( 'success' => false ); |
| | 3085 | function wp_send_json_error( $data = null, $status_code = 200 ) { |
| | 3086 | $response = array( 'success' => false, 'status_code' => (int) $status_code ); |
| 3079 | 3087 | |
| 3080 | 3088 | if ( isset( $data ) ) { |
| 3081 | 3089 | if ( is_wp_error( $data ) ) { |