* @copyright Copyright (c) 2010 - 2016, Vladimir Garagulya **/ class URE_Role_View extends URE_View { public $role_default_html = ''; private $role_to_copy_html = ''; private $role_select_html = ''; private $role_delete_html = ''; public function __construct() { parent::__construct(); $capabilities = URE_Capabilities::get_instance(); $this->caps_to_remove = $capabilities->get_caps_to_remove(); } // end of __construct() public function role_default_prepare_html($select_width=200) { $roles = $this->editor->get('roles'); if (!isset($roles) || !$roles) { // get roles data from database $roles = $this->lib->get_user_roles(); } ksort( $roles ); $caps_access_restrict_for_simple_admin = $this->lib->get_option('caps_access_restrict_for_simple_admin', 0); $show_admin_role = $this->lib->show_admin_role_allowed(); if ($select_width>0) { $select_style = 'style="width: '. $select_width .'px"'; } else { $select_style = ''; } $wp_default_role = get_option( 'default_role' ); $this->role_default_html = ''; } // end of role_default_prepare_html() private function role_select_copy_prepare_html( $select_width=200 ) { $current_user = wp_get_current_user(); $key_capability = URE_Own_Capabilities::get_key_capability(); $user_is_ure_admin = current_user_can( $key_capability ); $role_to_skip = ( $user_is_ure_admin ) ? '' : $current_user->roles[0]; $caps_access_restrict_for_simple_admin = $this->lib->get_option( 'caps_access_restrict_for_simple_admin', 0 ); $show_admin_role = $this->lib->show_admin_role_allowed(); $this->role_to_copy_html = ''; $current_role = $this->editor->get( 'current_role' ); $all_roles = $this->editor->get( 'roles' ); $roles = $this->lib->get_editable_user_roles( $all_roles ); ksort( $roles ); foreach ($roles as $key => $value) { if ( $key===$role_to_skip ) { // skip role of current user if he does not have full access to URE continue; } $selected1 = selected( $key, $current_role, false ); $disabled = ( $key==='administrator' && $caps_access_restrict_for_simple_admin && !$this->lib->is_super_admin()) ? 'disabled' : ''; if ( $show_admin_role || $key != 'administrator' ) { $translated_name = esc_html__( $value['name'], 'user-role-editor' ); // get translation from URE language file, if exists if ( $translated_name === $value['name'] ) { // get WordPress internal translation $translated_name = translate_user_role( $translated_name ); } $translated_name .= ' (' . $key . ')'; $this->role_select_html .= ''; $this->role_to_copy_html .= ''; } } $this->role_select_html .= ''; $this->role_to_copy_html .= ''; } // end of role_select_copy_prepare_html() private function role_delete_prepare_html() { $roles_can_delete = $this->editor->get_roles_can_delete(); if ( is_array( $roles_can_delete ) && count( $roles_can_delete ) > 0) { ksort( $roles_can_delete ); $this->role_delete_html = ''; } else { $this->role_delete_html = ''; } } // end of role_delete_prepare_html() /** * Build HTML for select drop-down list from capabilities we can remove * * @return string **/ public static function caps_to_remove_html() { global $wp_roles; $capabilities = URE_Capabilities::get_instance(); $caps_to_remove = $capabilities->get_caps_to_remove(); if ( empty( $caps_to_remove ) || !is_array( $caps_to_remove ) && count( $caps_to_remove )===0 ) { return ''; } $caps = array_keys($caps_to_remove); asort($caps); $network_admin = filter_input(INPUT_POST, 'network_admin', FILTER_SANITIZE_NUMBER_INT); $current_role = filter_input(INPUT_POST, 'current_role', FILTER_SANITIZE_STRING); if (!isset($wp_roles->roles[$current_role])) { $current_role = ''; } ob_start(); ?>
role_select_copy_prepare_html( $select_width ); $multisite = $this->lib->get( 'multisite' ); if ( $multisite && !is_network_admin() ) { $this->role_default_prepare_html( $select_width ); } $this->role_delete_prepare_html(); } // end of role_edit_prepare_html() public function display_edit_dialogs() { $multisite = $this->lib->get('multisite'); $current_role = $this->editor->get('current_role'); $current_role_name = $this->editor->get('current_role_name'); ?>
role_to_copy_html; ?>
role_delete_html; ?>
role_default_html; ?>
current_role * @param boolean $role_delete * @param boolean $capability_remove */ public function toolbar() { $caps_access_restrict_for_simple_admin = $this->lib->get_option('caps_access_restrict_for_simple_admin', 0); if ($caps_access_restrict_for_simple_admin) { $add_del_role_for_simple_admin = $this->lib->get_option('add_del_role_for_simple_admin', 1); } else { $add_del_role_for_simple_admin = 1; } $super_admin = $this->lib->is_super_admin(); $multisite = $this->lib->get('multisite'); ?>

role_delete_html) && current_user_can('ure_delete_roles')) { ?> caps_to_remove) && is_array($this->caps_to_remove) && count($this->caps_to_remove)>0 && current_user_can('ure_delete_capabilities')) { ?>

lib->get('multisite'); $active_for_network = $this->lib->get('active_for_network'); ?>
editor->get('caps_readable'); if ($caps_readable) { $checked = 'checked="checked"'; } else { $checked = ''; } $caps_access_restrict_for_simple_admin = $this->lib->get_option('caps_access_restrict_for_simple_admin', 0); if ($this->lib->is_super_admin() || !$multisite || !$this->lib->is_pro() || !$caps_access_restrict_for_simple_admin) { ?> onclick="ure_turn_caps_readable(0);"/>    editor->get('show_deprecated_caps'); if ($show_deprecated_caps) { $checked = 'checked="checked"'; } else { $checked = ''; } ?> onclick="ure_turn_deprecated_caps(0);"/> lib->is_super_admin()) { $hint = esc_html__('If checked, then apply action to ALL sites of this Network'); $apply_to_all = $this->editor->get('apply_to_all'); if ($apply_to_all) { $checked = 'checked="checked"'; $fontColor = 'color:#FF0000;'; } else { $checked = ''; $fontColor = ''; } ?>
title="" onclick="ure_main.apply_to_all_on_click(this)"/>

role_select_html; ?>
display_options(); $this->display_caps(); $ao = $this->editor->get('role_additional_options'); $current_role = $this->editor->get('current_role'); $ao->show($current_role); ?>