From 98e9f1ad0a1c1e6bc3485ed9821b3264baf17ef0 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 20 Feb 2007 01:24:31 +0000 Subject: [PATCH] Add WP_Error handling to wp_die(). Props mdawaffe. fixes #3791 git-svn-id: https://develop.svn.wordpress.org/trunk@4892 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/functions.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index b5138aff9b..1cb50feb6d 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1293,9 +1293,31 @@ function wp_nonce_ays($action) { wp_die($html, $title); } -function wp_die($message, $title = '') { +function wp_die( $message, $title = '' ) { global $wp_locale; + if ( is_wp_error( $message ) ) { + if ( empty($title) ) { + $error_data = $message->get_error_data(); + if ( is_array($error_data) && isset($error_data['title']) ) + $title = $error_data['title']; + } + $errors = $message->get_error_messages(); + switch ( count($errors) ) : + case 0 : + $message = ''; + break; + case 1 : + $message = "

{$errors[0]}

"; + break; + default : + $message = ""; + break; + endswitch; + } elseif ( is_string($message) ) { + $message = "

$message

"; + } + header('Content-Type: text/html; charset=utf-8'); if ( empty($title) ) @@ -1319,11 +1341,11 @@ function wp_die($message, $title = '') {

WordPress

-

+ +