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

后端 未结 3 1946
情书的邮戳
情书的邮戳 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:04

    You can either overload the wp_authenticate function (see the function in the code here: http://core.trac.wordpress.org/browser/trunk/wp-includes/pluggable.php) and return a WP_error if you don't want to allow the user to login.

    Or better, use the filter authenticate and return null if you don't want the user to log in, e.g.

    add_filter('authenticate', 'check_login', 10, 3);
    function check_login($user, $username, $password) {
        $user = get_userdatabylogin($username); 
    
        if( /* check to see if user is allowed */ ) {
            return null;
        }
        return $user;
    }
    

提交回复
热议问题