Changeset 30506
- Timestamp:
- 11/21/2014 04:55:28 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r30379 r30506 2802 2802 * Send a JSON response back to an Ajax request, indicating failure. 2803 2803 * 2804 * If the `$data` parameter is a `WP_Error` object, the errors within the object are processed 2805 * and output as an array of error codes and corresponding messages. All other types are 2806 * output without further processing. 2807 * 2804 2808 * @since 3.5.0 2809 * @since 4.1.0 The `$data` parameter is now processed if a `WP_Error` object is passed in. 2805 2810 * 2806 2811 * @param mixed $data Data to encode as JSON, then print and die. … … 2809 2814 $response = array( 'success' => false ); 2810 2815 2811 if ( isset( $data ) ) 2812 $response['data'] = $data; 2816 if ( isset( $data ) ) { 2817 if ( is_wp_error( $data ) ) { 2818 $result = array(); 2819 foreach ( $data->errors as $code => $messages ) { 2820 foreach ( $messages as $message ) { 2821 $result[] = array( 'code' => $code, 'message' => $message ); 2822 } 2823 } 2824 2825 $response['data'] = $result; 2826 } else { 2827 $response['data'] = $data; 2828 } 2829 } 2813 2830 2814 2831 wp_send_json( $response );
Note: See TracChangeset
for help on using the changeset viewer.