Title: Custom validation help
Last modified: August 30, 2016

---

# Custom validation help

 *  Resolved [bestdie3](https://wordpress.org/support/users/bestdie3/)
 * (@bestdie3)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/custom-validation-help/)
 * Since ‘create_new_user’ uses ‘register_post’ it validates the registration form
   before ‘registration_errors’ fires. This only permits custom validation to work
   if the username or email has errors. If they don’t, the form will ignore any 
   function with the hook ‘registration_errors’. The WordPress website states to
   never validate forms using ‘register_post’. So, my question is how do I add custom
   validation? Should i just add to to the core functions of the plugin like so:
 *     ```
       public function create_new_user( $user_login, $user_email, $errors ) {
       		$errors->add( 'demo_error', __( '<strong>ERROR</strong>: This is a demo error.', 'my_textdomain' ) );
       		if ( $errors->get_error_code() ) {
       			return;
       		}
   
       		// create the user
       		$user_pass = wp_generate_password( 12, false );
       		$user_id = wp_create_user( $user_login, $user_pass, $user_email );
       		if ( !$user_id ) {
       			$errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) );
       		}
       	}
       ```
   
 * What are my options. Is this code really unsafe like the WordPress site states?
 * [https://wordpress.org/plugins/new-user-approve/](https://wordpress.org/plugins/new-user-approve/)

The topic ‘Custom validation help’ is closed to new replies.

 * ![](https://ps.w.org/new-user-approve/assets/icon-128x128.gif?rev=2544141)
 * [New User Approve](https://wordpress.org/plugins/new-user-approve/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/new-user-approve/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/new-user-approve/)
 * [Active Topics](https://wordpress.org/support/plugin/new-user-approve/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/new-user-approve/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/new-user-approve/reviews/)

## Tags

 * [custom-validation](https://wordpress.org/support/topic-tag/custom-validation/)
 * [errors](https://wordpress.org/support/topic-tag/errors/)

 * 0 replies
 * 1 participant
 * Last reply from: [bestdie3](https://wordpress.org/support/users/bestdie3/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/custom-validation-help/)
 * Status: resolved