public static function get_instance()
 {
     if (self::$instance === null) {
         // new static() will work too
         self::$instance = new URE_Capabilities_Groups_Manager();
     }
     return self::$instance;
 }
Esempio n. 2
0
 /**
  * return array of built-in WP capabilities (WP 3.1 wp-admin/includes/schema.php) 
  * 
  * @return array 
  */
 public function get_built_in_wp_caps()
 {
     $caps_groups = URE_Capabilities_Groups_Manager::get_instance();
     $caps = $caps_groups->get_built_in_wp_caps();
     return $caps;
 }
    /**
     * output HTML-code for capabilities list
     * @param boolean $for_role - if true, it is role capabilities list, else - user specific capabilities list
     * @param boolean $edit_mode - if false, capabilities checkboxes are shown as disable - readonly mode
     */
    public function show_capabilities($for_role = true, $edit_mode=true) {
        
        $onclick_for_admin = '';
        $multisite = $this->lib->get('multisite');
        $current_role = $this->lib->get('current_role');
        if (!($multisite && is_super_admin())) {  // do not limit SuperAdmin for multi-site
            if ('administrator'==$current_role) {
                $onclick_for_admin = 'onclick="ure_turn_it_back(this)"';
            }
        }
        $user_to_edit = $this->lib->get('user_to_edit');
        $roles = $this->lib->get('roles');
        $full_capabilities = $this->lib->get('full_capabilities');
        $built_in_wp_caps = $this->lib->get_built_in_wp_caps();        
        $caps_readable = $this->lib->get('caps_readable');
        $caps_groups_manager = URE_Capabilities_Groups_Manager::get_instance();
        
        $key_capability = $this->lib->get_key_capability();
        $user_is_ure_admin = current_user_can($key_capability);
        $ure_caps = $this->lib->get_ure_caps();
        
        $output = '';
        foreach ($full_capabilities as $capability) {    
            $cap_id = $capability['inner'];
            if (!$user_is_ure_admin) { 
                if (isset($ure_caps[$cap_id]) || 
                    ($this->multisite && $cap_id=='manage_network_plugins')) { 
                    // exclude URE caps if user does not have full access to URE
                    continue;
                }
            }
            $label_style = ''; 
            $hidden_class = '';
            
            $this->deprecated_show_and_color($cap_id, $built_in_wp_caps, $label_style, $hidden_class);            
            $blocked = $this->blocked_for_single_admin_style($cap_id, $label_style);
            $classes = array('ure-cap-div');
            if ($blocked) {
                $classes[] = 'blocked';
                $hidden_class = 'hidden';
            }                                                              
            if ($hidden_class) {
                $classes[] = $hidden_class;
            }
            
            $cap_groups = $caps_groups_manager->get_cap_groups($cap_id, $built_in_wp_caps);
            $classes = array_merge($classes, $cap_groups);
            
            $checked = '';
            $disabled = '';
            if ($for_role) {
                if (isset($roles[$current_role]['capabilities'][$cap_id]) &&
                    !empty($roles[$current_role]['capabilities'][$cap_id])) {
                    $checked = 'checked="checked"';
                }
            } else {
                if (empty($edit_mode)) {
                    $disabled = 'disabled="disabled"';
                } else {
                    $disabled = '';
                }
                if ($this->lib->user_can($cap_id)) {
                    $checked = 'checked="checked"';
                    if (!isset($user_to_edit->caps[$cap_id])) {
                        $disabled = 'disabled="disabled"';
                    }
                }
            }                        
            $class = 'class="' . implode(' ', $classes) .'"';
            $cap_id_esc = str_replace(' ', URE_SPACE_REPLACER, $cap_id);
            $cap_html = '<div id="ure_cap_div_'. $cap_id_esc .'" '. $class .'><input type="checkbox" name="' . $cap_id_esc . '" id="' . 
                    $cap_id_esc . '" value="' . $cap_id .'" '. $checked . ' ' . $disabled . ' ' . $onclick_for_admin . 
                    'class="ure-cap-cb">';
            

            if ($caps_readable) {
                $cap_ind = 'human';
                $cap_ind_alt = 'inner';
            } else {
                $cap_ind = 'inner';
                $cap_ind_alt = 'human';
            }
            $cap_html .= '<label for="' . $cap_id_esc . '" title="' . $capability[$cap_ind_alt] . '" ' . $label_style . ' > ' . 
                 $capability[$cap_ind] . '</label> </div>';
            
            $output .= $cap_html;
        }

        echo $output;
    }