[ 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 BP_Roles() {
   8          $this->__construct();
   9      }
  10  
  11  	function __construct() {
  12          do_action_ref_array('init_roles', array(&$this) );
  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 BP_Role($role, $capabilities) {
  68          $this->name = $role;
  69          $this->capabilities = $capabilities;
  70      }
  71  
  72  	function add_cap($cap, $grant = true) {
  73          $this->capabilities[$cap] = $grant;
  74      }
  75  
  76  	function remove_cap($cap) {
  77          unset($this->capabilities[$cap]);
  78      }
  79  
  80  	function has_cap($cap) {
  81          $capabilities = apply_filters('role_has_cap', $this->capabilities, $cap, $this->name);
  82          $grant = !empty( $capabilities[$cap] );
  83          return apply_filters("{$this->name}_has_cap", $grant);
  84      }
  85  
  86  }


Generated: Wed Feb 8 03:57:40 2012 Hosted by follow the white rabbit.