Show or Hide Fields Based On Role
Support › MB Conditional Logic › Show or Hide Fields Based On RoleResolved
- This topic has 18 replies, 13 voices, and was last updated 3 months, 3 weeks ago by
brkard.
-
AuthorPosts
-
September 1, 2021 at 10:38 PM #30543
Martin
ParticipantHi, I have a need to be able to show or hide certain fields based on user role.
My specific scenario is that I have a Custom Field form which has dates and checkboxes. I want admins to be able to use the date fields to enter dates and a different role to be able to edit the checkboxes.
Admin will access the form via the Dashboard against a CPT. The other roles will access it via a view in the frontend.
So I don't mind how the fields are made to show or not show. It could be via the view (ie show the dates as their values and the checkboxes from the forms) but I can't see a way to do it there. It could be using Conditional Logic but that only seems to be for inclusion based on other form values. The Include/Exclude options have code for user role but this applies to the whole form rather than individual fields (that would be great if we had that level of feature at a field scope).
Any suggestions?
September 2, 2021 at 10:16 PM #30554Long Nguyen
ModeratorHi Martin,
The extension MB Conditional Logic does not support show/hide a field based on user role. You can use the extension MB Include Exclude to do that and separate fields for other meta boxes.
September 3, 2021 at 3:30 AM #30560Martin
ParticipantAs far as I can see from the docs you set the Include Exclude at the whole meta box form level rather than the individual field level. I need that functionality at the field level if that's possible.
September 3, 2021 at 9:46 PM #30573Long Nguyen
ModeratorHi,
Thanks for your feedback. I'm going to inform the developer team to consider adding it to the to-do list for the future development of the plugin.
September 4, 2021 at 9:27 PM #30589Martin
ParticipantCool. Thanks. I'll split my fields out to 2 custom field groups for now so I can control them separately that way.
September 6, 2021 at 4:05 PM #30622justdoit123
Participantplease update, I also need that functionality at the field level if that's possible.
February 12, 2022 at 4:30 AM #33855Jason
Participant+1 for the need for this functionality.
June 8, 2022 at 11:45 PM #36377Rebecca Robertson
ParticipantI also need that functionality.
July 11, 2022 at 10:50 PM #36915vacdk
Participant+1 for this
It will make forms much easier to buildSeptember 19, 2022 at 10:57 PM #38352[email protected]
Participantany news on this - I want to be able to hide some fields based on a user role - or a membership level maybe -
September 20, 2022 at 2:17 AM #38356Martin
ParticipantAs others are interested in this functionality this is how I went about what I need in the end:
I took the PHP code and implemented it in Snippets (or in functions.php etc). This allowed me to set the 'required' setting for each field as a variable. I then got the user role in code before the form creation happened and set the variable accordingly.
November 2, 2022 at 5:05 PM #38930brkard
Participanthi..
this should not be too hard to implement..and this should be a feature...also i need to hide some fields from some user roles...especially for settings page fields..
+1 for this...December 19, 2022 at 11:31 AM #39913Alaan TV
ParticipantI found a solution that may help; you can set the
type
of the field based on the role, like this:[ 'name' => 'My field', 'id' => 'my_field', 'type' => current_user_can( 'administrator' ) ? 'text' : 'hidden', // Show only for admins. ],
Here, the type of the field will be
hidden
for none admin users andtext
for administrators.August 8, 2023 at 9:47 PM #42847beepop
Participant+1 - need this, especially for Meta Box User Profile
October 25, 2023 at 4:07 AM #43606Yasmine
Participant+1 - very, very needed for my form.
-
AuthorPosts
- You must be logged in to reply to this topic.