• Resolved topi_r

    (@topi_r)


    Is possible to restrict registeration to certain domains with this plugin?

    I have a custom function for this hooked to add_action(‘register_post’, ‘is_valid_email_domain’); but it does not work with this plugin at the momement.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Justin Fletcher

    (@justinticktock)

    I can’t think of any reason why it wouldn’t work as all the normal hooks will be available. looking into the user.php hook description it states “If any errors are present in $errors, this will abort the user’s registration.” could this be your issue ?

    e.g. things like where your username or email address is used and already and registered to a different subsite.

    Thread Starter topi_r

    (@topi_r)

    add_action('register_post', 'is_valid_email_domain', 10, 3);
    function is_valid_email_domain($login, $email, $errors)
    {
        $allowed_domains = ['test.com', 'auto.com'];
        $valid = false;
        foreach ($allowed_domains as $domain) {
            $d_length = strlen($domain);
            $current_email_domain = strtolower(substr($email, -($d_length), $d_length));
            if ($current_email_domain === strtolower($domain)) {
                $valid = true;
                break;
            }
        }
        // Return error message for invalid domains
        if ($valid === false) {
            $errors->add('domain_whitelist_error', pll__('<strong>Error</strong>'));
        }
    }

    This is in functions.php. If plugin is in use all domains seems to be allowed for some reason. I tested this function with vanilla (single site) WP installation and it works.

    Plugin Author Justin Fletcher

    (@justinticktock)

    Try it with a multi site install without the NSUR plugin active. Does that work?
    It may also be impacting you that foe multisite registration is actually on the main site (for network registration) so it may need to be added there to.

    Plugin Author Justin Fletcher

    (@justinticktock)

    hi @topi_r … how did you get on ?
    I’m going to close this ticket now. however, if you want more support just continue here.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Restrict register certain domains’ is closed to new replies.