Formidable Forms: Hide Form Based on User Capability

formidable forms plugin for wordpressHave you ever wanted a little more control over who can access your Formidable forms than just the user level settings? Here’s a very quick and simple PHP function to hide your Formidable forms from any user who does not have a specific capability set.

The following PHP function can be added to your theme’s functions.php file or, what I recommend, by creating a simple little plugin and adding it to the plugin’s php file. Either way, this function looks for a specific form and when it finds it, checks the user’s capability to be sure they are authorized to view the form. If so, the see the form like normal. If not, they see nothing or an alternative, such as a message telling them they are not authorized.

Checking Capability Before Showing Formidable Forms

Line 4 is where you set the id of your form and line 6 is an optional message to display in place of your form. Like I said, pretty simple.

Now here’s an untested idea to spark a little thought and conversation.

What if you want to show a different form or a Formidable view when the user doesn’t have the capability to see this form? Just about anything you can do with a Formidable Forms shortcode has a PHP version in the documentation. You could add additional code just above line 7 and it will run in place of the form being checked.

Adding Capabilities Using Formidable Forms

You could also have Formidable Forms set a user’s capability when the form is submitted.

formidable forms plugin for wordpressThis function uses a checkbox field in a form that, when checked, adds the capability and if not checked and the form is updating, will remove the capability. An example of how I used something like this recently is for a site that had two types of users and each had their own dashboard. The dashboards are designed to show based on the user’s capability so after they log in, they automatically see one or the other, (or both, but that’s for anther article!).

The other thing to note about this function is that it uses both Formidable Forms hooks, frm_after_create_entry and frm_after_update_entry. This is important because we want to set or remove capabilities on both entry creation and entry updates.

How will you use this? Got ideas? Add them to the comments and let’s start a conversation!

2 Comments

  1. Daniel Fascia on July 9, 2015 at 2:50 PM

    The combination of Justin Tadlock’s Members plugin and Formidable Pro can be used quite effectively to fashion an entire membership site since he has based it on the WP user roles.

    It still doesn’t work for sites with multiple product based memberships however such as course sites since it relies on roles and not capabilities.



  2. Michael Davis on July 9, 2015 at 3:16 PM

    Hey Daniel,

    That’s a common issue with membership plugins, it seems. I’m surprised Justin’s was based on roles because he built that plugin pretty recently, didn’t he?

    Because I prefer to use capabilities instead of roles for members, I tend to just build all of it in Formidable and bypass user plugins altogether.



Leave a Comment





This site uses Akismet to reduce spam. Learn how your comment data is processed.