- This topic has 6 replies, 3 voices, and was last updated 1 month, 2 weeks ago by Tom.
November 26, 2020 at 7:18 am #1549889Benjamin
GP is one inch away of providing a pretty useful function : display/hide (page/post) content based on User Role.
It has everything except the option to select “Full Page/Post content” in the disable elements window:
this way we could protect the entire page content to be viewed based on user role.
Thanks for evaluating the idea,November 26, 2020 at 7:37 am #1549940DavidStaffCustomer Support
try this instead, create a new Hook Element or Block Element.
Select the Hook > Custom Hook and add:
You can either leave the Hook/Block content empty or add your own custom content for protected pages.
Then set your Display RulesNovember 27, 2020 at 9:24 am #1552934Benjamin
Thanks for he suggestion, looks like it could indeed work to show/hide the content if needed.
However it looks like the Display Rules won’t allow me to do what I need:
I wanted to be able to have basic membership level and display rules made with solely GP.
e.g. if logged-in User Role is NOT (Membership1 OR Membership2) OR user is not logged in => display “please log in or buy a membership” else display the normal loop content.
TBH I’ve always wondered why the GP display rules aren’t more developer friendly (like the Widget Logic plugin, e.g. is_page() && is_logged_in())November 27, 2020 at 10:50 am #1553144TomLead DeveloperLead Developer
The Display Rules aren’t that complex, unfortunately. Once you start adding in OR and AND conditions, things start getting pretty messy.
It would be sweet to introduce a way to add your own conditions as you’ve mentioned. Not sure what that would look like when it comes to UI, but it’s worth exploring. Noted 🙂November 27, 2020 at 12:57 pm #1553414Benjamin
“Not sure what that would look like when it comes to UI, but it’s worth exploring.”
I think you could offer a simple field like the “Widget Logic” UI, where people could enter pure WP conditionals, like so:
Maybe hide this field under an “Advanced configuration” and indicate that what is entered in that field overwrites any configuration made with the “Location/Exclude/Users” UI fields.November 27, 2020 at 1:41 pm #1553495Benjamin
Humm, actually there is no WP conditionals to check if the current user belongs to a give Role, so in my case even if GP allowed advanced rules, it wouldn’t work…November 28, 2020 at 11:23 am #1555355TomLead DeveloperLead Developer
The trouble there is then executing those conditions, as they’re just strings at that point. Definitely something worth looking into.
There is a filter that you can use to add your own conditions as well: https://docs.generatepress.com/article/generate_hook_element_display/
May be worth playing with 🙂
- You must be logged in to reply to this topic.