I'm just using the Magic Members plugin, and wondering if anyone has any experience checking permissions for an individual page. I'm looping through all of the child pages of one of the main pages, but different user levels will be able to view different child pages, so I need to be able to check and display that information based on whether the user has access to that particular child.
<?php
foreach($pages as $page):
if ($has_access):
?>
content for this child page prints out to the screen!
<?php
endif;
$i++;
endforeach;
?>
开发者_JS百科
How can I programmatically find out whether the user has the proper permissions to view that page ($has_access either true or false)?
Thanks!
It's not too difficult, actually. I got the answer from their custom support. Here it is, in case you are looking:
//current user
$current_user = wp_get_current_user();
//get membership type
$mgm_member = mgm_get_member($current_user->ID);
//mgm_array_dump($mgm_member); //you can uncomment this to see all of the available data for the member
$membership_type=$mgm_member->membership_type;
//then you can check for a certain user type
if ($membership_type=='client'){
//do something incredible here!
}
//current user
$current_user = wp_get_current_user();
//get membership type
$mgm_member = mgm_get_member($current_user->ID);
//mgm_array_dump($mgm_member); //you can uncomment this to see all of the available data for the member
$membership_type=$mgm_member->membership_type;
//then you can check for a certain user type
if ($membership_type=='client'){
//do something incredible here!
}
This code will only see if they were a member at one time in the life of your site. If they are payed up active member is another story.
just add this code:
//get member status
$membership_status=$mgm_member->status;
//then you can check for a certain user type
if ($membership_status=='Active'){
//do something incredible here!
}
精彩评论