GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions
GravityView_Roles_Capabilities Class Reference

GravityView Roles Class. More...

Public Member Functions

 __construct ()
 Get things going. More...
 
 add_caps ()
 Add capabilities to their respective roles if they don't already exist This could be simpler, but the goal is speed. More...
 
 filter_user_has_cap ( $usercaps=array(), $caps=array(), $args=array(), $user=NULL)
 Add support for gravityview_full_access capability, and. More...
 
 members_register_cap_group ()
 Add GravityView group to Members 1.x plugin management screen. More...
 
 remove_caps ()
 Remove all GravityView caps_to_check from all roles. More...
 

Static Public Member Functions

static all_caps ( $single_role=false, $flat_array=true)
 Get an array of GravityView capabilities. More...
 
static get_instance ()
 
static has_cap ( $caps_to_check='', $object_id=null, $user_id=null)
 Check whether the current user has a capability. More...
 
static maybe_add_full_access_caps ( $caps_to_check=array())
 Add Gravity Forms and GravityView's "full access" caps when any other caps are checked against. More...
 
static merge_with_all_caps ( $caps)
 Merge capabilities array with GravityView capabilities. More...
 

Static Public Attributes

static $instance = null
 

Private Member Functions

 add_gravity_forms_usercaps_to_gravityview_caps ( $usercaps)
 If a user has been assigned custom capabilities for Gravity Forms, but they haven't been assigned similar abilities in GravityView yet, we give temporary access to the permissions, until they're set. More...
 
 add_hooks ()
 
 wp_roles ()
 Retrieves the global WP_Roles instance and instantiates it if necessary. More...
 

Detailed Description

GravityView Roles Class.

This class handles the role creation and assignment of capabilities for those roles.

Since
1.15

Definition at line 23 of file class-gravityview-roles-capabilities.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Get things going.

Since
1.15

Definition at line 48 of file class-gravityview-roles-capabilities.php.

References add_hooks().

Member Function Documentation

◆ add_caps()

add_caps ( )

Add capabilities to their respective roles if they don't already exist This could be simpler, but the goal is speed.

Since
1.15
Returns
void

When $use_db is true, add_cap() performs update_option() every time. We disable updating the database here, then re-enable it below.

Update the option, as it does in add_cap when $use_db is true

See also
WP_Roles::add_cap() Original code

Restore previous $use_db setting

Definition at line 196 of file class-gravityview-roles-capabilities.php.

References wp_roles().

◆ add_gravity_forms_usercaps_to_gravityview_caps()

add_gravity_forms_usercaps_to_gravityview_caps (   $usercaps)
private

If a user has been assigned custom capabilities for Gravity Forms, but they haven't been assigned similar abilities in GravityView yet, we give temporary access to the permissions, until they're set.

This is for custom roles that GravityView_Roles_Capabilities::add_caps() doesn't modify. If you have a custom role with the ability to edit any Gravity Forms entries (gravityforms_edit_entries), you would expect GravityView to match that capability, until the role has been updated with GravityView caps.

Since
1.15
Parameters
array$usercapsUser's allcaps array
Returns
array

Definition at line 117 of file class-gravityview-roles-capabilities.php.

Referenced by filter_user_has_cap().

◆ add_hooks()

add_hooks ( )
private
Since
1.15

Definition at line 55 of file class-gravityview-roles-capabilities.php.

Referenced by __construct().

◆ all_caps()

static all_caps (   $single_role = false,
  $flat_array = true 
)
static

Get an array of GravityView capabilities.

See also
get_post_type_capabilities()
Since
1.15
Parameters
string$single_roleIf set, get the caps_to_check for a specific role. Pass 'all' to get all caps_to_check in a flat array. Default: all
boolean$flat_arrayTrue: return all caps in a one-dimensional array. False: a multi-dimensional array with $single_role as keys and the caps as the values
Returns
array If $role is set, flat array of caps_to_check. Otherwise, a multi-dimensional array of roles and their caps_to_check with the following keys: 'administrator', 'editor', 'author', 'contributor', 'subscriber'

Definition at line 244 of file class-gravityview-roles-capabilities.php.

◆ filter_user_has_cap()

filter_user_has_cap (   $usercaps = array(),
  $caps = array(),
  $args = array(),
  $user = NULL 
)

Add support for gravityview_full_access capability, and.

See also
map_meta_cap()
Since
1.15
Parameters
array$allcapsAn array of all the user's capabilities.
array$capsActual capabilities for meta capability.
array$argsOptional parameters passed to has_cap(), typically object ID.
WP_User | null$userThe user object, in WordPress 3.7.0 or higher
Returns
mixed

Enable all GravityView caps_to_check if gravityview_full_access is enabled

Definition at line 77 of file class-gravityview-roles-capabilities.php.

References add_gravity_forms_usercaps_to_gravityview_caps().

◆ get_instance()

static get_instance ( )
static

◆ has_cap()

static has_cap (   $caps_to_check = '',
  $object_id = null,
  $user_id = null 
)
static

Check whether the current user has a capability.

Since
1.15
See also
WP_User::user_has_cap()
https://codex.wordpress.org/Plugin_API/Filter_Reference/user_has_cap You can filter permissions based on entry/View/form ID using user_has_cap filter
GFCommon::current_user_can_any GFCommon::current_user_can_any
Parameters
string | array$caps_to_checkSingle capability or array of capabilities
int | null$object_id(optional) Parameter can be used to check for capabilities against a specific object, such as a post or us
int | null$user_id(optional) Check the capabilities for a user who is not necessarily the currently logged-in user
Returns
bool True: user has at least one passed capability; False: user does not have any defined capabilities
Runs Filter:
gravityview/capabilities/allow_logged_out Shall we allow a cap check for non-logged in users? USE WITH CAUTION!

WARNING: This allows anyone to edit and delete entries, add notes, delete notes, etc!

If you use this filter, at least check against certain capabilities and $object_ids.

There are use-cases, albeit strange ones, where we'd like to check and override capabilities for for a non-logged in user.

Examples, you ask? https://github.com/gravityview/GravityView/issues/826

Parameters
boolean$allow_logged_outAllow the capability check or bail without even checking. Default: false. Do not allow. Do not pass Go. Do not collect $200.
string | array$caps_to_checkSingle capability or array of capabilities to check against
int | null$object_id(optional) Parameter can be used to check for capabilities against a specific object, such as a post or us.
int | null$user_id(optional) Check the capabilities for a user who is not necessarily the currently logged-in user.

We bail with a negative response without even checking if:

  1. The current user is not logged in and non-logged in users are considered unprivileged (
    See also
    gravityview/capabilities/allow_logged_out filter).
  2. If the caps to check are empty.

Definition at line 336 of file class-gravityview-roles-capabilities.php.

Referenced by GravityView_Field_Is_Starred\get_content(), GVCommon\has_cap(), and GravityView_Field_Is_Starred\print_script().

◆ maybe_add_full_access_caps()

static maybe_add_full_access_caps (   $caps_to_check = array())
static

Add Gravity Forms and GravityView's "full access" caps when any other caps are checked against.

Since
1.15
Parameters
array$caps_to_check
Returns
array

Definition at line 405 of file class-gravityview-roles-capabilities.php.

◆ members_register_cap_group()

members_register_cap_group ( )

Add GravityView group to Members 1.x plugin management screen.

See also
members_register_cap_group()
Since
1.15
Returns
void

Definition at line 141 of file class-gravityview-roles-capabilities.php.

References $args.

◆ merge_with_all_caps()

static merge_with_all_caps (   $caps)
static

Merge capabilities array with GravityView capabilities.

Since
1.15 Used to add GravityView caps to the Members plugin
Parameters
array$capsExisting capabilities
Returns
array Modified capabilities array

Definition at line 163 of file class-gravityview-roles-capabilities.php.

◆ remove_caps()

remove_caps ( )

Remove all GravityView caps_to_check from all roles.

Since
1.15
Returns
void

Remove all GravityView caps_to_check from all roles

Definition at line 432 of file class-gravityview-roles-capabilities.php.

References wp_roles().

◆ wp_roles()

wp_roles ( )
private

Retrieves the global WP_Roles instance and instantiates it if necessary.

See also
wp_roles() This method uses the exact same code as wp_roles(), here for backward compatibility

WP_Roles $wp_roles WP_Roles global instance.

Returns
WP_Roles WP_Roles global instance if not already instantiated.

Definition at line 179 of file class-gravityview-roles-capabilities.php.

Referenced by add_caps(), and remove_caps().

Field Documentation

◆ $instance

$instance = null
static

Definition at line 28 of file class-gravityview-roles-capabilities.php.


The documentation for this class was generated from the following file: