Skip to content

Instantly share code, notes, and snippets.

@scarstens
Created July 18, 2012 22:27
Show Gist options
  • Save scarstens/3139359 to your computer and use it in GitHub Desktop.
Save scarstens/3139359 to your computer and use it in GitHub Desktop.
WordPress - Admin Function to Print Global $errors object using admin_notices
<?php
if(is_admin()){
//turn on admin notices which properly prints the global $errors objects detected errors
add_action('admin_notices', 'wlfw_admin_display_global_errors');
}
//function: wlfw_errors_in_footer_admin
//description: used with admin_notices to display global errors
//optional parameters: none
function wlfw_admin_display_global_errors ($original_value) {
global $errors;
if(is_wp_error($errors)) {
if( count($errors->errors) > 0 ) {
echo '<div id="message" class="error">';
foreach($errors->errors as $error_code => $error) {
echo '<p><strong>'.$error_code.':</strong> ';
foreach($error as $i => $message)
echo var_export($message, true);
echo '</p>';
}
echo '</div>'.PHP_EOL.'<!-- end of error admin notice -->';
}
//echo '<div id="message" class="error"><p>' . $errors->get_error_message() . '</p></div>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment