WordPress provides a simple class called WP_Error
that allows us to keep all our error messages tidy and in one place.
Change the plugin constructor to add initialization of error class:
if (version_compare($wp_version,"2.5","<")) { exit ($exit_msg); } // initialize the error class $this->error = new WP_Error(); $this->init_errors(); // add admin_menu action add_action('admin_menu', array(&$this, 'admin_menu'));
Initialize all our errors by defining the error code and the message:
// Init error messages function init_errors() { $this->error->add('e_image', __('Please upload a valid image.',$this->plugin_domain)); $this->error->add('e_title', __('You need to enter a title and add a photo.',$this->plugin_domain)); $this->error->add('e_url', __('You need to enter a URL.',$this->plugin_domain)); }
Add a function to retrieve an error:
// Retrieve an error message function my_error($e =...