Hide content in templates with Groups

We have a do_action() part of our theme and want to restrict it to users of two specific groups only. How do we put that do_action() in between the shortcode in the template file?

We’ve looked at the API page and the do_shortcode but can’t figure out exactly how to do it.

Any help is appreciated, thank you.

Posted in

Comments

8 responses to “Hide content in templates with Groups”

  1. Eugen Bleck Avatar
    Eugen Bleck

    Hi Thomas,

    I trust you had a wonderful weekend and are doing great!

    Please can you provide the code they are using? You could use pastebin and share the link in the comment.

    Warm regards,
    Eugen.

    1. Thomas Trudeau Avatar
      Thomas Trudeau

      All I want to do is restrict this line of code to two specific Groups, which produces an info box on our theme: https://pastebin.com/kJs9Wku8

      Thanks for the help.

      1. Eugen Bleck Avatar
        Eugen Bleck

        Hi Thomas,

        Thanks for the prompt response.

        However, I don’t think you can restrict a hook, as long as it is implemented everyone can use it.

        I’ll suggest you consider the shortcode approach to solving this issue. Implement a shortcode, wherein the shortcode callback function can do the group check and display company_box.

        Link to shortcodes codex: https://developer.wordpress.org/reference/functions/add_shortcode/

        Stay safe!
        Warm regards,
        Eugen.

  2. Thomas Trudeau Avatar
    Thomas Trudeau

    Hi there, yes I looked at this and we tried a few different things using that but couldn’t get it to work. In the theme we are using, we have this line of code that displays some information:

    We want to restrict this to logged-in users of two specific groups only using this shortcode somehow:
    [groups_member group="Advanced,Premium"][/groups_member]

    We tried to use some of the API info but our knowledge of it wasn’t good enough to get it working.

    Any further help much appreciated.

    1. Thomas Trudeau Avatar
      Thomas Trudeau

      Oops, realized the line of code didn’t get shown, this is the line of code we want to restrict:

      “”

      We looked at this “Does the current user belong to the Foobar group?” but couldnt figure out how to complete it with the shortcode parameters.

      Thank you

      1. Thomas Trudeau Avatar
        Thomas Trudeau

        Last try:
        “”

        Ignore the weird markup, just want to show it.

        1. Thomas Trudeau Avatar
          Thomas Trudeau

          Had to use screenshot, not sure how to paste code in here: https://ibb.co/0XXgTP7

  3. Eugen Bleck Avatar
    Eugen Bleck

    Hi Thomas,

    I trust you are safe and feeling awesome.

    Thanks for using Groups and its extension; Groups Restrict Categories.

    To best help you, I’ll need more information with regard to the tasks you are trying to accomplish.

    I’ll recommend you have a look at the example: Does the current user belong to the Foobar group? here: http://docs.itthinx.com/document/groups/api/examples/.

    Once more, thank you for reaching out and for using Groups Restrict Categories.

    Stay safe and I wish you a lovely weekend ahead.

    Kindest regards,
    Eugen.

Share