• Building a website?

    We build professional, user-friendly and engaging websites for businesses and individuals who require an impressive online presence.

    We're ready to discuss your project today —

    Contact Creative World

  • Keep in touch

    Sign up for our 'not so monthly' newsletter - updates, offers, tips and more.





  • Archives

  • Related Pages

  • Related Posts

Roles & Capabilities with Gravity Forms & WordPress

Managing user roles & capabilities in WordPress can be frustrating, especially if you want to assign specific permissions to just a role or user.

I came across a situation today where we wanted to allow WordPress Authors the ability to view and edit entries from the Gravity Forms plugin. The Gravity Forms plugin is a supurb plugin for WordPress that allows you to easily set up and manage forms on your website.

A good first option is to utilise a good role management plugin such as Justin Tadlock’s Members plugin for WordPress. It’s a great plugin with many additional features outside the scope of this article that will allow you to manage not only Gravity Forms capabilities (and many more) to each role in WordPress.

However, if you want to cut down on using plugins as much as possible, we can achieve the same goal by using your theme’s functions.php file.

Add the following code to your wp-content/themes/<theme name>/functions.php file:

/* Add additional capabilities to a role or specific users for Gravity Forms */

// get role by name (change 'editor' to a role)
$role = get_role( 'editor' );
// or get user by user ID (change $id to an id)
// $role = new WP_User( $id );
// or get user by username (change $name to a username)
// $role = new WP_User( null, '$name' );

// add core gravity form capabilities
// adjust as required
$role->add_cap( 'gravityforms_edit_forms' );
$role->add_cap( 'gravityforms_delete_forms' );
$role->add_cap( 'gravityforms_create_form' );
$role->add_cap( 'gravityforms_view_entries' );
$role->add_cap( 'gravityforms_edit_entries' );
$role->add_cap( 'gravityforms_delete_entries' );
$role->add_cap( 'gravityforms_view_settings' );
$role->add_cap( 'gravityforms_edit_settings' );
$role->add_cap( 'gravityforms_export_entries' );
$role->add_cap( 'gravityforms_view_entry_notes' );
$role->add_cap( 'gravityforms_edit_entry_notes' );
// $role->add_cap( 'gravityforms_feed' );
// $role->add_cap( 'gravityforms_uninstall' );

// gravity form add-on capabilities
// Campaign Monitor
// $role->add_cap( 'gravityforms_campaignmonitor' );
// $role->add_cap( 'gravityforms_campaignmonitor_uninstall' );

// Freshbooks
// $role->add_cap( 'gravityforms_freshbooks' );
// $role->add_cap( 'gravityforms_freshbooks_uninstall' );

// MailChimp
// $role->add_cap( 'gravityforms_mailchimp' );
// $role->add_cap( 'gravityforms_mailchimp_uninstall' );

// PayPal
// $role->add_cap( 'gravityforms_paypal' );
// $role->add_cap( 'gravityforms_paypal_uninstall' );

// User Registration
// $role->add_cap( 'gravityforms_user_registration' );
// $role->add_cap( 'gravityforms_user_registration_uninstall' );

Gravity Form’s have published a full list of capabilities.

Keep in mind, the current setup above will apply these capabilities to all users with an editor role. If you want to apply these to just a specific user id or username, adjust the code accordingly. And by putting this in your functions.php the above will be theme based! Updating your theme could mean you’ll overwrite these changes, or if you use your theme on another website you’ll be applying these capabilities possible unnecessarily.

Pro Tip: Once you’ve added these permissions and they’ve taken effect, the users/roles stay in place even if you remove the code from your functions.php. To remove permissions from a user/role, do the save as above except change add_cap to remove_cap.

Tags: , , , ,


Author | Leon Poole

Leon Poole is owner and founder of the Brisbane Web Design company Creative World. He has a passion for designing websites, solving problems and improving the user experience. You can follow me on Twitter or Google+.

One Response to Roles & Capabilities with Gravity Forms & WordPress

  1. What about roles for certain forms?

Leave a Reply...

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Stop SOPA