正在查看 2 个帖子:1-2 (共 2 个帖子)
-
作者帖子
-
直接贴代码上来吧,暂时我们还没启用,但后面如果被垃圾注册用户和注册机给弄烦了还是会开启的,下面的代码修改
@company1.com
@company2.com
@company3.com
的后缀为你想要用户使用的,比如 163 、 QQ 、 gmail 等等。代码放到子主题的功能文件 PHP 里。
add_action('um_before_new_user_register', 'require_google_email_for_signup'); function require_google_email_for_signup( $args ) { extract($args); // Store allowed domains in an array $allowed_domains = ['@company1.com', '@company2.com', '@company3.com']; // Set flag to false (fail-safe) $check = false; // Iterate through all allowed domains foreach( $allowed_domains as $domain ) { // If a match is found (remember to use lowercase emails!) // Update flag and break out of for loop if ( strpos( strtolower( $user_email ), $domain ) !== false ) { $check = true; break; } } if ( !$check ) exit( wp_redirect( add_query_arg('err', 'you_must_have_googlemail') ) ); }
效果的话没测试,但后台插件自带的那个屏蔽邮件黑名单不起作用,也没辙,这个算是加个白名单功能。
官方也提供了一个示例的代码片段,可以尝试,默认是
@gmail.com
,修改成你需要的即可。/* The following code will require @gmail.com as domain for user registrations. You can change @gmail.com to any provider you want. The code below requires a user email to be collected during registration */ add_action('um_before_new_user_register', 'require_google_email_for_signup'); function require_google_email_for_signup( $args ) { extract($args); if ( !strstr( $user_email, '@gmail.com' ) ) exit( wp_redirect( add_query_arg('err', 'you_must_have_googlemail') ) ); }
-
作者帖子
正在查看 2 个帖子:1-2 (共 2 个帖子)
- 哎呀,回复话题必需登录。