How do I hook into the Wordpress login system to stop some users programmatically?

后端 未结 3 1951
情书的邮戳
情书的邮戳 2020-12-31 14:22

I am working on a Wordpress based portal which integrates with a custom-made e-commerce. The e-commerce serves also as a \'control panel\': all the roles are set up there.

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 15:14

    There were a few issues with mjangda answer so I'm posting a version that works with WordPress 3.2

    The main issues were with the return statement. He should be returning a WP_User Object. The other issue was with the priority not being high enough.

    add_filter('authenticate', 'check_login', 100, 3);
    function check_login($user, $username, $password) {
        // this filter is called on the log in page
        // make sure we have a username before we move forward
        if (!empty($username)) {
            $user_data = $user->data;
    
            if (/* check to see if user is allowed */) {
              // stop login
              return null;
            }
            else {
                return $user;
            }
        }
    
        return $user;
    }
    

提交回复
热议问题