不用插件 - Wordpress 只允许特定邮箱后缀注册

直接将以下代码拷贝到 主题的 function.php

function is_allow_domains($login, $email, $errors ){
  $allow_domains = array(
    "gmail.com",
    "yahoo.com",
    "msn.com",
    "hotmail.com",
    "live.com",
    "aol.com",
    "ask.com",
    "qq.com",
    "163.com",
    "126.com",
    "189.cn",
    "139.com",
    "yeah.net",
    "sogou.com",
    "sohu.com",
    "sina.com",
    "mail.com",
    "inbox.com");// 允许注册的邮箱信息

  $valid = false;
  $pos = strpos($email, "@");
  $user_domain = strtolower( substr( $email, $pos+1));

  foreach( $allow_domains as $item ){
    if( $user_domain == $item ){
      $valid = true;
      break;
    }
  }
  // if invalid, return error message
  if( $valid === false ){
    $errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: 本站只支持以下域名的邮箱注册。' + implode(", ", $valid_email_domains) ));
  }
}
add_action('register_post', 'is_allow_domains',10,3 );

可以自行添加修改白名单目录