強制使用 Ultimate Member 插件進行電子郵件驗證,必須為特定的郵件後綴。

正在查看 2 個帖子:1-2 (共 2 個帖子)
  • 作者
    帖子
  • 詩語
    管理員
    • 文章數量: 5,932
    @feibisi
    樓主

    直接貼代碼上來吧,暫時我們還沒啓用,但後面如果被垃圾註冊用户和註冊機給弄煩了還是會開啓的,下面的代碼修改

    @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') ) );
    }

    效果的話沒測試,但後台插件自帶的那個屏蔽郵件黑名單不起作用,也沒轍,這個算是加個白名單功能。

    詩語
    管理員
    • 文章數量: 5,932
    @feibisi
    樓主

    官方也提供了一個示例的代碼片段,可以嘗試,默認是 @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 個帖子)
  • 哎呀,回覆話題必需登錄。

話題信息

  • 當前位於:Ultimate Member
  • 1 條回覆
  • 1 個參與人
  • 最後回覆:<a href="https://bbs.weixiaoduo.com/users/feibisi/" title=" 查看詩語的個人資料" class="bbp-author-link"><span class="bbp-author-name"> 詩語</span></a>
  • 上次活動:<a href="https://bbs.weixiaoduo.com/topic/34471/#post-34472" title=" 回覆至:強制使用 Ultimate Member 插件進行電子郵件驗證,必須為特定的郵件後綴。">5 年、 2 月前</a>