[ Index ]

PHP Cross Reference of BackPress

title

Body

[close]

/includes/ -> class.bp-roles.php (source)

   1  <?php
   2  
   3  class BP_Roles {
   4      var $role_objects = array();
   5      var $role_names = array();
   6  
   7  	function __construct() {
   8          do_action_ref_array('init_roles', array(&$this) );
   9      }
  10  
  11  	function BP_Roles() {
  12          self::__construct();
  13      }
  14  
  15  	function add_role($role, $display_name, $capabilities = '') {
  16          if ( isset($this->role_objects[$role]) )
  17              return;
  18  
  19          $this->role_objects[$role] = new BP_Role($role, $capabilities, $this);
  20          $this->role_names[$role] = $display_name;
  21          return $this->role_objects[$role];
  22      }
  23  
  24  	function remove_role($role) {
  25          if ( ! isset($this->role_objects[$role]) )
  26              return;
  27  
  28          unset($this->role_objects[$role]);
  29          unset($this->role_names[$role]);
  30      }
  31  
  32  	function add_cap($role, $cap, $grant = true) {
  33          if ( isset($this->role_objects[$role]) )
  34              $this->role_objects[$role]->add_cap($cap, $grant);
  35      }
  36  
  37  	function remove_cap($role, $cap) {
  38          if ( isset($this->role_objects[$role]) )
  39              $this->role_objects[$role]->remove_cap($cap, $grant);
  40      }
  41  
  42      function &get_role($role) {
  43          if ( isset($this->role_objects[$role]) )
  44              return $this->role_objects[$role];
  45          else
  46              return null;
  47      }
  48  
  49  	function get_names() {
  50          return $this->role_names;
  51      }
  52  
  53  	function is_role($role) {
  54          return isset($this->role_names[$role]);
  55      }
  56  
  57  	function map_meta_cap( $cap, $user_id ) {
  58          $args = array_slice(func_get_args(), 2);
  59          return apply_filters( 'map_meta_cap', array( $cap ), $cap, $user_id, $args );
  60      }
  61  }
  62  
  63  class BP_Role {
  64      var $name;
  65      var $capabilities;
  66  
  67  	function __construct($role, $capabilities) {
  68          $this->name = $role;
  69          $this->capabilities = $capabilities;
  70      }
  71  
  72  	function BP_Role($role, $capabilities) {
  73          self::__construct($role, $capabilities);
  74      }
  75  
  76  	function add_cap($cap, $grant = true) {
  77          $this->capabilities[$cap] = $grant;
  78      }
  79  
  80  	function remove_cap($cap) {
  81          unset($this->capabilities[$cap]);
  82      }
  83  
  84  	function has_cap($cap) {
  85          $capabilities = apply_filters('role_has_cap', $this->capabilities, $cap, $this->name);
  86          $grant = !empty( $capabilities[$cap] );
  87          return apply_filters("{$this->name}_has_cap", $grant);
  88      }
  89  
  90  }


Generated: Wed Dec 19 01:01:51 2018 Cross-referenced by PHPXref 0.7.1