正在查看 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 個帖子)
- 哎呀,回覆話題必需登錄。