| 2769 | * Kill WordPress execution and send AJAX response with error message. |
| 2770 | * |
| 2771 | * This is AJAX-version of the default handler for wp_die |
| 2772 | * |
| 2773 | * @since 3.0.0 |
| 2774 | * @access private |
| 2775 | * |
| 2776 | * @param string $message Error message. |
| 2777 | * @param string $title Error title. |
| 2778 | * @param string|array $args Optional arguements to control behaviour. |
| 2779 | */ |
| 2780 | function _ajax_wp_die_handler( $message, $title = '', $args = array() ) { |
| 2781 | $defaults = array( 'response' => 200 ); |
| 2782 | $r = wp_parse_args($args, $defaults); |
| 2783 | if ( !headers_sent() ) { |
| 2784 | status_header( $r['response'] ); |
| 2785 | } |
| 2786 | if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) { |
| 2787 | if ( empty( $title ) ) { |
| 2788 | $error_data = $message->get_error_data(); |
| 2789 | if ( is_array( $error_data ) && isset( $error_data['title'] ) ) |
| 2790 | $title = $error_data['title']; |
| 2791 | } |
| 2792 | $errors = $message->get_error_messages(); |
| 2793 | switch ( count( $errors ) ) : |
| 2794 | case 0 : |
| 2795 | $message = ''; |
| 2796 | break; |
| 2797 | case 1 : |
| 2798 | $message = "<p>{$errors[0]}</p>"; |
| 2799 | break; |
| 2800 | default : |
| 2801 | $message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>"; |
| 2802 | break; |
| 2803 | endswitch; |
| 2804 | } elseif ( is_string( $message ) ) { |
| 2805 | $message = "<p>$message</p>"; |
| 2806 | } |
| 2807 | echo "<div style='text-align:left;'>" . $message . "</div>"; |
| 2808 | die; |
| 2809 | } |
| 2810 | /** |