$error = new WP_Error( 'invalid_login', 'Invalid login credentials', array( 'status' => 401 ) ); $error_code = $error->get_error_code(); echo $error_code; // Output: invalid_login
$error = new WP_Error(); $error->add( 'empty_field', 'A required field is empty' ); $error->add( 'invalid_email', 'The email address is not valid' ); $error->add( 'invalid_password', 'The password is too short' ); $error_codes = $error->get_error_codes(); print_r( $error_codes ); // Output: Array ( [0] => empty_field [1] => invalid_email [2] => invalid_password )This example creates a new WP_Error object and adds three different error codes to it. The get_error_codes method is used to retrieve an array of all the error codes present in the object. Package library: WordPress