IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
|
| 3024 | 3024 | $defaults = array( 'response' => 500 ); |
| 3025 | 3025 | $r = wp_parse_args( $args, $defaults ); |
| 3026 | 3026 | |
| 3027 | | $have_gettext = function_exists( '__' ); |
| | 3027 | list( $message, $r, $title, $errors ) = _wp_die_process_input( $message, $r, $title ); |
| 3028 | 3028 | |
| 3029 | | if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) { |
| 3030 | | if ( empty( $title ) ) { |
| 3031 | | $error_data = $message->get_error_data(); |
| 3032 | | if ( is_array( $error_data ) && isset( $error_data['title'] ) ) { |
| 3033 | | $title = $error_data['title']; |
| 3034 | | } |
| 3035 | | } |
| 3036 | | $errors = $message->get_error_messages(); |
| 3037 | | switch ( count( $errors ) ) { |
| 3038 | | case 0: |
| 3039 | | $message = ''; |
| 3040 | | break; |
| 3041 | | case 1: |
| 3042 | | $message = "<p>{$errors[0]}</p>"; |
| 3043 | | break; |
| 3044 | | default: |
| 3045 | | $message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>"; |
| 3046 | | break; |
| 3047 | | } |
| 3048 | | } elseif ( is_string( $message ) ) { |
| 3049 | | $message = "<p>$message</p>"; |
| | 3029 | switch ( count( $errors ) ) { |
| | 3030 | case 0: |
| | 3031 | $message = "<p>$message</p>"; |
| | 3032 | break; |
| | 3033 | case 1: |
| | 3034 | $message = "<p>{$errors[0]}</p>"; |
| | 3035 | break; |
| | 3036 | default: |
| | 3037 | $message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>"; |
| | 3038 | break; |
| 3050 | 3039 | } |
| 3051 | 3040 | |
| 3052 | 3041 | if ( ! empty( $r['link_url'] ) && ! empty( $r['link_text'] ) ) { |
| … |
… |
|
| 3059 | 3048 | } |
| 3060 | 3049 | |
| 3061 | 3050 | if ( isset( $r['back_link'] ) && $r['back_link'] ) { |
| | 3051 | $have_gettext = function_exists( '__' ); |
| 3062 | 3052 | $back_text = $have_gettext ? __( '« Back' ) : '« Back'; |
| 3063 | 3053 | $message .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>"; |
| 3064 | 3054 | } |
| … |
… |
|
| 3070 | 3060 | header( 'Content-Type: text/html; charset=utf-8' ); |
| 3071 | 3061 | } |
| 3072 | 3062 | |
| 3073 | | if ( empty( $title ) ) { |
| 3074 | | $title = $have_gettext ? __( 'WordPress › Error' ) : 'WordPress › Error'; |
| 3075 | | } |
| 3076 | | |
| 3077 | 3063 | $text_direction = 'ltr'; |
| 3078 | 3064 | if ( isset( $r['text_direction'] ) && 'rtl' == $r['text_direction'] ) { |
| 3079 | 3065 | $text_direction = 'rtl'; |
| … |
… |
|
| 3237 | 3223 | * @param string|array $args Optional. Arguments to control behavior. Default empty array. |
| 3238 | 3224 | */ |
| 3239 | 3225 | function _json_wp_die_handler( $message, $title = '', $args = array() ) { |
| 3240 | | $defaults = array( 'response' => 500 ); |
| 3241 | | |
| 3242 | | $r = wp_parse_args( $args, $defaults ); |
| | 3226 | $defaults = array( 'response' => 500, 'status' => 500, 'title' => $title ); |
| | 3227 | $r = wp_parse_args( $args, $defaults ); |
| 3243 | 3228 | |
| 3244 | | $data = array( |
| 3245 | | 'code' => 'wp_die', |
| 3246 | | 'message' => $message, |
| 3247 | | 'status' => $r['response'], |
| 3248 | | ); |
| | 3229 | list( $message, $r, $title, $errors ) = _wp_die_process_input( $message, $r, $title ); |
| 3249 | 3230 | |
| 3250 | 3231 | if ( ! headers_sent() ) { |
| 3251 | 3232 | header( 'Content-Type: application/json; charset=utf-8' ); |
| … |
… |
|
| 3254 | 3235 | } |
| 3255 | 3236 | } |
| 3256 | 3237 | |
| | 3238 | $code = $r['code']; |
| | 3239 | unset( $r['code'] ); |
| | 3240 | unset( $r['response'] ); |
| | 3241 | |
| | 3242 | $data = array( |
| | 3243 | 'code' => $code, |
| | 3244 | 'message' => $message, |
| | 3245 | 'data' => $r, |
| | 3246 | ); |
| | 3247 | |
| | 3248 | if ( count( $errors ) > 1 ) { |
| | 3249 | // Remove the primary error. |
| | 3250 | array_shift( $errors ); |
| | 3251 | $data['additional_errors'] = $errors; |
| | 3252 | } |
| | 3253 | |
| 3257 | 3254 | echo wp_json_encode( $data ); |
| 3258 | 3255 | die(); |
| 3259 | 3256 | } |
| … |
… |
|
| 3277 | 3274 | $defaults = array( 'response' => 500 ); |
| 3278 | 3275 | |
| 3279 | 3276 | $r = wp_parse_args( $args, $defaults ); |
| | 3277 | list( $message, $r ) = _wp_die_process_input( $message, $r ); |
| 3280 | 3278 | |
| 3281 | 3279 | if ( $wp_xmlrpc_server ) { |
| 3282 | 3280 | $error = new IXR_Error( $r['response'], $message ); |
| … |
… |
|
| 3303 | 3301 | ); |
| 3304 | 3302 | $r = wp_parse_args( $args, $defaults ); |
| 3305 | 3303 | |
| | 3304 | list( $message, $r ) = _wp_die_process_input( $message, $r ); |
| | 3305 | |
| 3306 | 3306 | if ( ! headers_sent() && null !== $r['response'] ) { |
| 3307 | 3307 | status_header( $r['response'] ); |
| 3308 | 3308 | } |
| … |
… |
|
| 3330 | 3330 | die(); |
| 3331 | 3331 | } |
| 3332 | 3332 | |
| | 3333 | /** |
| | 3334 | * @param string $message |
| | 3335 | * @param string $title |
| | 3336 | * @param array $args |
| | 3337 | * |
| | 3338 | * @return array |
| | 3339 | */ |
| | 3340 | function _wp_die_process_input( $message = '', array $args = array(), $title = '' ) { |
| | 3341 | $defaults = array( 'response' => 500, 'code' => 'wp_die', ); |
| | 3342 | $args = wp_parse_args( $args, $defaults ); |
| | 3343 | $errors = array(); |
| | 3344 | if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) { |
| | 3345 | $errors = $message->get_error_messages(); |
| | 3346 | $args['code'] = $message->get_error_code(); |
| | 3347 | $error_data = $message->get_error_data(); |
| | 3348 | $message = $message->get_error_message(); |
| | 3349 | if ( is_array( $error_data ) ) { |
| | 3350 | $args = wp_parse_args( $error_data, $args ); |
| | 3351 | if ( empty( $title ) && isset( $error_data['title'] ) ) { |
| | 3352 | $title = $error_data['title']; |
| | 3353 | } |
| | 3354 | } |
| | 3355 | |
| | 3356 | } |
| | 3357 | |
| | 3358 | if ( empty( $title ) ) { |
| | 3359 | $have_gettext = function_exists( '__' ); |
| | 3360 | $title = $have_gettext ? __( 'WordPress › Error' ) : 'WordPress › Error'; |
| | 3361 | } |
| | 3362 | |
| | 3363 | return array( $message, $args, $title, $errors ); |
| | 3364 | } |
| | 3365 | |
| 3333 | 3366 | /** |
| 3334 | 3367 | * Encode a variable into JSON, with some sanity checks. |
| 3335 | 3368 | * |