Support » Plugin: Groups » Restricting Content in WordPress Templates

  • Resolved learnthat


    Is there a way to restrict content to members of a group in a theme template file? And display content to people who aren’t members of a group?

    In other words, is there a PHP equivalent to the groups_member group and groups_non_member shortcodes that I can use in a template file?


Viewing 7 replies - 1 through 7 (of 7 total)
  • Yep!:

    if( is_user_logged_is() ) {

    Plugin Author itthinx


    Using the is_user_logged_in() function is fine if the content is to be shown to a user who is logged in only, but @learnthat is asking if one can check based on group membership. In the Examples section it is shown how to check for group membership, that method can be used in a template to show content conditionally.

    So, I totally tried what you have based on the ‘examples’ page, but I must be doing something dumb, just not working for me. Is the way I have this code right?

      $is_a_member = false;
      require_once( ABSPATH . 'wp-includes/pluggable.php' );
      if ( $group = Groups_Group::read_by_name( 'Groupname' ) ) {
        $is_a_member = Groups_User_Group::read( get_current_user_id() , $group->group_id );
        // Do Stuff Here like maybe php html or jazz hands

    itthinx, I had the same problem as joshseltzer. Your example code doesn’t work as intended.

    What I found that it does do is that it checks if that group name exists, but not if the user belongs to it. Can you please supply a code example that does work.


    Plugin Author itthinx


    @joshseltzer @wpseeker the code is correct but you’re missing one obvious thing here, the conditional enclosing what you want to happen if it’s a member:

    if ( $is_a_member ) {
        // do what needs to be done for the member, for example ...
        echo 'Foo!';

    OK that worked! Thanks for the reply




    I need to hide WooCommerce stock info from public and make it available only to a group of users.
    It would be nice to have complete code that goes to theme function file.

    Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Restricting Content in WordPress Templates’ is closed to new replies.