Validate User Emails for WordPress Blog Registrations
As a WordPress blog owner, user registrations and comments are key to community. Ensure every new user or commenter uses a valid email, combating spam and enhancing your site's credibility.
The problem
Running a WordPress blog with open registrations or comment sections often attracts a significant amount of spam. Bots and malicious users create fake accounts or leave comments with invalid email addresses, intending to post spam links or disrupt discussions. This not only clutters your backend with junk data but also degrades the user experience for legitimate visitors, making your blog appear less professional and trustworthy. Manually moderating and deleting these spam entries is a constant, time-consuming battle.
The proliferation of fake user accounts or comments linked to invalid emails can negatively impact your blog's SEO and overall reputation. Search engines prioritize websites with genuine engagement, and a high volume of spam can signal low quality. Furthermore, if you rely on email for user notifications or community building, sending to invalid addresses results in high bounce rates, damaging your sender score and potentially leading to your legitimate emails being marked as spam.
How Verifyr solves it
Concrete example
<?php
add_filter('registration_errors', 'verifyr_validate_registration_email', 10, 3);
function verifyr_validate_registration_email($errors, $sanitized_user_login, $user_email) {
$api_key = 'YOUR_VERIFYR_API_KEY';
$response = wp_remote_post('https://api.verifyrhq.com/validate', [
'headers' => ['Content-Type' => 'application/json', 'X-API-KEY' => $api_key],
'body' => json_encode(['email' => $user_email])
]);
if (!is_wp_error($response) && $response['response']['code'] === 200) {
$data = json_decode(wp_remote_retrieve_body($response), true);
if ($data['status'] !== 'valid' || $data['disposable']) {
$errors->add('email_error', __('<strong>ERROR</strong>: Please enter a valid, non-disposable email address.'));
}
}
return $errors;
}
?>