scarstens
7/18/2012 - 10:27 PM

WordPress - Admin Function to Print Global $errors object using admin_notices

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>';
	}
}