I have functions that have to execute based on the user roles. How do I check the user role so that I can insert the respective function under their role?
EG.
if ($_GET['role'] == "free member" ) {//insert funtion 1}
elseif if ($_GET['role'] == "sliver member" ) {//insert funtion 2}
else {//insert funtion 3}
I tried using current_user_can, like this :
global $get_currentuserinfo, $current_user;
if( current_user_can('free_member') ) {//insert funtion 1}
elseif current_user_can('sliver_member'){//insert funtion 2}
else {//insert funtion 3}
This work with default role like “editor”,”author”, “contributor”. but seem doesn’t work with custom role that created by role managing plugin. I am using Advanced Access Manager to create the custom role by the way.
Since this role checking snippet is using in writing panel, so what approach is best to check the user role?
Looking around Google for a few minutes yielded several promising results.
Here’s a more detailed one adapted from a snippet on The Code Collective:
This will return an array of the user passed in as
$user_id
.