只希望订阅者的角色用户登录该应用。我不知道在wordpress中获得订阅者角色。这是我的代码
$u_name = $_POST['userName'];
$password = $_POST['password'];
$username = $u_name;
//$tokenID = $_GET['tokenID'];
$vendor_list = array();
if ( username_exists( $username ) )
{
$user = get_user_by( 'login', $username );
if ( $user && wp_check_password( $password, $user->user_pass, $user->ID) )
{
$email = $user->user_email;
$vendor_list[] = array("userID"=>$user->ID,"userName" =>$username,"email" =>$email);
echo json_encode($vendor_list);
}
else
{
$testing = 2;
echo json_encode($testing);
}
}
else
{
$testing = 1;
echo json_encode($testing);
}
答案 0 :(得分:1)
$u_name = $_POST['userName'];
$password = $_POST['password'];
$username = $u_name;
//$tokenID = $_GET['tokenID'];
$vendor_list = array();
if ( username_exists( $username ) )
{
$user = get_user_by( 'login', $username );
if ( $user && wp_check_password( $password, $user->user_pass, $user->ID) && )
{
$users = wp_get_current_user();
if(in_array( 'subscriber', (array) $users->roles ) )
{
$email = $user->user_email;
$vendor_list[] = array("userID"=>$users->ID,"userName" =>$username,"email" =>$email);
echo json_encode($vendor_list);
}
else
{
$testing = 3;
echo json_encode($testing);
}
}
else
{
$testing = 2;
echo json_encode($testing);
}
}
else
{
$testing = 1;
echo json_encode($testing);
}