Last active
April 28, 2016 15:58
-
-
Save amielucha/a092e9f78409a507f0db877bea767723 to your computer and use it in GitHub Desktop.
Get the Toolkit Access group assigned to a post within a loop and verify if currently logged-in user has permissions to access the list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // ----------------------------------------------------------------------------- | |
| // Usage: place the function in functions.php | |
| // Then call it from within the loop in the theme index.php, single.php etc. | |
| // while ( have_posts() ) : the_post(); if (iseek_user_access() ): | |
| // ... secret content goes here | |
| // endif; | |
| // ----------------------------------------------------------------------------- | |
| // Check if current user has permissions set in Toolkit Access plugin | |
| // Warning: only one group is allowed per post. It will not work for multiple groups. | |
| function iseek_user_access() { | |
| global $current_user; | |
| wp_get_current_user(); | |
| // Get current user ID | |
| $userId = get_current_user_id(); | |
| // Get the group assigned to the current post | |
| $post_meta = get_post_meta( get_the_ID() ); | |
| $access_group = $post_meta['_wpcf_access_group'][0]; | |
| if($access_group){ | |
| // check if user belongs to the group | |
| $access_option = get_option("wpcf-access-types"); | |
| // get the array of users who belong to $access_group | |
| $permitted_group_users = $access_option[ $access_group ]['permissions']['read']['users']; | |
| // Check if the currently logged-in user is on the accepted users list | |
| return in_array( $userId, $permitted_group_users ) ? true : false; | |
| } else { | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment