Support » Plugins » Custom error messages for register username

  • bcyork

    (@bcyork)


    I’m wanting to add a simple error message to this plugin script. The $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid. Use only lowercase letters' ) ); section was pulled from the base wordpress files but it breaks the plugin. How do I do this so I can have an error code that is specific?

    add_filter('validate_username' , 'custom_validate_username', 10, 2);
    
    function custom_validate_username($valid, $username ) {
    		if (preg_match("/\\s/", $username)) {
       			return $valid=false;
    		}
    		if (preg_match('/.*[A-Z]/', $username)) {
    			$errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid. Use only lowercase letters' ) );
    			return $valid=false;
    		}
    
    	return $valid;
    }
  • The topic ‘Custom error messages for register username’ is closed to new replies.