user-view.php
7.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/**
* User capabilities View class to output HTML with capabilities assigne to the user
*
* @package User-Role-Editor
* @subpackage Admin
* @author Vladimir Garagulya <support@role-editor.com>
* @copyright Copyright (c) 2010 - 2016, Vladimir Garagulya
**/
class URE_User_View extends URE_View {
private $user_to_edit = null;
public function __construct() {
parent::__construct();
$this->user_to_edit = $this->editor->get('user_to_edit');
}
// end of __construct()
public function display_edit_dialogs() {
}
// end of display_edit_dialogs()
/**
* output HTML code to create URE toolbar
*
* @param boolean $role_delete
* @param boolean $capability_remove
*/
public function toolbar() {
?>
<div id="ure_toolbar" >
<div id="ure_update">
<button id="ure_update_role" class="ure_toolbar_button button-primary">Update</button>
<?php
do_action('ure_user_edit_toolbar_update');
?>
</div>
</div>
<?php
}
// end of toolbar()
private function get_user_info() {
$switch_to_user = '';
if (!is_multisite() || current_user_can('manage_network_users')) {
$anchor_start = '<a href="' . wp_nonce_url("user-edit.php?user_id={$this->user_to_edit->ID}", "ure_user_{$this->user_to_edit->ID}") . '" >';
$anchor_end = '</a>';
if (class_exists('user_switching') && current_user_can('switch_to_user', $this->user_to_edit->ID)) {
$switch_to_user_link = user_switching::switch_to_url($this->user_to_edit);
$switch_to_user = '<a href="' . esc_url($switch_to_user_link) . '">' . esc_html__('Switch To', 'user-switching') . '</a>';
}
} else {
$anchor_start = '';
$anchor_end = '';
}
$user_info = ' <span style="font-weight: bold;">' . $anchor_start . $this->user_to_edit->user_login;
if ($this->user_to_edit->display_name !== $this->user_to_edit->user_login) {
$user_info .= ' (' . $this->user_to_edit->display_name . ')';
}
$user_info .= $anchor_end . '</span>';
if (is_multisite() && $this->lib->is_super_admin($this->user_to_edit->ID)) {
$user_info .= ' <span style="font-weight: bold; color:red;">' . esc_html__('Network Super Admin', 'user-role-editor') . '</span>';
}
if (!empty($switch_to_user)) {
$user_info .= ' ' . $switch_to_user;
}
return $user_info;
}
// end of get_user_info()
public function show_primary_role_dropdown_list($user_roles) {
?>
<select name="primary_role" id="primary_role">
<?php
// Compare user role against currently editable roles
$user_roles = array_intersect( array_values( $user_roles ), array_keys( get_editable_roles() ) );
$user_primary_role = array_shift( $user_roles );
// print the full list of roles with the primary one selected.
wp_dropdown_roles($user_primary_role);
// print the 'no role' option. Make it selected if the user has no role yet.
$selected = ( empty($user_primary_role) ) ? 'selected="selected"' : '';
echo '<option value="" '. $selected.'>' . esc_html__('— No role for this site —') . '</option>';
?>
</select>
<?php
}
// end of show_primary_role_dropdown_list()
protected function show_secondary_roles() {
$show_admin_role = $this->lib->show_admin_role_allowed();
$values = array_values($this->user_to_edit->roles);
$primary_role = array_shift($values); // get 1st element from roles array
$roles = $this->editor->get('roles');
foreach ($roles as $role_id => $role) {
if (($show_admin_role || $role_id != 'administrator') && ($role_id !== $primary_role)) {
if ($this->editor->user_can($role_id)) {
$checked = 'checked="checked"';
} else {
$checked = '';
}
echo '<label for="wp_role_' . $role_id . '"><input type="checkbox" id="wp_role_' . $role_id .
'" name="wp_role_' . $role_id . '" value="' . $role_id . '"' . $checked . ' /> ' .
esc_html__($role['name'], 'user-role-editor') . '</label><br />';
}
}
}
// end of show_secondary_roles()
public function display() {
$caps_readable = $this->editor->get('caps_readable');
$show_deprecated_caps = $this->editor->get('show_deprecated_caps');
$edit_user_caps_mode = $this->editor->get_edit_user_caps_mode();
$caps_access_restrict_for_simple_admin = $this->lib->get_option('caps_access_restrict_for_simple_admin', 0);
$user_info = $this->get_user_info();
$select_primary_role = apply_filters('ure_users_select_primary_role', true);
?>
<div class="postbox" style="float:left;min-width:1000px;width: 100%;">
<div id="ure_user_caps_header">
<span id="ure_user_caps_title"><?php esc_html_e('Change capabilities for user', 'user-role-editor')?></span> <?php echo $user_info;?>
</div>
<div class="inside">
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<tr>
<td> </td>
<td style="padding-left: 10px; padding-bottom: 5px;">
<?php
if ($this->lib->is_super_admin() || !is_multisite() || !class_exists('User_Role_Editor_Pro') || !$caps_access_restrict_for_simple_admin) {
if ($caps_readable) {
$checked = 'checked="checked"';
} else {
$checked = '';
}
?>
<input type="checkbox" name="ure_caps_readable" id="ure_caps_readable" value="1"
<?php echo $checked; ?> onclick="ure_turn_caps_readable(<?php echo $this->user_to_edit->ID; ?>);" />
<label for="ure_caps_readable"><?php esc_html_e('Show capabilities in human readable form', 'user-role-editor'); ?></label>
<?php
if ($show_deprecated_caps) {
$checked = 'checked="checked"';
} else {
$checked = '';
}
?>
<input type="checkbox" name="ure_show_deprecated_caps" id="ure_show_deprecated_caps" value="1"
<?php echo $checked; ?> onclick="ure_turn_deprecated_caps(<?php echo $this->user_to_edit->ID; ?>);"/>
<label for="ure_show_deprecated_caps"><?php esc_html_e('Show deprecated capabilities', 'user-role-editor'); ?></label>
<?php
}
?>
</td>
</tr>
<tr>
<td id="ure_user_roles">
<?php
if ($select_primary_role || $this->lib->is_super_admin()) {
?>
<div class="ure-user-role-section-title"><?php esc_html_e('Primary Role:', 'user-role-editor'); ?></div>
<?php
$this->show_primary_role_dropdown_list($this->user_to_edit->roles);
}
if (function_exists('bbp_filter_blog_editable_roles') ) { // bbPress plugin is active
?>
<div class="ure-user-role-section-title" style="margin-top: 5px;"><?php esc_html_e('bbPress Role:', 'user-role-editor'); ?></div>
<?php
$dynamic_roles = bbp_get_dynamic_roles();
$bbp_user_role = bbp_get_user_role($this->user_to_edit->ID);
if (!empty($bbp_user_role)) {
echo $dynamic_roles[$bbp_user_role]['name'];
}
}
?>
<div style="margin-top: 5px;margin-bottom: 5px; font-weight: bold;"><?php esc_html_e('Other Roles:', 'user-role-editor'); ?></div>
<?php
$this->show_secondary_roles();
?>
</td>
<td style="padding-left: 5px; padding-top: 5px; border-top: 1px solid #ccc; vertical-align: top;">
<?php $this->display_caps(false, $edit_user_caps_mode ); ?>
</td>
</tr>
</table>
<input type="hidden" name="object" value="user" />
<input type="hidden" name="user_id" value="<?php echo $this->user_to_edit->ID; ?>" />
</div>
</div>
<?php
}
// end of display()
}
// end of class URE_User_View