UAM 'allow_user_group' shortcode
-
For those times when you need finer access control granularity, when you need to hide/show a section of a page based upon the current user’s group, here is my solution. NOTE: I am not a PHP developer, just a casual user, so there are no doubt improvements that can be made to this.
I put this in functions.php:
/* Allow user group shortcode. Usage: [allow_user_group groupname="UAM_Group_Name|etcetera"]<HTML MARKUP>[/allow_user_group] */ add_shortcode('allow_user_group', 'allow_user_group_func'); function allow_user_group_func($atts, $content = '') { $result = ''; // <-- user does not have permission extract(shortcode_atts(array('groupname' => ''), $atts)); if(!empty($groupname)) { global $wpdb; $entries = $wpdb->get_results ( $wpdb->prepare ( "SELECT groupname FROM {$wpdb->prefix}uam_accessgroups uamag, {$wpdb->prefix}uam_accessgroup_to_object uamagto WHERE uamagto.group_id=uamag.id and uamagto.object_id=%d", wp_get_current_user()->ID ) ); $parts = explode("|", $groupname); foreach($parts as $part) { foreach($entries as $entry) { if(trim($entry->groupname) == trim($part)) { $result = $content; // <-- user has permission break; } } } } return $result; }
and I put the following into the page itself:
[allow_user_group groupname="Data_Top_Secret|Biatches_Only|etcetera"] You are authorized, biatch! [/allow_user_group]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘UAM 'allow_user_group' shortcode’ is closed to new replies.