Change WordPress user roles and capabilities Forums Bug Reports bug that prevents access to pardot / gravity forms functionality Reply To: bug that prevents access to pardot / gravity forms functionality

#5801
Vladimir
Keymaster

Hi James,

Gravity Forms adds menu for add-on if current user has access to this add-on. Permission is checked this way:


if ( $this->current_user_can_any( $this->_capabilities_plugin_page ) ) {
	//creates the subnav left menu
	add_filter( 'gform_addon_navigation', array( $this, 'create_plugin_page_menu' ) );
}

current_user_can_any() function works this way:


public static function current_user_can_any( $caps ) {

	if ( ! is_array( $caps ) ) {
		$has_cap = current_user_can( $caps ) || current_user_can( 'gform_full_access' );

		return $has_cap;
	}

	foreach ( $caps as $cap ) {
		if ( current_user_can( $cap ) ) {
			return true;
		}
	}

	$has_full_access = current_user_can( 'gform_full_access' );

	return $has_full_access;
}

Thus, _capabilities_plugin_page property is a key for access to the plugin. If user does not can _capabilities_plugin_page, code checks if user has older style full access to the GF plugin – ‘gform_full_access’.

_capabilities_plugin_page property of the base class for any add-on GFAddOn is empty by default:


	/**
	 * @var string|array A string or an array of capabilities or roles that have access to the plugin page
	 */
	protected $_capabilities_plugin_page = array();

“Pardot Connector” (PC) plugin does not define this property too. Thus the only way to get access to PC plugin when role editor plugin is active and GF uses detailed capabilities list instead of the single gform_full_access is to grant to a role gform_full_access.

Workaround (fix): add $_capabilities_plugin_page property to PC plugin, like this (look at the last line in the code fragment below):


class PardotGravityFormsConnectorAddOn extends GFFeedAddOn {

	protected $_version = PARDOT_GRAVITYFORMS_CONNECTOR_VERSION;
	protected $_min_gravityforms_version = '1.9';
	protected $_slug = 'pardot-gravityforms-connector';
	protected $_path = 'pardot-gravityforms-connector/pardot-gravityforms-connector.php';
	protected $_full_path = __FILE__;
	protected $_title = 'Pardot Gravity Forms Connector';
	protected $_short_title = 'Pardot Connector';
        protected $_capabilities_plugin_page = 'gravityforms_edit_settings';

This way ‘administrator’ role will get access to PC plugin without ‘gform_full_access’ capability.