lundi 23 mars 2015

Wordpress Authenticate Login / Problem when user is created



// check active status (login)
add_filter( 'wp_authenticate_user', 'check_active', 30, 3 );
function check_active( $user, $username) {
global $current_user,$wpdb;

$user_info = get_user_by( 'login', $username );
$active = $user_info->active;


$check_db = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE user_login = $username");

foreach ( $check_db as $choice )
{$status_active= $choice->active;};

if (is_admin($username)) {
return $user;
}

if ($status_active) {
return $user;
}
else
{
return new WP_Error( 'broke', __( "Your account is not active","not_active" ) );
}
}

function is_admin($user)
{
global $wpdb;
global $current_user;

$user_info = get_user_by( 'login', $user );
$uid = $user_info->ID;


$role = $wpdb->get_var("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = 'wp_capabilities' AND user_id = $uid");

if(!$role) return 'non-user';
$rarr = unserialize($role);
$roles = is_array($rarr) ? array_keys($rarr) : array('non-user');
$rolaa = $roles[0];
if ($rolaa=='administrator') { return true;}
else {return false;}

}


I have problem this code because when I registered new user, this function doesn't work. I register new user, and I can loggin on the page, but I don't want this :/ I want login user when is activated for me





Aucun commentaire:

Enregistrer un commentaire