• I previously used code to only allow users from certain (Administrator identified) domains to register, but it relies on wp register and doesn’t work with Simple User Registration Pro.

    Is there similar code I can add, a modification to the current code (included below), possibly a Simple User Registration Pro update that will allow me to identify specific domains that must be used for registration?

    function is_valid_email_domain($login, $email, $errors ){
    $valid_email_domains = array(“example.com”,”anotherexample.com”);// allowed domains
    $valid = false; // sets default validation to false
    foreach( $valid_email_domains as $d ){
    $d_length = strlen( $d );
    $current_email_domain = strtolower( substr( $email, -($d_length), $d_length));
    if( $current_email_domain == strtolower($d) ){
    $valid = true;
    break;
    }
    }
    // Return error message for invalid domains
    if( $valid === false ){

    $errors->add(‘domain_whitelist_error’,__( ‘ERROR: Registration is only allowed from approved domains. If you think you are seeing this in error, please contact the system administrator.’ ));
    }
    }
    add_action(‘register_post’, ‘is_valid_email_domain’,10,3 );

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Only allow certain domains to register’ is closed to new replies.