- This topic has 6 replies, 3 voices, and was last updated 3 years, 4 months ago by Tom.
-
AuthorPosts
-
November 26, 2020 at 7:18 am #1549889Benjamin
Hello,
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:
https://dropshare-files.s3-eu-west-1.amazonaws.com/Screen-Shot-2020-11-26-16-15-48.jpg
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 SupportHi there,
try this instead, create a new Hook Element or Block Element.
Select the Hook > Custom Hook and add:generate_do_template_part
You can either leave the Hook/Block content empty or add your own custom content for protected pages.
Then set your Display Rules
November 27, 2020 at 9:24 am #1552934BenjaminThanks 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 DeveloperThe 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:
https://dropshare-files.s3-eu-west-1.amazonaws.com/Screen-Shot-2020-11-27-21-57-06.28.jpg
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 #1553495BenjaminHumm, 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 DeveloperThe 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 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.