• Resolved bestdie3

    (@bestdie3)


    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/

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