I am developing a script that is going to check a get request against our WP database. I have been able to get by just fine until now.
Now I need to check the role associated with the email from the get request in the database. As seen here I know the user role is stored in the wp_usermeta table in the meta_value columns.
I need to run a conditional in my script where if the user role is subscriber then I will echo out "Disabled" and if it is our custom role ntnw_member then I will echo out "Enabled".
Here is what I see in the field for the meta_value column just for an example:
a:1:{s:11:"ntnw_member";b:1;}
I just need to get the part in between the double quotes and check if it is equal to either subscriber or ntnw_member.
here is attempt at the query - Note the checkRole variable is where I am getting stuck:
/**************************************************
Get our request and test against database
**************************************************/
if(isset($_GET["email"])) {
$userEmail = mysqli_real_escape_string($connect, $_GET["email"]);
//check email against database
$checkEmail = mysqli_query($connect, "select * from wp_usermeta WHERE meta_value = '$userEmail'") or die('Error: ' . mysqli_error($connect));
if(mysqli_num_rows($checkEmail)>0){
while ($row = mysqli_fetch_array($checkEmail, MYSQL_ASSOC)) {
//get the user_id from database
$userID = $row[user_id];
$subscriber = Array(
'subscriber' => 1
);
$ntnwMember = Array(
'ntnw_member' => 1
);
$checkRole = mysqli_query($connect, "select * from wp_usermeta WHERE user_id = '$userID' AND meta_value = '$ntnwMember'") or die('Error: ' . mysqli_error($connect));
if ($checkRole){
echo 'Enabled';
} else {
echo 'Disabled';
}
} //end while $row
} else {
//if email address does not match anything on file, kill this script
die('Failed: Your email address does not match our records');
} //end if if(mysqli_num_rows($checkEmail)>0){}
} //endif isset