pmpro_set_capabilities_for_role

The Paid Memberships Pro pmpro set capabilities for role function.

Description

pmpro_set_capabilities_for_role( (string) $role_name, (string) $action = 'enable' ); 

Parameters (2)

0. $role_name (string)
The role name.
1. $action — Optional. (string) => 'enable'
The action.

Usage

  1. if ( !function_exists( 'pmpro_set_capabilities_for_role' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/capabilities.php'; 
  3.  
  4. // The role name. 
  5. $role_name = ''; 
  6.  
  7. // The action. 
  8. $action = 'enable'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = pmpro_set_capabilities_for_role($role_name, $action); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/capabilities.php  
  1. function pmpro_set_capabilities_for_role( $role_name, $action = 'enable' ) 
  2. $cap_array = pmpro_get_capability_defs($role_name); 
  3.  
  4. //add caps to specified role 
  5. $role = get_role( $role_name ); 
  6.  
  7. // Iterate through the relevant caps for the role & add or remove them 
  8. foreach( $cap_array as $cap_name ) 
  9. if ( $action == 'enable' ) 
  10. $role->add_cap($cap_name); 
  11.  
  12. if ( $action == 'disable' ) 
  13. $role->remove_cap($cap_name);