$error = new WP_Error(); $error->add( '404', __( 'The requested page could not be found.' ), 'page_not_found' );
$error = new WP_Error(); $error->add( 'validation_error', __( 'The field cannot be empty.' ), array( 'field_name' => 'name' ) );In this example, we create a new instance of WP_Error class and add a validation_error with a message and a field name. These code examples are part of the WordPress package library.