Title: UAM &#039;allow_user_group&#039; shortcode
Last modified: August 21, 2016

---

# UAM 'allow_user_group' shortcode

 *  [Pat Garner](https://wordpress.org/support/users/wordpressorgpatgarnercom/)
 * (@wordpressorgpatgarnercom)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/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]
       ```
   
 * [https://wordpress.org/plugins/user-access-manager/](https://wordpress.org/plugins/user-access-manager/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [miyanke](https://wordpress.org/support/users/miyanke/)
 * (@miyanke)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/uam-allow_user_group-shortcode/#post-4867766)
 * I used it, but I can’t read it as admin of the site, ¿may I change something?
 *  Thread Starter [Pat Garner](https://wordpress.org/support/users/wordpressorgpatgarnercom/)
 * (@wordpressorgpatgarnercom)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/uam-allow_user_group-shortcode/#post-4867768)
 * You need to leave a code example. I have no idea what you are talking about “
   it.”
 *  [hidde1968](https://wordpress.org/support/users/hidde1968/)
 * (@hidde1968)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/uam-allow_user_group-shortcode/#post-4867811)
 * Hello, thank you for your shortcode.I have same issue.
    UAM can’t add admin user
   to any group. If I use this code, admin user can’t see THE CONTENT, because admin
   is not belong to GROUP_NAME.
 *     ```
       [allow_user_group groupname="GROUP_NAME"]
       THE CONTENT
       [/allow_user_group]
       ```
   
 * Do you have any idea how to show admin THE CONTENT ?
 * Thanks.
 *  Thread Starter [Pat Garner](https://wordpress.org/support/users/wordpressorgpatgarnercom/)
 * (@wordpressorgpatgarnercom)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/uam-allow_user_group-shortcode/#post-4867812)
 * Ohhhh, now I understand miyanke’s post. Y’all’s problems are that you can’t add
   admin user to a user group. Well you can’t use my shortcode for role, only for
   user groups. Instead you must use a shortcode that works with roles.
 * Google is your friend.
 * [http://blog.haraldkraft.de/2014/01/wordpress-shortcode-for-user-role-visibility/](http://blog.haraldkraft.de/2014/01/wordpress-shortcode-for-user-role-visibility/)
 *  [hidde1968](https://wordpress.org/support/users/hidde1968/)
 * (@hidde1968)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/uam-allow_user_group-shortcode/#post-4867813)
 * Than you for quick reply, Pat.
    And thank you for your infromation.
 * Sorry for my double post.
    Thanks again!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘UAM 'allow_user_group' shortcode’ is closed to new replies.

 * ![](https://ps.w.org/user-access-manager/assets/icon.svg?rev=1563783)
 * [User Access Manager](https://wordpress.org/plugins/user-access-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/user-access-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/user-access-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/user-access-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/user-access-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/user-access-manager/reviews/)

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [UAM](https://wordpress.org/support/topic-tag/uam/)

 * 5 replies
 * 3 participants
 * Last reply from: [hidde1968](https://wordpress.org/support/users/hidde1968/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/uam-allow_user_group-shortcode/#post-4867813)
 * Status: not resolved