WordPress
Email checker for WordPress. Verify emails in contact forms, WooCommerce, and user registration.
Adicione verificação de e-mail em tempo real ao seu site WordPress. Valide e-mails em formulários de contato, registro e checkout do WooCommerce.
Métodos de Integração
| Método | Melhor Para | Complexidade |
|---|---|---|
| Plugin | Configuração rápida | Baixa |
| Contact Form 7 | Usuários de CF7 | Baixa |
| WPForms | Usuários de WPForms | Baixa |
| PHP Personalizado | Controle total | Média |
Método 1: Plugin EmailVerify
Instale nosso plugin oficial do WordPress para a integração mais fácil.
Instalação
- Vá para Plugins → Adicionar Novo
- Pesquise por "EmailVerify Email Verification"
- Clique em Instalar Agora e depois Ativar
- Vá para Configurações → EmailVerify
- Digite sua chave de API
Configuração
// wp-config.php (opcional)
define('EMAILVERIFY_API_KEY', 'bv_live_xxx');Recursos
- Verificação em tempo real em todos os formulários
- Bloquear e-mails descartáveis
- Bloquear e-mails baseados em função
- Mensagens de erro personalizáveis
- Integração com WooCommerce
- Validação AJAX
Método 2: Contact Form 7
Adicione verificação aos formulários do Contact Form 7.
Usando Hooks
// functions.php
add_filter('wpcf7_validate_email*', 'emailverify_cf7_validation', 20, 2);
function emailverify_cf7_validation($result, $tag) {
$email = isset($_POST[$tag->name]) ? sanitize_email($_POST[$tag->name]) : '';
if (empty($email)) {
return $result;
}
$verification = emailverify_check_email($email);
if ($verification['status'] === 'invalid') {
$result->invalidate($tag, 'Digite um endereço de e-mail válido.');
}
if ($verification['result']['disposable']) {
$result->invalidate($tag, 'E-mails descartáveis não são permitidos.');
}
return $result;
}
function emailverify_check_email($email) {
$api_key = defined('EMAILVERIFY_API_KEY')
? EMAILVERIFY_API_KEY
: get_option('emailverify_api_key');
$response = wp_remote_post('https://api.emailverify.ai/v1/verify', [
'headers' => [
'Authorization' => 'Bearer ' . $api_key,
'Content-Type' => 'application/json',
],
'body' => json_encode(['email' => $email]),
'timeout' => 10,
]);
if (is_wp_error($response)) {
return ['status' => 'unknown'];
}
return json_decode(wp_remote_retrieve_body($response), true);
}Configuração da Tag do Formulário
[email* your-email class:emailverify-email]Método 3: WPForms
Integre com WPForms usando validação personalizada.
Validação PHP
// functions.php
add_filter('wpforms_process_before_form_data', 'emailverify_wpforms_validation', 10, 2);
function emailverify_wpforms_validation($form_data, $entry) {
foreach ($entry['fields'] as $field_id => $value) {
$field = $form_data['fields'][$field_id] ?? null;
if ($field && $field['type'] === 'email' && !empty($value)) {
$verification = emailverify_check_email($value);
if ($verification['status'] === 'invalid') {
wpforms()->process->errors[$form_data['id']][$field_id] =
'Digite um endereço de e-mail válido.';
}
if ($verification['result']['disposable'] ?? false) {
wpforms()->process->errors[$form_data['id']][$field_id] =
'E-mails descartáveis não são permitidos.';
}
}
}
return $form_data;
}Método 4: Integração PHP Personalizada
Para controle total, integre-se diretamente com nossa API.
Classe Auxiliar
<?php
// includes/class-emailverify.php
class EmailVerify {
private $api_key;
private $api_url = 'https://api.emailverify.ai/v1';
public function __construct($api_key = null) {
$this->api_key = $api_key ?: get_option('emailverify_api_key');
}
public function verify($email) {
$response = wp_remote_post($this->api_url . '/verify', [
'headers' => [
'Authorization' => 'Bearer ' . $this->api_key,
'Content-Type' => 'application/json',
],
'body' => json_encode(['email' => $email]),
'timeout' => 10,
]);
if (is_wp_error($response)) {
return [
'success' => false,
'error' => $response->get_error_message(),
];
}
$body = json_decode(wp_remote_retrieve_body($response), true);
return [
'success' => true,
'data' => $body,
];
}
public function is_valid($email) {
$result = $this->verify($email);
return $result['success'] && $result['data']['status'] === 'valid';
}
public function is_disposable($email) {
$result = $this->verify($email);
return $result['success'] && ($result['data']['result']['disposable'] ?? false);
}
}Uso
$bv = new EmailVerify();
// Verificação básica
$result = $bv->verify('user@example.com');
if ($result['data']['status'] === 'valid') {
// E-mail é válido
}
// Verificações rápidas
if ($bv->is_valid('user@example.com')) {
// Processar e-mail válido
}
if ($bv->is_disposable('user@example.com')) {
// Bloquear e-mail descartável
}Registro do WordPress
Verifique e-mails durante o registro do usuário.
// functions.php
add_filter('registration_errors', 'emailverify_registration_check', 10, 3);
function emailverify_registration_check($errors, $sanitized_user_login, $user_email) {
$bv = new EmailVerify();
$result = $bv->verify($user_email);
if (!$result['success']) {
return $errors; // Permitir registro se a API falhar
}
$data = $result['data'];
if ($data['status'] === 'invalid') {
$errors->add('invalid_email',
'<strong>Erro</strong>: Digite um endereço de e-mail válido.');
}
if ($data['result']['disposable'] ?? false) {
$errors->add('disposable_email',
'<strong>Erro</strong>: Endereços de e-mail temporários não são permitidos.');
}
return $errors;
}Validação AJAX
Adicione validação em tempo real com JavaScript.
Endpoint PHP
// functions.php
add_action('wp_ajax_verify_email', 'emailverify_ajax_verify');
add_action('wp_ajax_nopriv_verify_email', 'emailverify_ajax_verify');
function emailverify_ajax_verify() {
check_ajax_referer('emailverify_nonce', 'nonce');
$email = sanitize_email($_POST['email'] ?? '');
if (empty($email)) {
wp_send_json_error(['message' => 'E-mail é obrigatório']);
}
$bv = new EmailVerify();
$result = $bv->verify($email);
if ($result['success']) {
wp_send_json_success($result['data']);
} else {
wp_send_json_error(['message' => 'Verificação falhou']);
}
}
// Enfileirar scripts
add_action('wp_enqueue_scripts', 'emailverify_enqueue_scripts');
function emailverify_enqueue_scripts() {
wp_enqueue_script('emailverify',
get_template_directory_uri() . '/js/emailverify.js',
['jquery'],
'1.0.0',
true
);
wp_localize_script('emailverify', 'emailverify_ajax', [
'url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('emailverify_nonce'),
]);
}JavaScript
// js/emailverify.js
jQuery(function($) {
$('input[type="email"]').on('blur', function() {
var $input = $(this);
var email = $input.val();
if (!email) return;
$input.addClass('verifying');
$.post(emailverify_ajax.url, {
action: 'verify_email',
nonce: emailverify_ajax.nonce,
email: email
})
.done(function(response) {
$input.removeClass('verifying');
if (response.success) {
var data = response.data;
if (data.status === 'invalid') {
showError($input, 'Digite um endereço de e-mail válido');
} else if (data.result && data.result.disposable) {
showError($input, 'E-mails descartáveis não são permitidos');
} else {
showSuccess($input);
}
}
})
.fail(function() {
$input.removeClass('verifying');
});
});
function showError($input, message) {
$input.addClass('error').removeClass('valid');
$input.next('.bv-message').remove();
$input.after('<span class="bv-message error">' + message + '</span>');
}
function showSuccess($input) {
$input.addClass('valid').removeClass('error');
$input.next('.bv-message').remove();
$input.after('<span class="bv-message valid">✓</span>');
}
});CSS
/* style.css */
input[type="email"].verifying {
background-image: url('spinner.gif');
background-position: right 10px center;
background-repeat: no-repeat;
}
input[type="email"].error {
border-color: #dc3545;
}
input[type="email"].valid {
border-color: #28a745;
}
.bv-message {
display: block;
font-size: 12px;
margin-top: 4px;
}
.bv-message.error {
color: #dc3545;
}
.bv-message.valid {
color: #28a745;
}Cache
Armazene em cache os resultados de verificação para reduzir as chamadas de API.
function emailverify_check_email_cached($email) {
$cache_key = 'bv_email_' . md5($email);
$cached = get_transient($cache_key);
if ($cached !== false) {
return $cached;
}
$result = emailverify_check_email($email);
// Armazene em cache por 24 horas
set_transient($cache_key, $result, DAY_IN_SECONDS);
return $result;
}Melhores Práticas
1. Degradação Graciosa
Sempre permita o envio do formulário se a API falhar:
$result = $bv->verify($email);
if (!$result['success']) {
// Registre o erro mas não bloqueie o usuário
error_log('EmailVerify API error: ' . $result['error']);
return; // Permitir envio
}2. Limite de Taxa
Previna abuso com limite de taxa:
function emailverify_rate_limit($email) {
$ip = $_SERVER['REMOTE_ADDR'];
$key = 'bv_rate_' . md5($ip);
$count = get_transient($key) ?: 0;
if ($count >= 10) { // 10 verificações por minuto
return false;
}
set_transient($key, $count + 1, MINUTE_IN_SECONDS);
return true;
}3. Segurança
Sempre limpe e valide as entradas:
$email = sanitize_email($_POST['email']);
if (!is_email($email)) {
// Formato inválido, não é necessário chamar a API
return;
}