$error = new WP_Error( 'invalid_email', 'Invalid email address.' ); $message = $error->get_error_message( 'invalid_email' ); echo $message;
$error = new WP_Error(); $error->add( 'missing_field', 'Please fill in all required fields.' ); $error->add( 'server_error', 'An error occurred on the server.' ); $error->add( 'invalid_email', 'Invalid email address.' ); foreach ( $error->get_error_codes() as $code ) { $message = $error->get_error_message( $code ); echo $message . 'This example creates a new WP_Error instance and adds three different errors to it with their associated error codes and messages. The get_error_codes function is then used to retrieve all of the error codes associated with this instance, which are then used in a loop to retrieve each error message using the get_error_message function. Each error message is printed to the screen with a line break between them. Package library: WordPress.
'; }