Block Free Email Domains at LearnDash Registration
Restrict LearnDash sign-ups to work email addresses by rejecting free and disposable domains in registration_errors, with the message wired into the form and an allowlist mode.

Corporate training portals, partner academies and continuing-education sites often need learners to register with a work address, both to tie the account to an organisation and to keep disposable addresses out. LearnDash 4.18.0.1 has no setting for this, but because its registration form submits through WordPress core, a single validation filter does the job. This article adds a blocklist of free and disposable domains, shows the rejection in the LearnDash form, and offers an allowlist variant for sites that only accept specific companies.
Where to validate
The LearnDash registration form posts to wp-login.php?action=register, and WordPress runs the registration_errors filter with the WP_Error object, the sanitized login and the email before creating the user. LearnDash hooks register_post at priority 99, applies the same filter, and on error redirects back to the LearnDash form with each error code as a query argument, printing a message for every code found in the map returned by learndash_login_error_conditions(). So the snippet has two parts: add the error, and add the code to that map through learndash_registration_errors. The full path is documented in our registration hooks and filters reference.
The snippet
<?php
/**
* Reject free and disposable email domains on registration.
*/
function wwc_blocked_email_domains() {
$domains = array(
'gmail.com',
'googlemail.com',
'yahoo.com',
'yahoo.co.uk',
'hotmail.com',
'outlook.com',
'live.com',
'aol.com',
'icloud.com',
'proton.me',
'protonmail.com',
'mailinator.com',
'guerrillamail.com',
'10minutemail.com',
'yopmail.com',
);
/**
* Filter the list of blocked registration email domains.
*
* @param string[] $domains Lower-case domain names.
*/
return apply_filters( 'wwc_blocked_email_domains', $domains );
}
function wwc_email_domain( $email ) {
$email = strtolower( trim( (string) $email ) );
$at = strrpos( $email, '@' );
return ( false === $at ) ? '' : substr( $email, $at + 1 );
}
add_filter(
'registration_errors',
function ( $errors, $sanitized_user_login, $user_email ) {
if ( ! is_email( $user_email ) ) {
return $errors; // Core already reports invalid emails.
}
$domain = wwc_email_domain( $user_email );
if ( in_array( $domain, wwc_blocked_email_domains(), true ) ) {
$errors->add( 'wwc_blocked_email_domain', __( 'Please register with your work email address.', 'wwc' ) );
}
return $errors;
},
10,
3
);
add_filter(
'learndash_registration_errors',
function ( $conditions ) {
$conditions['wwc_blocked_email_domain'] = __( 'Free and disposable email addresses are not accepted. Please use your work email.', 'wwc' );
return $conditions;
}
);
Unlike the custom field example, this check deliberately does not look for the LearnDash nonce, so it applies to the standard wp-login.php registration form too. If you only want to restrict the LearnDash form, add the nonce check shown in adding a custom field to the LearnDash registration form.
Matching subdomains and lookalikes
An exact match misses mail.yahoo.com style addresses and plus-addressed variants are already handled because the domain is what we compare. To block a domain and all its subdomains, compare the suffix instead:
<?php
foreach ( wwc_blocked_email_domains() as $blocked ) {
if ( $domain === $blocked || str_ends_with( $domain, '.' . $blocked ) ) {
$errors->add( 'wwc_blocked_email_domain', __( 'Please register with your work email address.', 'wwc' ) );
break;
}
}
Disposable providers rotate domains constantly, so a static list ages quickly. A maintained list can be loaded from a file in your plugin and refreshed with your deployments, or checked through a reputation API from the same callback with a short cache; fail open on API errors so an outage does not stop legitimate sign-ups.
Allowlist mode for closed cohorts
A partner academy that only serves three companies is simpler to express as an allowlist. Replace the condition:
<?php
$allowed = array( 'acme.example', 'globex.example', 'initech.example' );
if ( ! in_array( $domain, $allowed, true ) ) {
$errors->add( 'wwc_domain_not_allowed', __( 'Registration is limited to approved organisations.', 'wwc' ) );
}
and register wwc_domain_not_allowed in the learndash_registration_errors map. If each company maps to a LearnDash group, you can go one step further and enroll the new user into the matching group on user_register with ld_update_group_access( $user_id, $group_id ), which gives them the group's courses immediately; enrolling into groups in code covers that function.
Where the rule does not apply
- WooCommerce checkout registration uses
woocommerce_registration_errors, which receives the same three arguments, so the same function can be attached to it. - Multisite validates through
wpmu_validate_user_signup, which has its own banned-domain setting under Network Settings, Banned Email Domains. Use that instead. - Users created by administrators or imported through the REST API do not run
registration_errors. That is usually desirable. - Social login plugins create users through their own paths. Check whether yours calls the core filter.
Communicating the rule
Learners who hit the error after filling the whole form are annoyed, so say it up front. Print a sentence under the email field from learndash_registration_form_fields_after, and if the course is sold, state the requirement on the sales page as well. For sites that must still allow exceptions, give the error message a contact link so that a freelancer without a company domain has somewhere to go.
Logging rejected attempts
Record each rejection with the domain, never the full address, and the course the visitor came from, available as the posted ld_register_id. A week of that log tells you whether the rule is blocking real prospects at a particular company whose domain looks like a free provider, or whether disposable traffic is targeting one landing page. Write the entries through the LearnDash logger or a small custom table, and review them before adjusting the list rather than reacting to single complaints.
Existing learners on free providers
The filter only affects new registrations, so learners who signed up with a personal address before the rule remain untouched, and their logins keep working. If the organisation now requires work addresses for everyone, that is a profile-change task: hook user_profile_update_errors to apply the same domain check when a user edits their email, and run a one-off report of accounts on blocked domains to contact them. Do not change emails on their behalf; account recovery and purchase receipts depend on the address the learner controls.
Testing
- Register with a blocked domain and confirm the form reloads with the message and the other fields intact.
- Register with an uppercase domain such as
GMAIL.COMand confirm it is still blocked, because the domain is lower-cased before comparison. - Register with a work domain and confirm it succeeds.
- If you added the WooCommerce hook, repeat the first test at checkout.
When to get help
This filter is a half-hour task. Mapping domains to groups, verifying ownership of a company domain by email confirmation, or integrating a corporate directory for sign-up is where our LearnDash services team usually helps, and a LearnDash developer can also connect registration to your CRM through API integration.
Frequently asked questions
Which hook blocks email domains on the LearnDash registration form?
The core registration_errors filter, because the LearnDash form submits through WordPress registration. Register your error code with learndash_registration_errors so the form shows the message.
Does this block existing users with those addresses?
No. It only runs when a new account is being registered.
Can I allow only certain domains instead?
Yes. Invert the check to an allowlist as shown, and consider enrolling each domain into its LearnDash group on registration.
Why are disposable addresses still getting through?
Static lists go stale. Load a maintained list or add a reputation API check with caching and fail-open behaviour.
Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.
