Changeset 38422
- Timestamp:
- 08/28/2016 05:41:25 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r38421 r38422 3091 3091 * 3092 3092 * @since 3.5.0 3093 * 3094 * @param mixed $response Variable (usually an array or object) to encode as JSON, 3095 * then print and die. 3096 */ 3097 function wp_send_json( $response ) { 3093 * @since 4.7.0 The `$status_code` parameter was added. 3094 * 3095 * @param mixed $response Variable (usually an array or object) to encode as JSON, 3096 * then print and die. 3097 * @param int $status_code The HTTP status code to output. 3098 */ 3099 function wp_send_json( $response, $status_code = 200 ) { 3098 3100 @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); 3101 status_header( $status_code ); 3099 3102 echo wp_json_encode( $response ); 3100 3103 if ( wp_doing_ajax() ) … … 3108 3111 * 3109 3112 * @since 3.5.0 3110 * 3111 * @param mixed $data Data to encode as JSON, then print and die. 3112 */ 3113 function wp_send_json_success( $data = null ) { 3113 * @since 4.7.0 The `$status_code` parameter was added. 3114 * 3115 * @param mixed $data Data to encode as JSON, then print and die. 3116 * @param int $status_code The HTTP status code to output. 3117 */ 3118 function wp_send_json_success( $data = null, $status_code = 200 ) { 3114 3119 $response = array( 'success' => true ); 3115 3120 … … 3117 3122 $response['data'] = $data; 3118 3123 3119 wp_send_json( $response );3124 wp_send_json( $response, $status_code ); 3120 3125 } 3121 3126 … … 3130 3135 * @since 3.5.0 3131 3136 * @since 4.1.0 The `$data` parameter is now processed if a WP_Error object is passed in. 3132 * 3133 * @param mixed $data Data to encode as JSON, then print and die. 3134 */ 3135 function wp_send_json_error( $data = null ) { 3137 * @since 4.7.0 The `$status_code` parameter was added. 3138 * 3139 * @param mixed $data Data to encode as JSON, then print and die. 3140 * @param int $status_code The HTTP status code to output. 3141 */ 3142 function wp_send_json_error( $data = null, $status_code = 200 ) { 3136 3143 $response = array( 'success' => false ); 3137 3144 … … 3151 3158 } 3152 3159 3153 wp_send_json( $response );3160 wp_send_json( $response, $status_code ); 3154 3161 } 3155 3162
Note: See TracChangeset
for help on using the changeset viewer.