| 3027 | | $have_gettext = function_exists( '__' ); |
| 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; |
| | 3026 | if ( is_string( $message ) ) { |
| | 3027 | if ( ! empty( $r['additional_errors'] ) ) { |
| | 3028 | $message = array_merge( |
| | 3029 | array( $message ), |
| | 3030 | wp_list_pluck( $r['additional_errors'], 'message' ) |
| | 3031 | ); |
| | 3032 | $message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $message ) . "</li>\n\t</ul>"; |
| | 3033 | } else { |
| | 3034 | $message = "<p>$message</p>"; |
| | 3315 | * Processes arguments passed to {@see wp_die()} consistently for its handlers. |
| | 3316 | * |
| | 3317 | * @since 5.1.0 |
| | 3318 | * @access private |
| | 3319 | * |
| | 3320 | * @param string $message Error message. |
| | 3321 | * @param string $title Optional. Error title. Default empty. |
| | 3322 | * @param string|array $args Optional. Arguments to control behavior. Default empty array. |
| | 3323 | * @return array List of processed $message string, $title string, and $args array. |
| | 3324 | */ |
| | 3325 | function _wp_die_process_input( $message, $title = '', $args = array() ) { |
| | 3326 | $defaults = array( |
| | 3327 | 'response' => 0, |
| | 3328 | 'code' => '', |
| | 3329 | 'back_link' => false, |
| | 3330 | 'link_url' => '', |
| | 3331 | 'link_text' => '', |
| | 3332 | 'text_direction' => '', |
| | 3333 | 'additional_errors' => array(), |
| | 3334 | ); |
| | 3335 | |
| | 3336 | $args = wp_parse_args( $args, $defaults ); |
| | 3337 | |
| | 3338 | if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) { |
| | 3339 | if ( ! empty( $message->errors ) ) { |
| | 3340 | $errors = array(); |
| | 3341 | foreach ( (array) $message->errors as $error_code => $error_messages ) { |
| | 3342 | foreach ( (array) $error_messages as $error_message ) { |
| | 3343 | $errors[] = array( |
| | 3344 | 'code' => $error_code, |
| | 3345 | 'message' => $error_message, |
| | 3346 | 'data' => $error->get_error_data( $error_code ), |
| | 3347 | ); |
| | 3348 | } |
| | 3349 | } |
| | 3350 | |
| | 3351 | $message = $errors[0]['message']; |
| | 3352 | if ( empty( $args['code'] ) ) { |
| | 3353 | $args['code'] = $errors[0]['code']; |
| | 3354 | } |
| | 3355 | if ( empty( $args['response'] ) && is_array( $errors[0]['data'] ) && ! empty( $errors[0]['data']['status'] ) ) { |
| | 3356 | $args['response'] = $errors[0]['data']['status']; |
| | 3357 | } |
| | 3358 | if ( empty( $title ) && is_array( $errors[0]['data'] ) && ! empty( $errors[0]['data']['title'] ) ) { |
| | 3359 | $title = $errors[0]['data']['title']; |
| | 3360 | } |
| | 3361 | |
| | 3362 | unset( $errors[0] ); |
| | 3363 | $args['additional_errors'] = array_values( $errors ); |
| | 3364 | } else { |
| | 3365 | $message = ''; |
| | 3366 | } |
| | 3367 | } |
| | 3368 | |
| | 3369 | $have_gettext = function_exists( '__' ); |
| | 3370 | |
| | 3371 | if ( empty( $args['code'] ) ) { |
| | 3372 | $args['code'] = 'wp_die'; |
| | 3373 | } |
| | 3374 | if ( empty( $args['response'] ) ) { |
| | 3375 | $args['code'] = 500; |
| | 3376 | } |
| | 3377 | if ( empty( $title ) ) { |
| | 3378 | $title = $have_gettext ? __( 'WordPress › Error' ) : 'WordPress › Error'; |
| | 3379 | } |
| | 3380 | |
| | 3381 | if ( empty( $args['text_direction'] ) || ! in_array( $args['text_direction'], array( 'ltr', 'rtl' ), true ) ) { |
| | 3382 | $args['text_direction'] = 'ltr'; |
| | 3383 | if ( function_exists( 'is_rtl' ) && is_rtl() ) { |
| | 3384 | $args['text_direction'] = 'rtl'; |
| | 3385 | } |
| | 3386 | } |
| | 3387 | |
| | 3388 | return array( $message, $title, $args ); |
| | 3389 | } |
| | 3390 | |
| | 3391 | /** |