WPFront User Role Editor - Version 1.0

Version Description

  • Set new user default role
  • Stability improvements
Download this release

Release Info

Developer syammohanm
Plugin Icon 128x128 WPFront User Role Editor
Version 1.0
Comparing to
See all releases

Code changes from version 0.3.1 to 1.0

classes/class-wpfront-user-role-editor-add-edit.php ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+
26
+ if (!class_exists('WPFront_User_Role_Editor_Add_Edit')) {
27
+
28
+ /**
29
+ * Add or Edit Role
30
+ *
31
+ * @author Syam Mohan <syam@wpfront.com>
32
+ * @copyright 2014 WPFront.com
33
+ */
34
+ class WPFront_User_Role_Editor_Add_Edit {
35
+
36
+ const MENU_SLUG = 'wpfront-user-role-editor-add-new';
37
+
38
+ private $main;
39
+ private $role = null;
40
+ private $is_editable = FALSE;
41
+ private $role_exists = FALSE;
42
+ private $error = FALSE;
43
+
44
+ function __construct($main) {
45
+ $this->main = $main;
46
+ }
47
+
48
+ public function ajax_register() {
49
+ add_action('wp_ajax_wpfront_user_role_editor_copy_capabilities', array($this, 'copy_capabilities_callback'));
50
+ }
51
+
52
+ public function add_edit_role($role_name) {
53
+ global $wp_roles;
54
+ $roles = $wp_roles->role_names;
55
+
56
+ if (array_key_exists($role_name, $roles)) {
57
+ $this->role = get_role($role_name);
58
+ }
59
+
60
+ if ($this->role === NULL) {
61
+ if (!$this->can_create()) {
62
+ $this->main->permission_denied();
63
+ return;
64
+ }
65
+ } else {
66
+ if (!$this->can_edit()) {
67
+ $this->main->permission_denied();
68
+ return;
69
+ }
70
+ }
71
+
72
+ if ($this->role == NULL) {
73
+ $this->is_editable = TRUE;
74
+ } else if ($role_name != 'administrator') {
75
+ $this->is_editable = array_key_exists($role_name, get_editable_roles());
76
+ }
77
+
78
+ $success = FALSE;
79
+ if (!empty($_POST['createrole'])) {
80
+ while (TRUE) {
81
+ if (!$this->is_display_name_valid())
82
+ break;
83
+ if ($this->role == NULL && !$this->is_role_name_valid())
84
+ break;
85
+
86
+ $capabilities = array();
87
+ if (!empty($_POST['capabilities'])) {
88
+ foreach ($_POST['capabilities'] as $key => $value) {
89
+ $capabilities[$key] = TRUE;
90
+ }
91
+ }
92
+
93
+ if ($this->role == NULL) {
94
+ $role_name = $this->get_role_name();
95
+ if (array_key_exists($role_name, $roles)) {
96
+ $this->role_exists = TRUE;
97
+ break;
98
+ }
99
+ $error = add_role($role_name, $this->get_display_name(), $capabilities);
100
+ if ($error == NULL) {
101
+ $this->error = TRUE;
102
+ break;
103
+ }
104
+ } else {
105
+ global $wp_roles;
106
+ $wp_roles->roles[$this->role->name] = array(
107
+ 'name' => $this->get_display_name(),
108
+ 'capabilities' => $capabilities
109
+ );
110
+ update_option($wp_roles->role_key, $wp_roles->roles);
111
+ $wp_roles->role_objects[$this->role->name] = new WP_Role($this->role->name, $capabilities);
112
+ $wp_roles->role_names[$this->role->name] = $this->get_display_name();
113
+ }
114
+
115
+ $success = TRUE;
116
+ break;
117
+ }
118
+ }
119
+
120
+ if ($success) {
121
+ printf('<script type="text/javascript">document.location="%s";</script>', $this->list_roles_url());
122
+ } else {
123
+ include($this->main->pluginDIR() . 'templates/add-edit-role.php');
124
+ }
125
+ }
126
+
127
+ private function can_create() {
128
+ return $this->main->current_user_can('create_roles');
129
+ }
130
+
131
+ private function can_edit() {
132
+ return $this->main->current_user_can('edit_roles');
133
+ }
134
+
135
+ private function __($s) {
136
+ return $this->main->__($s);
137
+ }
138
+
139
+ private function add_new_url() {
140
+ return admin_url('admin.php') . '?page=' . self::MENU_SLUG;
141
+ }
142
+
143
+ private function list_roles_url() {
144
+ return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_List::MENU_SLUG;
145
+ }
146
+
147
+ private function is_display_name_valid() {
148
+ if (empty($_POST['createrole']))
149
+ return TRUE;
150
+
151
+ if ($this->get_display_name() == '')
152
+ return FALSE;
153
+
154
+ return TRUE;
155
+ }
156
+
157
+ private function is_display_name_disabled() {
158
+ return !$this->is_editable;
159
+ }
160
+
161
+ private function get_display_name() {
162
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
163
+ if (empty($_POST['display_name']))
164
+ return '';
165
+
166
+ return trim($_POST['display_name']);
167
+ }
168
+
169
+ if ($this->role == NULL)
170
+ return '';
171
+ global $wp_roles;
172
+ return $wp_roles->role_names[$this->role->name];
173
+ }
174
+
175
+ private function is_role_name_valid() {
176
+ if (empty($_POST['createrole']))
177
+ return TRUE;
178
+
179
+ if ($this->get_role_name() == '')
180
+ return FALSE;
181
+
182
+ return TRUE;
183
+ }
184
+
185
+ private function is_role_name_disabled() {
186
+ if ($this->role != NULL)
187
+ return TRUE;
188
+ if (!$this->is_editable)
189
+ return TRUE;
190
+ return FALSE;
191
+ }
192
+
193
+ private function get_role_name() {
194
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
195
+ if (empty($_POST['role_name']))
196
+ return '';
197
+
198
+ return preg_replace('/\W/', '', preg_replace('/ /', '_', trim($_POST['role_name'])));
199
+ }
200
+
201
+ if ($this->role == NULL)
202
+ return '';
203
+ return $this->role->name;
204
+ }
205
+
206
+ private function is_submit_disabled() {
207
+ if (!$this->is_editable)
208
+ return TRUE;
209
+ return FALSE;
210
+ }
211
+
212
+ private function get_capability_groups() {
213
+ $caps_group = array();
214
+
215
+ foreach ($this->main->get_capabilities() as $key => $value) {
216
+ $deprecated = array_key_exists($key, WPFront_User_Role_Editor::$DEPRECATED_CAPABILITIES);
217
+ $other = array_key_exists($key, WPFront_User_Role_Editor::$OTHER_CAPABILITIES);
218
+
219
+ $caps_group[$key] = (OBJECT) array(
220
+ 'caps' => $value,
221
+ 'display_name' => $this->__($key),
222
+ 'deprecated' => $deprecated,
223
+ 'disabled' => !$this->is_editable || $deprecated,
224
+ 'hidden' => $deprecated && !$this->main->display_deprecated(),
225
+ 'key' => str_replace(' ', '-', $key),
226
+ 'has_help' => !$other
227
+ );
228
+ }
229
+
230
+ return $caps_group;
231
+ }
232
+
233
+ private function get_copy_from() {
234
+ if (!$this->is_editable)
235
+ return array();
236
+
237
+ global $wp_roles;
238
+ $roles = $wp_roles->role_names;
239
+ asort($roles);
240
+ return $roles;
241
+ }
242
+
243
+ private function is_role_exists() {
244
+ return $this->role_exists;
245
+ }
246
+
247
+ private function is_error() {
248
+ return $this->error;
249
+ }
250
+
251
+ public function copy_capabilities_callback() {
252
+ if (empty($_POST['role'])) {
253
+ echo '{}';
254
+ die();
255
+ return;
256
+ }
257
+
258
+ $role = get_role($_POST['role']);
259
+ if ($role == NULL) {
260
+ echo '{}';
261
+ die();
262
+ return;
263
+ }
264
+
265
+ echo json_encode($role->capabilities);
266
+ die();
267
+ }
268
+
269
+ private function capability_checked($cap) {
270
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
271
+ if (empty($_POST['capabilities']))
272
+ return FALSE;
273
+
274
+ return array_key_exists($cap, $_POST['capabilities']);
275
+ }
276
+
277
+ if ($this->role != NULL) {
278
+ if (array_key_exists($cap, $this->role->capabilities))
279
+ return $this->role->capabilities[$cap];
280
+ }
281
+
282
+ return FALSE;
283
+ }
284
+
285
+ private function footer() {
286
+ $this->main->footer();
287
+ }
288
+
289
+ private function image_url() {
290
+ return $this->main->pluginURL() . 'images/';
291
+ }
292
+
293
+ private function get_help_url($cap) {
294
+ return 'http://wpfront.com/wordpress-capabilities/#' . $cap;
295
+ }
296
+
297
+ }
298
+
299
+ }
classes/class-wpfront-user-role-editor-delete.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+
26
+ if (!class_exists('WPFront_User_Role_Editor_Delete')) {
27
+
28
+ /**
29
+ * WPFront User Role Editor Plugin Delete Role
30
+ *
31
+ * @author Syam Mohan <syam@wpfront.com>
32
+ * @copyright 2014 WPFront.com
33
+ */
34
+ class WPFront_User_Role_Editor_Delete {
35
+
36
+ private $main;
37
+ private $roles;
38
+
39
+ function __construct($main) {
40
+ $this->main = $main;
41
+ }
42
+
43
+ public function delete_role($delete_roles) {
44
+ $this->roles = array();
45
+ $editable_roles = get_editable_roles();
46
+ global $wp_roles;
47
+
48
+ foreach ($delete_roles as $value) {
49
+ if (array_key_exists($value, $wp_roles->role_names)) {
50
+ $status_message = '';
51
+ $is_deletable = TRUE;
52
+ if (!array_key_exists($value, $editable_roles)) {
53
+ $status_message = 'This role cannot be deleted: Permission denied.';
54
+ $is_deletable = FALSE;
55
+ } else if ($value == 'administrator') {
56
+ $status_message = '\'administrator\' role cannot be deleted.';
57
+ $is_deletable = FALSE;
58
+ } else {
59
+ global $user_ID;
60
+ $user = new WP_User($user_ID);
61
+ if (in_array($value, $user->roles)) {
62
+ $status_message = 'Current user\'s role cannot be deleted.';
63
+ $is_deletable = FALSE;
64
+ }
65
+ }
66
+ $this->roles[$value] = (OBJECT) array(
67
+ 'name' => $value,
68
+ 'display_name' => $wp_roles->role_names[$value],
69
+ 'is_deletable' => $is_deletable,
70
+ 'status_message' => $status_message
71
+ );
72
+ }
73
+ }
74
+
75
+ if(!empty($_POST['confirm-delete'])) {
76
+ $this->main->verify_nonce();
77
+ foreach ($this->roles as $key => $value) {
78
+ if($value->is_deletable) {
79
+ remove_role($key);
80
+ }
81
+ }
82
+ printf('<script type="text/javascript">document.location="%s";</script>', $this->list_roles_url());
83
+ return;
84
+ }
85
+
86
+ include($this->main->pluginDIR() . 'templates/delete-role.php');
87
+ }
88
+
89
+ public function is_pending_action() {
90
+ if(!empty($_POST['confirm-delete']) && !empty($_POST['delete-roles'])) {
91
+ $this->delete_role(array_keys($_POST['delete-roles']));
92
+ return TRUE;
93
+ }
94
+ return FALSE;
95
+ }
96
+
97
+ private function get_deleting_roles() {
98
+ return $this->roles;
99
+ }
100
+
101
+ private function is_submit_allowed() {
102
+ foreach ($this->roles as $key => $value) {
103
+ if($value->is_deletable)
104
+ return TRUE;
105
+ }
106
+
107
+ return FALSE;
108
+ }
109
+
110
+ private function list_roles_url() {
111
+ return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_List::MENU_SLUG;
112
+ }
113
+
114
+ private function __($s) {
115
+ return $this->main->__($s);
116
+ }
117
+
118
+ }
119
+
120
+ }
classes/class-wpfront-user-role-editor-list.php ADDED
@@ -0,0 +1,371 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ require_once("class-wpfront-user-role-editor-add-edit.php");
25
+
26
+ if (!class_exists('WPFront_User_Role_Editor_List')) {
27
+
28
+ /**
29
+ * Lists Roles
30
+ *
31
+ * @author Syam Mohan <syam@wpfront.com>
32
+ * @copyright 2014 WPFront.com
33
+ */
34
+ class WPFront_User_Role_Editor_List {
35
+
36
+ const MENU_SLUG = 'wpfront-user-role-editor-all-roles';
37
+
38
+ private $main;
39
+ private $role_data = NULL;
40
+
41
+ function __construct($main) {
42
+ $this->main = $main;
43
+ }
44
+
45
+ public function list_roles() {
46
+ if (!$this->can_list())
47
+ $this->main->permission_denied();
48
+
49
+ if (!empty($_GET['edit_role'])) {
50
+ $obj = new WPFront_User_Role_Editor_Add_Edit($this->main);
51
+ $obj->add_edit_role(trim($_GET['edit_role']));
52
+ return;
53
+ }
54
+
55
+ if (!empty($_GET['delete_role'])) {
56
+ $obj = new WPFront_User_Role_Editor_Delete($this->main);
57
+ $obj->delete_role(array(trim($_GET['delete_role'])));
58
+ return;
59
+ }
60
+
61
+ if (!empty($_GET['set_default_role'])) {
62
+ $this->set_default_role($_GET['set_default_role']);
63
+ printf('<script type="text/javascript">document.location="%s";</script>', $this->list_url());
64
+ return;
65
+ }
66
+
67
+ $obj = new WPFront_User_Role_Editor_Delete($this->main);
68
+ if ($obj->is_pending_action()) {
69
+ return;
70
+ }
71
+
72
+ $action = '';
73
+ if (!empty($_POST['doaction_top']) && !empty($_POST['action_top'])) {
74
+ $action = $_POST['action_top'];
75
+ } else if (!empty($_POST['doaction_bottom']) && !empty($_POST['action_bottom'])) {
76
+ $action = $_POST['action_bottom'];
77
+ }
78
+
79
+ if ($action == 'delete') {
80
+ if (!empty($_POST['selected-roles'])) {
81
+ $obj = new WPFront_User_Role_Editor_Delete($this->main);
82
+ $obj->delete_role(array_keys($_POST['selected-roles']));
83
+ return;
84
+ }
85
+ }
86
+
87
+ include($this->main->pluginDIR() . 'templates/list-roles.php');
88
+ }
89
+
90
+ private function __($s) {
91
+ return $this->main->__($s);
92
+ }
93
+
94
+ private function can_list() {
95
+ return $this->main->current_user_can('list_roles');
96
+ }
97
+
98
+ private function can_create() {
99
+ return $this->main->current_user_can('create_roles');
100
+ }
101
+
102
+ private function can_edit() {
103
+ return $this->main->current_user_can('edit_roles');
104
+ }
105
+
106
+ private function can_delete() {
107
+ return $this->main->current_user_can('delete_roles');
108
+ }
109
+
110
+ private function list_url() {
111
+ return admin_url('admin.php') . '?page=' . self::MENU_SLUG;
112
+ }
113
+
114
+ private function add_new_url() {
115
+ return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_Add_Edit::MENU_SLUG;
116
+ }
117
+
118
+ private function edit_url() {
119
+ return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_List::MENU_SLUG . '&edit_role=';
120
+ }
121
+
122
+ private function delete_url() {
123
+ return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_List::MENU_SLUG . '&delete_role=';
124
+ }
125
+
126
+ private function set_default_url() {
127
+ return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_List::MENU_SLUG . '&nonce=' . wp_create_nonce($this->list_url()) . '&set_default_role=';
128
+ }
129
+
130
+ private function set_default_role($default_role) {
131
+ if (empty($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], $this->list_url())) {
132
+ $this->main->permission_denied();
133
+ return;
134
+ }
135
+
136
+ if (!current_user_can('manage_options')) {
137
+ $this->main->permission_denied();
138
+ return;
139
+ }
140
+
141
+ update_option('default_role', $default_role);
142
+ }
143
+
144
+ private function get_roles() {
145
+ if ($this->role_data != NULL)
146
+ return $this->role_data;
147
+
148
+ $this->role_data = array();
149
+
150
+ global $wp_roles;
151
+ $roles = $wp_roles->role_names;
152
+ asort($roles, SORT_STRING | SORT_FLAG_CASE);
153
+
154
+ $editable_roles = get_editable_roles();
155
+
156
+ $user_default = get_option('default_role');
157
+
158
+ foreach ($roles as $key => $value) {
159
+ $this->role_data[$key] = array(
160
+ 'role_name' => $key,
161
+ 'display_name' => $value,
162
+ 'is_default' => in_array($key, WPFront_User_Role_Editor::$DEFAULT_ROLES),
163
+ 'user_count' => count(get_users(array('role' => $key))),
164
+ 'caps_count' => count($wp_roles->roles[$key]['capabilities']),
165
+ 'user_default' => $key == $user_default
166
+ );
167
+
168
+ if ($this->can_edit()) {
169
+ $this->role_data[$key]['edit_url'] = $this->edit_url() . $key;
170
+
171
+ if ($key === 'administrator')
172
+ $this->role_data[$key]['is_editable'] = FALSE;
173
+ else {
174
+ $this->role_data[$key]['is_editable'] = array_key_exists($key, $editable_roles);
175
+ }
176
+ }
177
+
178
+ if ($this->can_delete()) {
179
+ $this->role_data[$key]['delete_url'] = $this->delete_url() . $key;
180
+
181
+ if ($key === 'administrator')
182
+ $this->role_data[$key]['is_deletable'] = FALSE;
183
+ else {
184
+ $this->role_data[$key]['is_deletable'] = array_key_exists($key, $editable_roles);
185
+ }
186
+ }
187
+
188
+ if ($key != $user_default && current_user_can('manage_options')) {
189
+ $this->role_data[$key]['set_default_url'] = $this->set_default_url() . $key;
190
+ }
191
+ }
192
+
193
+ switch ($this->get_current_list_filter()) {
194
+ case 'all':
195
+ break;
196
+ case 'haveusers':
197
+ foreach ($this->role_data as $key => $value) {
198
+ if ($this->role_data[$key]['user_count'] == 0)
199
+ unset($this->role_data[$key]);
200
+ }
201
+ break;
202
+ case 'nousers':
203
+ foreach ($this->role_data as $key => $value) {
204
+ if (!$this->role_data[$key]['user_count'] == 0)
205
+ unset($this->role_data[$key]);
206
+ }
207
+ break;
208
+ case 'builtin':
209
+ foreach ($this->role_data as $key => $value) {
210
+ if (!$this->role_data[$key]['is_default'])
211
+ unset($this->role_data[$key]);
212
+ }
213
+ break;
214
+ case 'custom':
215
+ foreach ($this->role_data as $key => $value) {
216
+ if ($this->role_data[$key]['is_default'])
217
+ unset($this->role_data[$key]);
218
+ }
219
+ break;
220
+ }
221
+
222
+ $search = $this->get_search_term();
223
+ $search = strtolower(trim($search));
224
+ if ($search !== '') {
225
+ foreach ($this->role_data as $key => $value) {
226
+ if (strpos(strtolower($value['display_name']), $search) === FALSE)
227
+ unset($this->role_data[$key]);
228
+ }
229
+ }
230
+
231
+ return $this->role_data;
232
+ }
233
+
234
+ private function table_header() {
235
+ ?>
236
+ <tr>
237
+ <th scope="col" id="cb" class="manage-column column-cb check-column">
238
+ <label class="screen-reader-text" for="cb-select-all-1"><?php echo $this->__('Select All'); ?></label>
239
+ <input id="cb-select-all-1" type="checkbox" />
240
+ </th>
241
+ <th scope="col" id="rolename" class="manage-column column-rolename">
242
+ <a><span><?php echo $this->__('Display Name'); ?></span></a>
243
+ </th>
244
+ <th scope="col" id="rolename" class="manage-column column-rolename">
245
+ <a><span><?php echo $this->__('Role Name'); ?></span></a>
246
+ </th>
247
+ <th scope="col" id="roletype" class="manage-column column-roletype">
248
+ <a><span><?php echo $this->__('Type'); ?></span></a>
249
+ </th>
250
+ <th scope="col" id="userdefault" class="manage-column column-userdefault num">
251
+ <a><span><?php echo $this->__('User Default'); ?></span></a>
252
+ </th>
253
+ <th scope="col" id="usercount" class="manage-column column-usercount num">
254
+ <a><span><?php echo $this->__('Users'); ?></span></a>
255
+ </th>
256
+ <th scope="col" id="capscount" class="manage-column column-capscount num">
257
+ <a><span><?php echo $this->__('Capabilities'); ?></span></a>
258
+ </th>
259
+ </tr>
260
+ <?php
261
+ }
262
+
263
+ private function bulk_actions($position) {
264
+ ?>
265
+ <div class="tablenav <?php echo $position; ?>">
266
+ <div class="alignleft actions bulkactions">
267
+ <select name="action_<?php echo $position; ?>">
268
+ <option value="" selected="selected"><?php echo $this->__('Bulk Actions'); ?></option>
269
+ <?php if ($this->can_delete()) { ?>
270
+ <option value="delete"><?php echo $this->__('Delete'); ?></option>
271
+ <?php } ?>
272
+ </select>
273
+ <input type="submit" name="doaction_<?php echo $position; ?>" class="button bulk action" value="<?php echo $this->__('Apply'); ?>">
274
+ </div>
275
+ <div class="tablenav-pages one-page"><span class="displaying-num"><?php echo sprintf($this->__('%s item(s)'), count($this->get_roles())); ?></span>
276
+ <br class="clear">
277
+ </div>
278
+ </div>
279
+ <?php
280
+ }
281
+
282
+ private function get_search_term() {
283
+ if (empty($_POST['search']))
284
+ return '';
285
+
286
+ return $_POST['search'];
287
+ }
288
+
289
+ private function get_list_filters() {
290
+ $filter_data = array();
291
+
292
+ global $wp_roles;
293
+ $role_data = $wp_roles->role_names;
294
+
295
+ $page = admin_url('admin.php') . '?page=' . self::MENU_SLUG;
296
+
297
+ $filter_data['all'] = array(
298
+ 'display' => $this->__('All'),
299
+ 'url' => $page,
300
+ 'count' => count($role_data)
301
+ );
302
+
303
+ $count = 0;
304
+ foreach ($role_data as $key => $value) {
305
+ if (count(get_users(array('role' => $key))) > 0)
306
+ $count++;
307
+ }
308
+ $filter_data['haveusers'] = array(
309
+ 'display' => $this->__('Having Users'),
310
+ 'url' => $page . '&list=haveusers',
311
+ 'count' => $count
312
+ );
313
+
314
+ $filter_data['nousers'] = array(
315
+ 'display' => $this->__('No Users'),
316
+ 'url' => $page . '&list=nousers',
317
+ 'count' => count($role_data) - $count
318
+ );
319
+
320
+ $count = 0;
321
+ foreach ($role_data as $key => $value) {
322
+ if (in_array($key, WPFront_User_Role_Editor::$DEFAULT_ROLES))
323
+ $count++;
324
+ }
325
+ $filter_data['builtin'] = array(
326
+ 'display' => $this->__('Built-In'),
327
+ 'url' => $page . '&list=builtin',
328
+ 'count' => $count
329
+ );
330
+
331
+ $filter_data['custom'] = array(
332
+ 'display' => $this->__('Custom'),
333
+ 'url' => $page . '&list=custom',
334
+ 'count' => count($role_data) - $count
335
+ );
336
+
337
+ return $filter_data;
338
+ }
339
+
340
+ private function get_current_list_filter() {
341
+ if (empty($_GET['list']))
342
+ return 'all';
343
+
344
+ $list = $_GET['list'];
345
+
346
+ switch ($list) {
347
+ case 'all':
348
+ case 'haveusers':
349
+ case 'nousers':
350
+ case 'builtin':
351
+ case 'custom':
352
+ break;
353
+ default:
354
+ $list = 'all';
355
+ break;
356
+ }
357
+
358
+ return $list;
359
+ }
360
+
361
+ private function footer() {
362
+ $this->main->footer();
363
+ }
364
+
365
+ private function image_url() {
366
+ return $this->main->pluginURL() . 'images/';
367
+ }
368
+
369
+ }
370
+
371
+ }
classes/class-wpfront-user-role-editor-options.php CHANGED
@@ -41,7 +41,7 @@ if (!class_exists('WPFront_User_Role_Editor_Options')) {
41
  $this->addOption('display_deprecated', 'bit', FALSE)->__('Display Deprecated Capabilities');
42
  $this->addOption('enable_role_capabilities', 'bit', FALSE)->__('Add Role Capabilities');
43
  }
44
-
45
  }
46
 
47
  }
41
  $this->addOption('display_deprecated', 'bit', FALSE)->__('Display Deprecated Capabilities');
42
  $this->addOption('enable_role_capabilities', 'bit', FALSE)->__('Add Role Capabilities');
43
  }
44
+
45
  }
46
 
47
  }
classes/class-wpfront-user-role-editor.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  /*
4
  WPFront User Role Editor Plugin
5
  Copyright (C) 2014, WPFront.com
@@ -24,6 +23,9 @@
24
 
25
  require_once("base/class-wpfront-base.php");
26
  require_once("class-wpfront-user-role-editor-options.php");
 
 
 
27
 
28
  if (!class_exists('WPFront_User_Role_Editor')) {
29
 
@@ -36,16 +38,111 @@ if (!class_exists('WPFront_User_Role_Editor')) {
36
  class WPFront_User_Role_Editor extends WPFront_Base {
37
 
38
  //Constants
39
- const VERSION = '0.3.1';
40
  const OPTIONS_GROUP_NAME = 'wpfront-user-role-editor-options-group';
41
  const OPTION_NAME = 'wpfront-user-role-editor-options';
42
  const PLUGIN_SLUG = 'wpfront-user-role-editor';
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  //Variables
45
  protected $options;
46
- protected $role_caps = array('wpfront_list_roles', 'wpfront_create_roles', 'wpfront_edit_roles', 'wpfront_delete_roles');
47
- protected $builtin_roles = array('administrator', 'editor', 'author', 'contributor', 'subscriber');
48
- protected $delete_roles;
49
 
50
  function __construct() {
51
  parent::__construct(__FILE__, self::PLUGIN_SLUG);
@@ -53,31 +150,35 @@ if (!class_exists('WPFront_User_Role_Editor')) {
53
  $this->add_menu($this->__('WPFront User Role Editor'), $this->__('User Role Editor'));
54
  }
55
 
56
- public function admin_init() {
57
- register_setting(self::OPTIONS_GROUP_NAME, self::OPTION_NAME);
 
 
58
 
59
- add_action('wp_ajax_wpfront_user_role_editor_update_options', array($this, 'update_options_callback'));
60
- add_action('wp_ajax_wpfront_user_role_editor_copy_capabilities', array($this, 'copy_capabilities_callback'));
61
  }
62
 
63
- public function get_capability_string($capability) {
64
- if ($this->options->enable_role_capabilities())
65
- return 'wpfront_' . $capability . '_roles';
66
 
67
- return $capability . '_users';
 
 
 
68
  }
69
 
70
  public function admin_menu() {
71
  parent::admin_menu();
72
 
73
- $menu_slug = self::PLUGIN_SLUG . '-all-roles';
74
  add_menu_page($this->__('Roles'), $this->__('Roles'), $this->get_capability_string('list'), $menu_slug, null, $this->pluginURL() . 'images/roles_menu.png', '69.9999');
75
 
76
- $page_hook_suffix = add_submenu_page($menu_slug, $this->__('Roles'), $this->__('All Roles'), $this->get_capability_string('list'), $menu_slug, array($this, 'list_roles'));
77
  add_action('admin_print_scripts-' . $page_hook_suffix, array($this, 'enqueue_scripts'));
78
  add_action('admin_print_styles-' . $page_hook_suffix, array($this, 'enqueue_styles'));
79
 
80
- $page_hook_suffix = add_submenu_page($menu_slug, $this->__('Add New Role'), $this->__('Add New'), $this->get_capability_string('create'), self::PLUGIN_SLUG . '-add-new', array($this, 'add_new_role'));
81
  add_action('admin_print_scripts-' . $page_hook_suffix, array($this, 'enqueue_scripts'));
82
  add_action('admin_print_styles-' . $page_hook_suffix, array($this, 'enqueue_styles'));
83
  }
@@ -85,13 +186,14 @@ if (!class_exists('WPFront_User_Role_Editor')) {
85
  //add scripts
86
  public function enqueue_scripts() {
87
  // $jsRoot = $this->pluginURLRoot . 'js/';
88
-
89
  wp_enqueue_script('jquery');
90
  }
91
 
92
  //add styles
93
  public function enqueue_styles() {
94
- // $cssRoot = $this->pluginURLRoot . 'css/';
 
95
  }
96
 
97
  //options page scripts
@@ -102,29 +204,11 @@ if (!class_exists('WPFront_User_Role_Editor')) {
102
  //options page styles
103
  public function enqueue_options_styles() {
104
  $this->enqueue_styles();
105
-
106
  $styleRoot = $this->pluginURLRoot . 'css/';
107
  wp_enqueue_style('wpfront-user-role-editor-options', $styleRoot . 'options.css', array(), self::VERSION);
108
  }
109
 
110
- public function plugins_loaded() {
111
- //load plugin options
112
- $this->reload_option();
113
- }
114
-
115
- private function reload_option() {
116
- $this->options = new WPFront_User_Role_Editor_Options(self::OPTION_NAME, self::PLUGIN_SLUG);
117
- }
118
-
119
- public function options_page() {
120
- if (!current_user_can('manage_options')) {
121
- wp_die($this->__('You do not have sufficient permissions to access this page.'));
122
- return;
123
- }
124
-
125
- include($this->pluginDIRRoot . 'templates/options-template.php');
126
- }
127
-
128
  public function update_options_callback() {
129
  check_ajax_referer($_POST['referer'], 'nonce');
130
 
@@ -137,13 +221,13 @@ if (!class_exists('WPFront_User_Role_Editor')) {
137
 
138
  if ($this->options->enable_role_capabilities()) {
139
  $role_admin = get_role('administrator');
140
- foreach ($this->role_caps as $value) {
141
  $role_admin->add_cap($value, TRUE);
142
  }
143
  } else {
144
  global $wp_roles;
145
  foreach ($wp_roles->role_objects as $key => $role) {
146
- foreach ($this->role_caps as $value) {
147
  $role->remove_cap($value);
148
  }
149
  }
@@ -153,123 +237,44 @@ if (!class_exists('WPFront_User_Role_Editor')) {
153
  die();
154
  }
155
 
156
- public function list_roles() {
157
- $no_access = FALSE;
158
-
159
- if (!current_user_can($this->get_capability_string('list'))) {
160
- $no_access = TRUE;
161
- }
162
-
163
- if (!empty($_GET['edit_role'])) {
164
- if (!current_user_can($this->get_capability_string('edit'))) {
165
- $no_access = TRUE;
166
- } else {
167
- $edit_role = $_GET['edit_role'];
168
- if (get_role($edit_role) == NULL) {
169
- $no_access = TRUE;
170
- } else {
171
- if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
172
- $roles = get_editable_roles();
173
- $no_access = !array_key_exists($edit_role, $roles);
174
- if ($edit_role == 'administrator')
175
- $no_access = TRUE;
176
- }
177
- }
178
- }
179
-
180
- if (!$no_access) {
181
- include($this->pluginDIRRoot . 'templates/add-edit-role.php');
182
- return;
183
- }
184
- } else if (!empty($_GET['delete_role'])) {
185
- if (!current_user_can($this->get_capability_string('delete'))) {
186
- $no_access = TRUE;
187
- } else {
188
- $delete_role = $_GET['delete_role'];
189
- if (get_role($delete_role) == NULL) {
190
- $no_access = TRUE;
191
- } else {
192
- if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
193
- $roles = get_editable_roles();
194
- $no_access = !array_key_exists($delete_role, $roles);
195
- if ($delete_role == 'administrator')
196
- $no_access = TRUE;
197
- }
198
- }
199
- $this->delete_roles = array($delete_role);
200
- }
201
-
202
- if (!$no_access) {
203
- include($this->pluginDIRRoot . 'templates/delete-role.php');
204
- return;
205
- }
206
- } else if ((!empty($_POST['doaction_top']) && !empty($_POST['action_top'])) || (!empty($_POST['doaction_bottom']) && !empty($_POST['action_bottom']))) {
207
- $action = $_POST['action_top'] == "-1" ? $_POST['action_bottom'] : $_POST['action_top'];
208
- switch ($action) {
209
- case 'delete':
210
- $this->delete_roles = array();
211
- global $wp_roles;
212
- foreach ($wp_roles->role_names as $role => $name) {
213
- if (!empty($_POST['cb-select-' . $role]))
214
- $this->delete_roles[] = $role;
215
- }
216
-
217
- if (!empty($this->delete_roles)) {
218
- include($this->pluginDIRRoot . 'templates/delete-role.php');
219
- return;
220
- }
221
- }
222
- } else if (!empty($_POST['confirm-delete'])) {
223
- include($this->pluginDIRRoot . 'templates/delete-role.php');
224
- return;
225
- }
226
-
227
- if ($no_access) {
228
- wp_die($this->__('You do not have sufficient permissions to access this page.'));
229
- return;
230
- }
231
 
232
- include($this->pluginDIRRoot . 'templates/list-roles.php');
233
  }
234
 
235
- public function add_new_role() {
236
- if (!current_user_can($this->get_capability_string('create'))) {
237
- wp_die($this->__('You do not have sufficient permissions to access this page.'));
238
- return;
239
- }
240
-
241
- include($this->pluginDIRRoot . 'templates/add-edit-role.php');
242
  }
243
 
244
- public function copy_capabilities_callback() {
245
- if (empty($_POST['role'])) {
246
- echo '{}';
247
- die();
248
- return;
249
- }
250
-
251
- $role = get_role($_POST['role']);
252
- if ($role == NULL) {
253
- echo '{}';
254
- die();
255
- return;
256
  }
257
-
258
- echo json_encode($role->capabilities);
259
- die();
260
  }
261
 
262
- protected function create_nonce() {
263
  if (empty($_SERVER['REQUEST_URI'])) {
264
- wp_die($this->__('You do not have sufficient permissions to access this page.'));
265
  exit;
 
266
  }
267
  $referer = $_SERVER['REQUEST_URI'];
268
  echo '<input type = "hidden" name = "_wpnonce" value = "' . wp_create_nonce($referer) . '" />';
269
  echo '<input type = "hidden" name = "_wp_http_referer" value = "' . $referer . '" />';
270
  }
271
 
272
- protected function verify_nonce() {
273
  if (strtolower($_SERVER['REQUEST_METHOD']) === 'post') {
274
  $flag = TRUE;
275
  if (empty($_POST['_wpnonce'])) {
@@ -281,12 +286,70 @@ if (!class_exists('WPFront_User_Role_Editor')) {
281
  }
282
 
283
  if (!$flag) {
284
- wp_die($this->__('You do not have sufficient permissions to access this page.'));
285
  exit;
286
  }
287
  }
288
  }
289
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  }
291
 
292
  }
1
  <?php
 
2
  /*
3
  WPFront User Role Editor Plugin
4
  Copyright (C) 2014, WPFront.com
23
 
24
  require_once("base/class-wpfront-base.php");
25
  require_once("class-wpfront-user-role-editor-options.php");
26
+ require_once("class-wpfront-user-role-editor-list.php");
27
+ require_once("class-wpfront-user-role-editor-add-edit.php");
28
+ require_once("class-wpfront-user-role-editor-delete.php");
29
 
30
  if (!class_exists('WPFront_User_Role_Editor')) {
31
 
38
  class WPFront_User_Role_Editor extends WPFront_Base {
39
 
40
  //Constants
41
+ const VERSION = '1.0';
42
  const OPTIONS_GROUP_NAME = 'wpfront-user-role-editor-options-group';
43
  const OPTION_NAME = 'wpfront-user-role-editor-options';
44
  const PLUGIN_SLUG = 'wpfront-user-role-editor';
45
 
46
+ public static $ROLE_CAPS = array('wpfront_list_roles', 'wpfront_create_roles', 'wpfront_edit_roles', 'wpfront_delete_roles');
47
+ public static $DEFAULT_ROLES = array('administrator', 'editor', 'author', 'contributor', 'subscriber');
48
+ public static $STANDARD_CAPABILITIES = array(
49
+ 'Dashboard' => array(
50
+ 'read',
51
+ 'edit_dashboard'
52
+ ),
53
+ 'Posts' => array(
54
+ 'publish_posts',
55
+ 'edit_posts',
56
+ 'delete_posts',
57
+ 'edit_published_posts',
58
+ 'delete_published_posts',
59
+ 'edit_others_posts',
60
+ 'delete_others_posts',
61
+ 'read_private_posts',
62
+ 'edit_private_posts',
63
+ 'delete_private_posts',
64
+ 'manage_categories'
65
+ ),
66
+ 'Media' => array(
67
+ 'upload_files',
68
+ 'unfiltered_upload'
69
+ ),
70
+ 'Pages' => array(
71
+ 'publish_pages',
72
+ 'edit_pages',
73
+ 'delete_pages',
74
+ 'edit_published_pages',
75
+ 'delete_published_pages',
76
+ 'edit_others_pages',
77
+ 'delete_others_pages',
78
+ 'read_private_pages',
79
+ 'edit_private_pages',
80
+ 'delete_private_pages'
81
+ ),
82
+ 'Comments' => array(
83
+ 'edit_comment',
84
+ 'moderate_comments'
85
+ ),
86
+ 'Themes' => array(
87
+ 'switch_themes',
88
+ 'edit_theme_options',
89
+ 'edit_themes',
90
+ 'delete_themes',
91
+ 'install_themes',
92
+ 'update_themes'
93
+ ),
94
+ 'Plugins' => array(
95
+ 'activate_plugins',
96
+ 'edit_plugins',
97
+ 'install_plugins',
98
+ 'update_plugins',
99
+ 'delete_plugins'
100
+ ),
101
+ 'Users' => array(
102
+ 'list_users',
103
+ 'create_users',
104
+ 'edit_users',
105
+ 'delete_users',
106
+ 'promote_users',
107
+ 'add_users',
108
+ 'remove_users'
109
+ ),
110
+ 'Tools' => array(
111
+ 'import',
112
+ 'export'
113
+ ),
114
+ 'Admin' => array(
115
+ 'manage_options',
116
+ 'update_core',
117
+ 'unfiltered_html'
118
+ ),
119
+ 'Links' => array(
120
+ 'manage_links'
121
+ )
122
+ );
123
+ public static $DEPRECATED_CAPABILITIES = array(
124
+ 'Deprecated' => array(
125
+ 'edit_files',
126
+ 'level_0',
127
+ 'level_1',
128
+ 'level_2',
129
+ 'level_3',
130
+ 'level_4',
131
+ 'level_5',
132
+ 'level_6',
133
+ 'level_7',
134
+ 'level_8',
135
+ 'level_9',
136
+ 'level_10'
137
+ )
138
+ );
139
+ public static $OTHER_CAPABILITIES = array(
140
+ 'Other Capabilities' => array(
141
+ )
142
+ );
143
+ private static $CAPABILITIES = NULL;
144
  //Variables
145
  protected $options;
 
 
 
146
 
147
  function __construct() {
148
  parent::__construct(__FILE__, self::PLUGIN_SLUG);
150
  $this->add_menu($this->__('WPFront User Role Editor'), $this->__('User Role Editor'));
151
  }
152
 
153
+ public function plugins_loaded() {
154
+ //load plugin options
155
+ $this->reload_option();
156
+ }
157
 
158
+ private function reload_option() {
159
+ $this->options = new WPFront_User_Role_Editor_Options(self::OPTION_NAME, self::PLUGIN_SLUG);
160
  }
161
 
162
+ public function admin_init() {
163
+ register_setting(self::OPTIONS_GROUP_NAME, self::OPTION_NAME);
 
164
 
165
+ add_action('wp_ajax_wpfront_user_role_editor_update_options', array($this, 'update_options_callback'));
166
+
167
+ $add_new = new WPFront_User_Role_Editor_Add_Edit($this);
168
+ $add_new->ajax_register();
169
  }
170
 
171
  public function admin_menu() {
172
  parent::admin_menu();
173
 
174
+ $menu_slug = WPFront_User_Role_Editor_List::MENU_SLUG;
175
  add_menu_page($this->__('Roles'), $this->__('Roles'), $this->get_capability_string('list'), $menu_slug, null, $this->pluginURL() . 'images/roles_menu.png', '69.9999');
176
 
177
+ $page_hook_suffix = add_submenu_page($menu_slug, $this->__('Roles'), $this->__('All Roles'), $this->get_capability_string('list'), $menu_slug, array(new WPFront_User_Role_Editor_List($this), 'list_roles'));
178
  add_action('admin_print_scripts-' . $page_hook_suffix, array($this, 'enqueue_scripts'));
179
  add_action('admin_print_styles-' . $page_hook_suffix, array($this, 'enqueue_styles'));
180
 
181
+ $page_hook_suffix = add_submenu_page($menu_slug, $this->__('Add New Role'), $this->__('Add New'), $this->get_capability_string('create'), WPFront_User_Role_Editor_Add_Edit::MENU_SLUG, array(new WPFront_User_Role_Editor_Add_Edit($this), 'add_edit_role'));
182
  add_action('admin_print_scripts-' . $page_hook_suffix, array($this, 'enqueue_scripts'));
183
  add_action('admin_print_styles-' . $page_hook_suffix, array($this, 'enqueue_styles'));
184
  }
186
  //add scripts
187
  public function enqueue_scripts() {
188
  // $jsRoot = $this->pluginURLRoot . 'js/';
189
+
190
  wp_enqueue_script('jquery');
191
  }
192
 
193
  //add styles
194
  public function enqueue_styles() {
195
+ $styleRoot = $this->pluginURLRoot . 'css/';
196
+ wp_enqueue_style('wpfront-user-role-editor-styles', $styleRoot . 'style.css', array(), self::VERSION);
197
  }
198
 
199
  //options page scripts
204
  //options page styles
205
  public function enqueue_options_styles() {
206
  $this->enqueue_styles();
207
+
208
  $styleRoot = $this->pluginURLRoot . 'css/';
209
  wp_enqueue_style('wpfront-user-role-editor-options', $styleRoot . 'options.css', array(), self::VERSION);
210
  }
211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  public function update_options_callback() {
213
  check_ajax_referer($_POST['referer'], 'nonce');
214
 
221
 
222
  if ($this->options->enable_role_capabilities()) {
223
  $role_admin = get_role('administrator');
224
+ foreach (self::$ROLE_CAPS as $value) {
225
  $role_admin->add_cap($value, TRUE);
226
  }
227
  } else {
228
  global $wp_roles;
229
  foreach ($wp_roles->role_objects as $key => $role) {
230
+ foreach (self::$ROLE_CAPS as $value) {
231
  $role->remove_cap($value);
232
  }
233
  }
237
  die();
238
  }
239
 
240
+ public function get_capability_string($capability) {
241
+ if ($this->options->enable_role_capabilities())
242
+ return 'wpfront_' . $capability . '_roles';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
 
244
+ return $capability . '_users';
245
  }
246
 
247
+ public function permission_denied() {
248
+ wp_die($this->__('You do not have sufficient permissions to access this page.'));
 
 
 
 
 
249
  }
250
 
251
+ public function current_user_can($capability) {
252
+ switch ($capability) {
253
+ case 'list_roles':
254
+ return current_user_can($this->get_capability_string('list'));
255
+ case 'edit_roles':
256
+ return current_user_can($this->get_capability_string('edit'));
257
+ case 'delete_roles':
258
+ return current_user_can($this->get_capability_string('delete'));
259
+ case 'create_roles':
260
+ return current_user_can($this->get_capability_string('create'));
261
+ default :
262
+ return current_user_can($capability);
263
  }
 
 
 
264
  }
265
 
266
+ public function create_nonce() {
267
  if (empty($_SERVER['REQUEST_URI'])) {
268
+ $this->permission_denied();
269
  exit;
270
+ return;
271
  }
272
  $referer = $_SERVER['REQUEST_URI'];
273
  echo '<input type = "hidden" name = "_wpnonce" value = "' . wp_create_nonce($referer) . '" />';
274
  echo '<input type = "hidden" name = "_wp_http_referer" value = "' . $referer . '" />';
275
  }
276
 
277
+ public function verify_nonce() {
278
  if (strtolower($_SERVER['REQUEST_METHOD']) === 'post') {
279
  $flag = TRUE;
280
  if (empty($_POST['_wpnonce'])) {
286
  }
287
 
288
  if (!$flag) {
289
+ $this->permission_denied();
290
  exit;
291
  }
292
  }
293
  }
294
 
295
+ public function footer() {
296
+ ?>
297
+ <div class="footer">
298
+ <a target="_blank" href="http://wpfront.com/contact/"><?php echo $this->__('Feedback'); ?></a>
299
+ |
300
+ <a target="_blank" href="http://wpfront.com/donate/"><?php echo $this->__('Buy me a Beer'); ?></a>
301
+ </div>
302
+ <?php
303
+ }
304
+
305
+ public function get_capabilities() {
306
+ if (self::$CAPABILITIES != NULL)
307
+ return self::$CAPABILITIES;
308
+
309
+ self::$CAPABILITIES = array();
310
+
311
+ foreach (self::$STANDARD_CAPABILITIES as $key => $value) {
312
+ self::$CAPABILITIES[$key] = $value;
313
+ }
314
+
315
+ foreach (self::$DEPRECATED_CAPABILITIES as $key => $value) {
316
+ self::$CAPABILITIES[$key] = $value;
317
+ }
318
+
319
+ if ($this->options->enable_role_capabilities())
320
+ self::$CAPABILITIES['Roles (WPFront)'] = self::$ROLE_CAPS;
321
+
322
+ reset(self::$OTHER_CAPABILITIES);
323
+ $other_key = key(self::$OTHER_CAPABILITIES);
324
+
325
+ global $wp_roles;
326
+ foreach ($wp_roles->roles as $key => $role) {
327
+ foreach ($role['capabilities'] as $cap => $value) {
328
+ $found = FALSE;
329
+ foreach (self::$CAPABILITIES as $g => $wcaps) {
330
+ if (in_array($cap, $wcaps)) {
331
+ $found = TRUE;
332
+ break;
333
+ }
334
+ }
335
+ if (!$found && !in_array($cap, self::$OTHER_CAPABILITIES[$other_key])) {
336
+ self::$OTHER_CAPABILITIES[$other_key][] = $cap;
337
+ }
338
+ }
339
+ }
340
+
341
+ foreach (self::$OTHER_CAPABILITIES as $key => $value) {
342
+ if (count($value) > 0)
343
+ self::$CAPABILITIES[$key] = $value;
344
+ }
345
+
346
+ return self::$CAPABILITIES;
347
+ }
348
+
349
+ public function display_deprecated() {
350
+ return $this->options->display_deprecated();
351
+ }
352
+
353
  }
354
 
355
  }
css/style.css ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ WPFront User Role Editor Plugin
3
+ Copyright (C) 2014, WPFront.com
4
+ Website: wpfront.com
5
+ Contact: syam@wpfront.com
6
+
7
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
8
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
9
+ St, Fifth Floor, Boston, MA 02110, USA
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
12
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
13
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
14
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
15
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
17
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
18
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
20
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
+ */
22
+
23
+ div.wrap div.footer {
24
+ text-align: center;
25
+ }
26
+
27
+ div.list-roles td.column-userdefault img.user-default {
28
+ width: 16px;
29
+ height: 16px;
30
+ }
31
+
32
+ div.list-roles table div.row-actions {
33
+ white-space: nowrap;
34
+ }
35
+
36
+ div.role-add-new form#createuser table.sub-head {
37
+ width: 100%;
38
+ }
39
+
40
+ div.role-add-new form#createuser table.sub-head th.sub-head {
41
+ text-align: left;
42
+ padding: 0px;
43
+ }
44
+
45
+ div.role-add-new form#createuser table.sub-head th.sub-head h3 {
46
+ }
47
+
48
+ div.role-add-new form#createuser table.sub-head td.sub-head-controls {
49
+ text-align: right;
50
+ padding: 0px;
51
+ }
52
+
53
+ div.role-add-new form#createuser table.sub-head td.sub-head-controls div {
54
+ display: inline-block;
55
+ vertical-align: top;
56
+ }
57
+
58
+ div.role-add-new form#createuser table.sub-head td.sub-head-controls div.spacer {
59
+ width: 10px;
60
+ height: 0px;
61
+ }
62
+
63
+ div.role-add-new form#createuser table.sub-head td.sub-head-controls input.select-all, div.role-add-new form#createuser table.sub-head td.sub-head-controls input.select-none {
64
+ width: 100px;
65
+ }
66
+
67
+ div.role-add-new div.metabox-holder div.postbox {
68
+ margin-bottom: 8px;
69
+ }
70
+
71
+ div.role-add-new div.metabox-holder div.postbox.deprecated {
72
+ filter: alpha(opacity=80);
73
+ opacity: 0.8;
74
+ }
75
+
76
+ div.role-add-new div.metabox-holder div.postbox h3.hndle {
77
+ cursor: default;
78
+ }
79
+
80
+ div.role-add-new div.metabox-holder div.postbox div.inside div.main div {
81
+ padding: 2px 0px;
82
+ display: inline-block;
83
+ width: 250px;
84
+ }
85
+
86
+ div.role-add-new div.metabox-holder div.postbox label {
87
+ vertical-align: top;
88
+ }
89
+
90
+ div.role-add-new div.metabox-holder div.postbox div.main img.help {
91
+ width: 12px;
92
+ height: 12px;
93
+ opacity: 0.8;
94
+ }
95
+
96
+ div.role-add-new div.footer {
97
+ text-align: center;
98
+ }
images/check-icon.png ADDED
Binary file
images/help.png ADDED
Binary file
images/roles_menu.png CHANGED
Binary file
images/settings32x32.png CHANGED
Binary file
languages/wpfront-user-role-editor.mo CHANGED
Binary file
languages/wpfront-user-role-editor.po CHANGED
@@ -1,8 +1,8 @@
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: WPFront Notification Bar\n"
4
- "POT-Creation-Date: 2014-03-01 18:07-0700\n"
5
- "PO-Revision-Date: 2014-03-01 18:07-0700\n"
6
  "Last-Translator: \n"
7
  "Language-Team: WPFront <contact@wpfront.com>\n"
8
  "Language: en\n"
@@ -17,106 +17,99 @@ msgstr ""
17
  "X-Poedit-SearchPath-0: ..\n"
18
 
19
  #: ../classes/base/class-wpfront-base-menu.php:52
20
- #: ../classes/base/class-wpfront-base-menu.php:62
21
  msgid "Name"
22
  msgstr "Name"
23
 
24
  #: ../classes/base/class-wpfront-base-menu.php:53
25
- #: ../classes/base/class-wpfront-base-menu.php:63
26
  msgid "Version"
27
  msgstr "Version"
28
 
29
  #: ../classes/base/class-wpfront-base-menu.php:54
30
- #: ../classes/base/class-wpfront-base-menu.php:64
31
  msgid "Rating"
32
  msgstr "Rating"
33
 
34
  #: ../classes/base/class-wpfront-base-menu.php:55
35
- #: ../classes/base/class-wpfront-base-menu.php:65
36
  msgid "Description"
37
  msgstr "Description"
38
 
39
- #: ../classes/base/class-wpfront-base-menu.php:75
40
  #, php-format
41
  msgid "based on %s rating(s)"
42
  msgstr "based on %s rating(s)"
43
 
44
- #: ../classes/base/class-wpfront-base-menu.php:111
45
  msgid "Unable to communicate with WordPress.org"
46
  msgstr "Unable to communicate with WordPress.org"
47
 
48
- #: ../classes/base/class-wpfront-base-menu.php:129
49
- #: ../classes/base/class-wpfront-base-menu.php:223
50
  msgid "WPFront Plugins"
51
  msgstr "WPFront Plugins"
52
 
53
- #: ../classes/base/class-wpfront-base-menu.php:153
54
  #, php-format
55
  msgid "By %s"
56
  msgstr "By %s"
57
 
58
- #: ../classes/base/class-wpfront-base-menu.php:160
59
  #, php-format
60
  msgid "More information about %s"
61
  msgstr "More information about %s"
62
 
63
- #: ../classes/base/class-wpfront-base-menu.php:160
64
  msgid "Details"
65
  msgstr "Details"
66
 
67
- #: ../classes/base/class-wpfront-base-menu.php:169
68
  #, php-format
69
  msgid "Install %s"
70
  msgstr "Install %s"
71
 
72
- #: ../classes/base/class-wpfront-base-menu.php:169
73
  msgid "Install Now"
74
  msgstr "Install Now"
75
 
76
- #: ../classes/base/class-wpfront-base-menu.php:174
77
  #, php-format
78
  msgid "Update to version %s"
79
  msgstr "Update to version %s"
80
 
81
- #: ../classes/base/class-wpfront-base-menu.php:174
82
  msgid "Update Now"
83
  msgstr "Update Now"
84
 
85
- #: ../classes/base/class-wpfront-base-menu.php:179
86
  msgid "This plugin is already installed and is up to date"
87
  msgstr "This plugin is already installed and is up to date"
88
 
89
- #: ../classes/base/class-wpfront-base-menu.php:179
90
  msgid "Installed"
91
  msgstr "Installed"
92
 
93
- #: ../classes/base/class-wpfront-base-menu.php:181
94
  #: ../classes/base/class-wpfront-base.php:105
95
  msgid "Settings"
96
  msgstr "Settings"
97
 
98
- #: ../classes/base/class-wpfront-base-menu.php:183
99
  msgid "Activate"
100
  msgstr "Activate"
101
 
102
- #: ../classes/base/class-wpfront-base-menu.php:205
 
103
  msgid "Feedback"
104
  msgstr "Feedback"
105
 
106
- #: ../classes/base/class-wpfront-base-menu.php:222
107
  msgid "WPFront"
108
  msgstr "WPFront"
109
 
110
- #: ../classes/base/class-wpfront-base-menu.php:223
111
  msgid "All Plugins"
112
  msgstr "All Plugins"
113
 
114
  #: ../classes/base/class-wpfront-base.php:130
115
- #: ../classes/class-wpfront-user-role-editor.php:138
116
- #: ../classes/class-wpfront-user-role-editor.php:244
117
- #: ../classes/class-wpfront-user-role-editor.php:253
118
- #: ../classes/class-wpfront-user-role-editor.php:280
119
- #: ../classes/class-wpfront-user-role-editor.php:300
120
  msgid "You do not have sufficient permissions to access this page."
121
  msgstr "You do not have sufficient permissions to access this page."
122
 
@@ -156,179 +149,186 @@ msgstr "Contact Me (syam@wpfront.com)"
156
  msgid "Save Changes"
157
  msgstr "Save Changes"
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  #: ../classes/class-wpfront-user-role-editor-options.php:41
160
  msgid "Display Deprecated Capabilities"
161
- msgstr ""
162
 
163
  #: ../classes/class-wpfront-user-role-editor-options.php:42
164
  msgid "Add Role Capabilities"
165
- msgstr ""
166
 
167
- #: ../classes/class-wpfront-user-role-editor.php:53
168
  msgid "WPFront User Role Editor"
169
- msgstr ""
170
 
171
- #: ../classes/class-wpfront-user-role-editor.php:53
172
  msgid "User Role Editor"
173
- msgstr ""
174
 
175
- #: ../classes/class-wpfront-user-role-editor.php:74
176
- #: ../classes/class-wpfront-user-role-editor.php:76
177
- #: ../templates/list-roles.php:128
178
  msgid "Roles"
179
- msgstr ""
180
 
181
- #: ../classes/class-wpfront-user-role-editor.php:76
182
  msgid "All Roles"
183
  msgstr "All Roles"
184
 
185
- #: ../classes/class-wpfront-user-role-editor.php:80
186
- #: ../templates/add-edit-role.php:367 ../templates/add-edit-role.php:458
187
  msgid "Add New Role"
188
- msgstr ""
189
 
190
- #: ../classes/class-wpfront-user-role-editor.php:80
191
- #: ../templates/add-edit-role.php:371 ../templates/list-roles.php:129
192
  msgid "Add New"
193
- msgstr ""
194
 
195
- #: ../templates/add-edit-role.php:367
 
 
 
 
196
  msgid "Edit Role"
197
- msgstr ""
198
 
199
- #: ../templates/add-edit-role.php:381 ../templates/add-edit-role.php:389
200
  msgid "ERROR"
201
- msgstr ""
202
 
203
- #: ../templates/add-edit-role.php:381
204
  msgid "This role already exists in this site."
205
- msgstr ""
206
 
207
- #: ../templates/add-edit-role.php:389
208
  msgid "There was an unexpected error while performing this action."
209
- msgstr ""
210
 
211
- #: ../templates/add-edit-role.php:398
212
  msgid "Create a brand new role and add it to this site."
213
- msgstr ""
214
-
215
- #: ../templates/add-edit-role.php:408 ../templates/list-roles.php:43
216
- msgid "Display Name"
217
- msgstr "Display Name"
218
 
219
- #: ../templates/add-edit-role.php:408 ../templates/add-edit-role.php:416
220
  msgid "required"
221
- msgstr ""
222
 
223
- #: ../templates/add-edit-role.php:416 ../templates/list-roles.php:46
224
- msgid "Role Name"
225
- msgstr "Role Name"
226
-
227
- #: ../templates/add-edit-role.php:428 ../templates/list-roles.php:55
228
- msgid "Capabilities"
229
- msgstr ""
230
-
231
- #: ../templates/add-edit-role.php:432
232
  msgid "Copy from"
233
- msgstr ""
234
-
235
- #: ../templates/add-edit-role.php:444 ../templates/list-roles.php:71
236
- msgid "Apply"
237
- msgstr ""
238
 
239
- #: ../templates/add-edit-role.php:448 ../templates/list-roles.php:39
240
- msgid "Select All"
241
- msgstr ""
242
-
243
- #: ../templates/add-edit-role.php:449
244
  msgid "Select None"
245
- msgstr ""
246
 
247
- #: ../templates/add-edit-role.php:458
248
  msgid "Update Role"
249
  msgstr "Update Role"
250
 
251
- #: ../templates/delete-role.php:53
252
- msgid "This role cannot be deleted: Permission denied."
253
- msgstr ""
254
-
255
- #: ../templates/delete-role.php:55
256
- msgid "'administrator' role cannot be deleted."
257
- msgstr ""
258
-
259
- #: ../templates/delete-role.php:57
260
- msgid "Current user's role cannot be deleted."
261
- msgstr ""
262
-
263
- #: ../templates/delete-role.php:76
264
  msgid "Delete Roles"
265
- msgstr ""
266
 
267
- #: ../templates/delete-role.php:77
268
  msgid "You have specified these roles for deletion"
269
- msgstr ""
270
 
271
- #: ../templates/delete-role.php:84
272
  msgid "Role"
273
- msgstr ""
274
-
275
- #: ../templates/list-roles.php:49
276
- msgid "Type"
277
- msgstr ""
278
-
279
- #: ../templates/list-roles.php:52
280
- msgid "Users"
281
- msgstr ""
282
-
283
- #: ../templates/list-roles.php:66
284
- msgid "Bulk Actions"
285
- msgstr "Bulk Actions"
286
 
287
- #: ../templates/list-roles.php:68 ../templates/list-roles.php:270
288
- msgid "Delete"
289
- msgstr ""
290
-
291
- #: ../templates/list-roles.php:73
292
- #, php-format
293
- msgid "%s item(s)"
294
- msgstr ""
295
-
296
- #: ../templates/list-roles.php:131
297
- #, php-format
298
- msgid "Search results for “%s”"
299
- msgstr ""
300
-
301
- #: ../templates/list-roles.php:137
302
- msgid "All"
303
- msgstr ""
304
-
305
- #: ../templates/list-roles.php:151
306
- msgid "Having Users"
307
- msgstr ""
308
-
309
- #: ../templates/list-roles.php:159
310
- msgid "No Users"
311
- msgstr ""
312
-
313
- #: ../templates/list-roles.php:167
314
- msgid "Built-In"
315
- msgstr ""
316
-
317
- #: ../templates/list-roles.php:174
318
- msgid "Custom"
319
- msgstr "Custom"
320
 
321
- #: ../templates/list-roles.php:222 ../templates/list-roles.php:224
322
  msgid "Search Roles"
323
- msgstr ""
324
 
325
- #: ../templates/list-roles.php:264
326
  msgid "Edit"
327
- msgstr ""
328
 
329
- #: ../templates/list-roles.php:264
330
  msgid "View"
331
- msgstr ""
 
 
 
 
332
 
333
  #: ../templates/options-template.php:32
334
  msgid "WPFront User Role Editor Settings"
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: WPFront Notification Bar\n"
4
+ "POT-Creation-Date: 2014-04-30 18:53-0700\n"
5
+ "PO-Revision-Date: 2014-04-30 18:54-0700\n"
6
  "Last-Translator: \n"
7
  "Language-Team: WPFront <contact@wpfront.com>\n"
8
  "Language: en\n"
17
  "X-Poedit-SearchPath-0: ..\n"
18
 
19
  #: ../classes/base/class-wpfront-base-menu.php:52
 
20
  msgid "Name"
21
  msgstr "Name"
22
 
23
  #: ../classes/base/class-wpfront-base-menu.php:53
 
24
  msgid "Version"
25
  msgstr "Version"
26
 
27
  #: ../classes/base/class-wpfront-base-menu.php:54
 
28
  msgid "Rating"
29
  msgstr "Rating"
30
 
31
  #: ../classes/base/class-wpfront-base-menu.php:55
 
32
  msgid "Description"
33
  msgstr "Description"
34
 
35
+ #: ../classes/base/class-wpfront-base-menu.php:69
36
  #, php-format
37
  msgid "based on %s rating(s)"
38
  msgstr "based on %s rating(s)"
39
 
40
+ #: ../classes/base/class-wpfront-base-menu.php:105
41
  msgid "Unable to communicate with WordPress.org"
42
  msgstr "Unable to communicate with WordPress.org"
43
 
44
+ #: ../classes/base/class-wpfront-base-menu.php:123
45
+ #: ../classes/base/class-wpfront-base-menu.php:217
46
  msgid "WPFront Plugins"
47
  msgstr "WPFront Plugins"
48
 
49
+ #: ../classes/base/class-wpfront-base-menu.php:147
50
  #, php-format
51
  msgid "By %s"
52
  msgstr "By %s"
53
 
54
+ #: ../classes/base/class-wpfront-base-menu.php:154
55
  #, php-format
56
  msgid "More information about %s"
57
  msgstr "More information about %s"
58
 
59
+ #: ../classes/base/class-wpfront-base-menu.php:154
60
  msgid "Details"
61
  msgstr "Details"
62
 
63
+ #: ../classes/base/class-wpfront-base-menu.php:163
64
  #, php-format
65
  msgid "Install %s"
66
  msgstr "Install %s"
67
 
68
+ #: ../classes/base/class-wpfront-base-menu.php:163
69
  msgid "Install Now"
70
  msgstr "Install Now"
71
 
72
+ #: ../classes/base/class-wpfront-base-menu.php:168
73
  #, php-format
74
  msgid "Update to version %s"
75
  msgstr "Update to version %s"
76
 
77
+ #: ../classes/base/class-wpfront-base-menu.php:168
78
  msgid "Update Now"
79
  msgstr "Update Now"
80
 
81
+ #: ../classes/base/class-wpfront-base-menu.php:173
82
  msgid "This plugin is already installed and is up to date"
83
  msgstr "This plugin is already installed and is up to date"
84
 
85
+ #: ../classes/base/class-wpfront-base-menu.php:173
86
  msgid "Installed"
87
  msgstr "Installed"
88
 
89
+ #: ../classes/base/class-wpfront-base-menu.php:175
90
  #: ../classes/base/class-wpfront-base.php:105
91
  msgid "Settings"
92
  msgstr "Settings"
93
 
94
+ #: ../classes/base/class-wpfront-base-menu.php:177
95
  msgid "Activate"
96
  msgstr "Activate"
97
 
98
+ #: ../classes/base/class-wpfront-base-menu.php:199
99
+ #: ../classes/class-wpfront-user-role-editor.php:298
100
  msgid "Feedback"
101
  msgstr "Feedback"
102
 
103
+ #: ../classes/base/class-wpfront-base-menu.php:216
104
  msgid "WPFront"
105
  msgstr "WPFront"
106
 
107
+ #: ../classes/base/class-wpfront-base-menu.php:217
108
  msgid "All Plugins"
109
  msgstr "All Plugins"
110
 
111
  #: ../classes/base/class-wpfront-base.php:130
112
+ #: ../classes/class-wpfront-user-role-editor.php:248
 
 
 
 
113
  msgid "You do not have sufficient permissions to access this page."
114
  msgstr "You do not have sufficient permissions to access this page."
115
 
149
  msgid "Save Changes"
150
  msgstr "Save Changes"
151
 
152
+ #: ../classes/class-wpfront-user-role-editor-list.php:238
153
+ #: ../templates/add-edit-role.php:111
154
+ msgid "Select All"
155
+ msgstr "Select All"
156
+
157
+ #: ../classes/class-wpfront-user-role-editor-list.php:242
158
+ #: ../templates/add-edit-role.php:71
159
+ msgid "Display Name"
160
+ msgstr "Display Name"
161
+
162
+ #: ../classes/class-wpfront-user-role-editor-list.php:245
163
+ #: ../templates/add-edit-role.php:81
164
+ msgid "Role Name"
165
+ msgstr "Role Name"
166
+
167
+ #: ../classes/class-wpfront-user-role-editor-list.php:248
168
+ msgid "Type"
169
+ msgstr "Type"
170
+
171
+ #: ../classes/class-wpfront-user-role-editor-list.php:251
172
+ msgid "User Default"
173
+ msgstr "User Default"
174
+
175
+ #: ../classes/class-wpfront-user-role-editor-list.php:254
176
+ msgid "Users"
177
+ msgstr "Users"
178
+
179
+ #: ../classes/class-wpfront-user-role-editor-list.php:257
180
+ #: ../templates/add-edit-role.php:95
181
+ msgid "Capabilities"
182
+ msgstr "Capabilities"
183
+
184
+ #: ../classes/class-wpfront-user-role-editor-list.php:268
185
+ msgid "Bulk Actions"
186
+ msgstr "Bulk Actions"
187
+
188
+ #: ../classes/class-wpfront-user-role-editor-list.php:270
189
+ #: ../templates/list-roles.php:101
190
+ msgid "Delete"
191
+ msgstr "Delete"
192
+
193
+ #: ../classes/class-wpfront-user-role-editor-list.php:273
194
+ #: ../templates/add-edit-role.php:107
195
+ msgid "Apply"
196
+ msgstr "Apply"
197
+
198
+ #: ../classes/class-wpfront-user-role-editor-list.php:275
199
+ #, php-format
200
+ msgid "%s item(s)"
201
+ msgstr "%s item(s)"
202
+
203
+ #: ../classes/class-wpfront-user-role-editor-list.php:298
204
+ msgid "All"
205
+ msgstr "All"
206
+
207
+ #: ../classes/class-wpfront-user-role-editor-list.php:309
208
+ msgid "Having Users"
209
+ msgstr "Having Users"
210
+
211
+ #: ../classes/class-wpfront-user-role-editor-list.php:315
212
+ msgid "No Users"
213
+ msgstr "No Users"
214
+
215
+ #: ../classes/class-wpfront-user-role-editor-list.php:326
216
+ #: ../templates/list-roles.php:114
217
+ msgid "Built-In"
218
+ msgstr "Built-In"
219
+
220
+ #: ../classes/class-wpfront-user-role-editor-list.php:332
221
+ #: ../templates/list-roles.php:114
222
+ msgid "Custom"
223
+ msgstr "Custom"
224
+
225
  #: ../classes/class-wpfront-user-role-editor-options.php:41
226
  msgid "Display Deprecated Capabilities"
227
+ msgstr "Display Deprecated Capabilities"
228
 
229
  #: ../classes/class-wpfront-user-role-editor-options.php:42
230
  msgid "Add Role Capabilities"
231
+ msgstr "Add Role Capabilities"
232
 
233
+ #: ../classes/class-wpfront-user-role-editor.php:150
234
  msgid "WPFront User Role Editor"
235
+ msgstr "WPFront User Role Editor"
236
 
237
+ #: ../classes/class-wpfront-user-role-editor.php:150
238
  msgid "User Role Editor"
239
+ msgstr "User Role Editor"
240
 
241
+ #: ../classes/class-wpfront-user-role-editor.php:175
242
+ #: ../classes/class-wpfront-user-role-editor.php:177
243
+ #: ../templates/list-roles.php:37
244
  msgid "Roles"
245
+ msgstr "Roles"
246
 
247
+ #: ../classes/class-wpfront-user-role-editor.php:177
248
  msgid "All Roles"
249
  msgstr "All Roles"
250
 
251
+ #: ../classes/class-wpfront-user-role-editor.php:181
252
+ #: ../templates/add-edit-role.php:35 ../templates/add-edit-role.php:154
253
  msgid "Add New Role"
254
+ msgstr "Add New Role"
255
 
256
+ #: ../classes/class-wpfront-user-role-editor.php:181
257
+ #: ../templates/add-edit-role.php:37 ../templates/list-roles.php:40
258
  msgid "Add New"
259
+ msgstr "Add New"
260
 
261
+ #: ../classes/class-wpfront-user-role-editor.php:300
262
+ msgid "Buy me a Beer"
263
+ msgstr "Buy me a Beer"
264
+
265
+ #: ../templates/add-edit-role.php:35
266
  msgid "Edit Role"
267
+ msgstr "Edit Role"
268
 
269
+ #: ../templates/add-edit-role.php:45 ../templates/add-edit-role.php:53
270
  msgid "ERROR"
271
+ msgstr "ERROR"
272
 
273
+ #: ../templates/add-edit-role.php:45
274
  msgid "This role already exists in this site."
275
+ msgstr "This role already exists in this site."
276
 
277
+ #: ../templates/add-edit-role.php:53
278
  msgid "There was an unexpected error while performing this action."
279
+ msgstr "There was an unexpected error while performing this action."
280
 
281
+ #: ../templates/add-edit-role.php:60
282
  msgid "Create a brand new role and add it to this site."
283
+ msgstr "Create a brand new role and add it to this site."
 
 
 
 
284
 
285
+ #: ../templates/add-edit-role.php:71 ../templates/add-edit-role.php:81
286
  msgid "required"
287
+ msgstr "required"
288
 
289
+ #: ../templates/add-edit-role.php:100
 
 
 
 
 
 
 
 
290
  msgid "Copy from"
291
+ msgstr "Copy from"
 
 
 
 
292
 
293
+ #: ../templates/add-edit-role.php:112
 
 
 
 
294
  msgid "Select None"
295
+ msgstr "Select None"
296
 
297
+ #: ../templates/add-edit-role.php:154
298
  msgid "Update Role"
299
  msgstr "Update Role"
300
 
301
+ #: ../templates/delete-role.php:37
 
 
 
 
 
 
 
 
 
 
 
 
302
  msgid "Delete Roles"
303
+ msgstr "Delete Roles"
304
 
305
+ #: ../templates/delete-role.php:38
306
  msgid "You have specified these roles for deletion"
307
+ msgstr "You have specified these roles for deletion"
308
 
309
+ #: ../templates/delete-role.php:45
310
  msgid "Role"
311
+ msgstr "Role"
 
 
 
 
 
 
 
 
 
 
 
 
312
 
313
+ #: ../templates/delete-role.php:57
314
+ msgid "Confirm Deletion"
315
+ msgstr "Confirm Deletion"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
 
317
+ #: ../templates/list-roles.php:62 ../templates/list-roles.php:64
318
  msgid "Search Roles"
319
+ msgstr "Search Roles"
320
 
321
+ #: ../templates/list-roles.php:98
322
  msgid "Edit"
323
+ msgstr "Edit"
324
 
325
+ #: ../templates/list-roles.php:98
326
  msgid "View"
327
+ msgstr "View"
328
+
329
+ #: ../templates/list-roles.php:104
330
+ msgid "Default"
331
+ msgstr "Default"
332
 
333
  #: ../templates/options-template.php:32
334
  msgid "WPFront User Role Editor Settings"
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: syammohanm
3
  Donate link: http://wpfront.com/donate/
4
  Tags: user role editor, role editor, user role, role, user roles, roles, user roles editor, roles editor, role manager, roles manager, manage roles, manage role, access, capability, editor, permission, role, security, user, capability editor, capability manager
5
  Requires at least: 3.5
6
- Tested up to: 3.9
7
- Stable tag: 0.3.1
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -20,6 +20,7 @@ You can create, edit or delete user roles and manage role capabilities.
20
  * Clone existing roles.
21
  * Manage capabilities.
22
  * Allows you to add role capabilities.
 
23
 
24
  Visit [WPFront User Role Editor](http://wpfront.com/user-role-editor-plugin/) page for screens and functionalities.
25
 
@@ -52,6 +53,10 @@ Visit [WPFront User Role Editor Settings](http://wpfront.com/user-role-editor-pl
52
 
53
  == Changelog ==
54
 
 
 
 
 
55
  = 0.3.1 =
56
  * Bug fixes
57
 
@@ -60,6 +65,9 @@ Visit [WPFront User Role Editor Settings](http://wpfront.com/user-role-editor-pl
60
 
61
  == Upgrade Notice ==
62
 
 
 
 
63
  = 0.3.1 =
64
  * Fixed an issue with deleting roles
65
 
3
  Donate link: http://wpfront.com/donate/
4
  Tags: user role editor, role editor, user role, role, user roles, roles, user roles editor, roles editor, role manager, roles manager, manage roles, manage role, access, capability, editor, permission, role, security, user, capability editor, capability manager
5
  Requires at least: 3.5
6
+ Tested up to: 3.9.1
7
+ Stable tag: 1.0
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
20
  * Clone existing roles.
21
  * Manage capabilities.
22
  * Allows you to add role capabilities.
23
+ * Change default user role.
24
 
25
  Visit [WPFront User Role Editor](http://wpfront.com/user-role-editor-plugin/) page for screens and functionalities.
26
 
53
 
54
  == Changelog ==
55
 
56
+ = 1.0 =
57
+ * Set new user default role
58
+ * Stability improvements
59
+
60
  = 0.3.1 =
61
  * Bug fixes
62
 
65
 
66
  == Upgrade Notice ==
67
 
68
+ = 1.0 =
69
+ * Easily set new user default role
70
+
71
  = 0.3.1 =
72
  * Fixed an issue with deleting roles
73
 
templates/add-edit-role.php CHANGED
@@ -29,397 +29,60 @@
29
  */
30
  ?>
31
 
32
- <?php
33
- $this->verify_nonce();
34
-
35
- $edit_role = null;
36
- $disabled = FALSE;
37
- if (!empty($_GET['edit_role'])) {
38
- $edit_role = get_role($_GET['edit_role']);
39
- if ($edit_role->name == 'administrator') {
40
- $disabled = TRUE;
41
- }
42
- }
43
-
44
- $valid_role_name = TRUE;
45
- $valid_display_name = TRUE;
46
- if (strtolower($_SERVER['REQUEST_METHOD']) === 'post' && !empty($_POST['createrole'])) {
47
- if ($edit_role == NULL) {
48
- if (empty($_POST['role_name'])) {
49
- $valid_role_name = FALSE;
50
- } else if (trim($_POST['role_name']) == '') {
51
- $valid_role_name = FALSE;
52
- }
53
- }
54
-
55
- if (empty($_POST['display_name'])) {
56
- $valid_display_name = FALSE;
57
- } else if (trim($_POST['display_name']) == '') {
58
- $valid_display_name = FALSE;
59
- }
60
- }
61
-
62
- $url = admin_url('admin.php');
63
-
64
- $capabilities = array(
65
- 'Dashboard' => array(
66
- 'read',
67
- 'edit_dashboard'
68
- ),
69
- 'Posts' => array(
70
- 'publish_posts',
71
- 'edit_posts',
72
- 'delete_posts',
73
- 'edit_published_posts',
74
- 'delete_published_posts',
75
- 'edit_others_posts',
76
- 'delete_others_posts',
77
- 'read_private_posts',
78
- 'edit_private_posts',
79
- 'delete_private_posts',
80
- 'manage_categories'
81
- ),
82
- 'Media' => array(
83
- 'upload_files',
84
- 'unfiltered_upload'
85
- ),
86
- 'Pages' => array(
87
- 'publish_pages',
88
- 'edit_pages',
89
- 'delete_pages',
90
- 'edit_published_pages',
91
- 'delete_published_pages',
92
- 'edit_others_pages',
93
- 'delete_others_pages',
94
- 'read_private_pages',
95
- 'edit_private_pages',
96
- 'delete_private_pages'
97
- ),
98
- 'Comments' => array(
99
- 'edit_comment',
100
- 'moderate_comments'
101
- ),
102
- 'Themes' => array(
103
- 'switch_themes',
104
- 'edit_theme_options',
105
- 'edit_themes',
106
- 'delete_themes',
107
- 'install_themes',
108
- 'update_themes'
109
- ),
110
- 'Plugins' => array(
111
- 'activate_plugins',
112
- 'edit_plugins',
113
- 'install_plugins',
114
- 'update_plugins',
115
- 'delete_plugins'
116
- ),
117
- 'Users' => array(
118
- 'list_users',
119
- 'create_users',
120
- 'edit_users',
121
- 'delete_users',
122
- 'promote_users',
123
- 'add_users',
124
- 'remove_users'
125
- ),
126
- 'Tools' => array(
127
- 'import',
128
- 'export'
129
- ),
130
- 'Admin' => array(
131
- 'manage_options',
132
- 'update_core',
133
- 'unfiltered_html'
134
- ),
135
- 'Links' => array(
136
- 'manage_links'
137
- ),
138
- 'Deprecated' => array(
139
- 'edit_files',
140
- 'level_0',
141
- 'level_1',
142
- 'level_2',
143
- 'level_3',
144
- 'level_4',
145
- 'level_5',
146
- 'level_6',
147
- 'level_7',
148
- 'level_8',
149
- 'level_9',
150
- 'level_10'
151
- )
152
- );
153
- if ($this->options->enable_role_capabilities()) {
154
- $capabilities['Roles (WPFront)'] = $this->role_caps;
155
- }
156
-
157
- global $wp_roles;
158
- $other_caps = array();
159
- foreach ($wp_roles->roles as $key => $role) {
160
- foreach ($role['capabilities'] as $cap => $value) {
161
- $found = FALSE;
162
- foreach ($capabilities as $s => $wcaps) {
163
- foreach ($wcaps as $wcap) {
164
- if ($wcap == $cap) {
165
- $found = TRUE;
166
- break;
167
- }
168
- }
169
- if ($found)
170
- break;
171
- }
172
- if (!$found) {
173
- $other_caps[] = $cap;
174
- }
175
- }
176
- }
177
-
178
- $other_caps = array_unique($other_caps);
179
- if (!empty($other_caps)) {
180
- $capabilities['Other Capabilities'] = $other_caps;
181
- }
182
-
183
- $role_error = FALSE;
184
- $role_exists = FALSE;
185
- $role_name = '';
186
- $display_name = '';
187
- $role_success = FALSE;
188
- $post_capabilities = array();
189
-
190
- if ($edit_role != NULL) {
191
- global $wp_roles;
192
- $role_name = $edit_role->name;
193
- $display_name = $wp_roles->role_names[$edit_role->name];
194
- $post_capabilities = $edit_role->capabilities;
195
- }
196
-
197
- if (strtolower($_SERVER['REQUEST_METHOD']) === 'post') {
198
- $post_capabilities = array();
199
- if (!empty($_POST['capabilities'])) {
200
- $post_capabilities = $_POST['capabilities'];
201
- foreach ($post_capabilities as $key => $value) {
202
- $post_capabilities[$key] = TRUE;
203
- }
204
- }
205
- if ($valid_role_name && $valid_display_name) {
206
- $display_name = trim($_POST['display_name']);
207
-
208
- if ($edit_role == NULL) {
209
- $role_name = trim($_POST['role_name']);
210
- $role_name = strtolower($role_name);
211
- $role_name = str_replace(' ', '_', $role_name);
212
- $role_name = preg_replace('/\W/', '', $role_name);
213
- if ($role_name == '')
214
- $valid_role_name = FALSE;
215
- }
216
- else {
217
- $role_name = $edit_role->name;
218
- }
219
- }
220
- if ($valid_role_name && $valid_display_name) {
221
- if ($edit_role == NULL & get_role($role_name) != NULL) {
222
- $role_exists = TRUE;
223
- } else {
224
- foreach ($post_capabilities as $pcap => $pvalue) {
225
- $found = FALSE;
226
- foreach ($capabilities as $group => $caps) {
227
- foreach ($caps as $cap) {
228
- if ($cap == $pcap) {
229
- $found = TRUE;
230
- break;
231
- }
232
- }
233
- if ($found)
234
- break;
235
- }
236
- if (!$found) {
237
- unset($post_capabilities[$pcap]);
238
- }
239
- }
240
-
241
- if ($edit_role == NULL) {
242
- $role_error = add_role($role_name, $display_name, $post_capabilities);
243
- if ($role_error == NULL) {
244
- $role_error = TRUE;
245
- } else {
246
- $role_error = FALSE;
247
- $role_success = TRUE;
248
- }
249
- } else {
250
- $caps = array();
251
- foreach ($post_capabilities as $cap => $value) {
252
- $caps[$cap] = TRUE;
253
- }
254
- global $wp_roles;
255
- $wp_roles->roles[$edit_role->name] = array(
256
- 'name' => $display_name,
257
- 'capabilities' => $caps
258
- );
259
- update_option($wp_roles->role_key, $wp_roles->roles);
260
- $wp_roles->role_objects[$edit_role->name] = new WP_Role($edit_role->name, $caps);
261
- $wp_roles->role_names[$edit_role->name] = $display_name;
262
- $role_success = TRUE;
263
- }
264
- }
265
- }
266
- }
267
-
268
- if ($role_success) {
269
- echo '<script>document.location = "' . admin_url('admin.php?page=' . self::PLUGIN_SLUG . '-all-roles') . '";</script>';
270
- exit();
271
- return;
272
- }
273
-
274
- function wpfront_user_role_editor_list_capabilities($self, $capabilities, $post_capabilities, $display_deprecated, $disabled) {
275
- ?>
276
- <div class="metabox-holder">
277
- <?php
278
- foreach ($capabilities as $group => $caps) {
279
- ?>
280
- <div class="postbox <?php echo $group == 'Deprecated' ? 'deprecated' : 'active'; ?> <?php echo $group == 'Deprecated' && !$display_deprecated ? 'hidden' : ''; ?>">
281
- <h3 class="hndle">
282
- <input type="checkbox" class="select-all" id="<?php echo str_replace(' ', '_', $group); ?>" <?php echo $disabled || $group == 'Deprecated' ? 'disabled' : ''; ?> />
283
- <label for="<?php echo str_replace(' ', '_', $group); ?>"><?php echo $self->__($group); ?></label>
284
- </h3>
285
- <div class="inside">
286
- <div class="main">
287
- <?php
288
- foreach ($caps as $cap) {
289
- ?>
290
- <div>
291
- <input type="checkbox" id="<?php echo $cap; ?>" name="capabilities[<?php echo $cap; ?>]" <?php echo array_key_exists($cap, $post_capabilities) ? 'checked' : ''; ?> <?php echo $disabled || $group == 'Deprecated' ? 'disabled' : ''; ?> />
292
- <label for="<?php echo $cap; ?>"><?php echo $cap; ?></label>
293
- </div>
294
- <?php
295
- }
296
- ?>
297
- </div>
298
- </div>
299
- </div>
300
- <?php
301
- }
302
- ?>
303
- </div>
304
- <?php
305
- }
306
- ?>
307
-
308
- <style type="text/css">
309
- div.role-add-new form#createuser table.sub-head {
310
- width: 100%;
311
- }
312
-
313
- div.role-add-new form#createuser table.sub-head th.sub-head {
314
- text-align: left;
315
- padding: 0px;
316
- }
317
-
318
- div.role-add-new form#createuser table.sub-head th.sub-head h3 {
319
- }
320
-
321
- div.role-add-new form#createuser table.sub-head td.sub-head-controls {
322
- text-align: right;
323
- padding: 0px;
324
- }
325
-
326
- div.role-add-new form#createuser table.sub-head td.sub-head-controls div {
327
- display: inline-block;
328
- vertical-align: top;
329
- }
330
-
331
- div.role-add-new form#createuser table.sub-head td.sub-head-controls div.spacer {
332
- width: 10px;
333
- height: 0px;
334
- }
335
-
336
- div.role-add-new form#createuser table.sub-head td.sub-head-controls input.select-all, div.role-add-new form#createuser table.sub-head td.sub-head-controls input.select-none {
337
- width: 100px;
338
- }
339
-
340
- div.role-add-new div.metabox-holder div.postbox {
341
- margin-bottom: 8px;
342
- }
343
-
344
- div.role-add-new div.metabox-holder div.postbox.deprecated {
345
- filter: alpha(opacity=80);
346
- opacity: 0.8;
347
- }
348
-
349
- div.role-add-new div.metabox-holder div.postbox h3.hndle {
350
- cursor: default;
351
- }
352
-
353
- div.role-add-new div.metabox-holder div.postbox div.inside div.main div {
354
- padding: 2px 0px;
355
- display: inline-block;
356
- width: 250px;
357
- }
358
-
359
- div.role-add-new div.metabox-holder div.postbox label {
360
- vertical-align: top;
361
- }
362
-
363
- div.role-add-new div.footer {
364
- text-align: center;
365
- }
366
- </style>
367
-
368
  <div class="wrap role-add-new">
369
  <h2 id="add-new-role">
370
- <?php echo $edit_role == NULL ? $this->__('Add New Role') : $this->__('Edit Role'); ?>
371
  <?php
372
- if ($edit_role != NULL && current_user_can($this->get_capability_string('create'))) {
373
- ?>
374
- <a href="<?php echo $url . '?page=' . self::PLUGIN_SLUG . '-add-new'; ?>" class="add-new-h2"><?php echo $this->__('Add New'); ?></a>
375
- <?php
376
  }
377
  ?>
378
  </h2>
379
- <?php
380
- if ($role_exists) {
381
- ?>
382
  <div class="error below-h2">
383
  <p>
384
  <strong><?php echo $this->__('ERROR'); ?></strong>: <?php echo $this->__('This role already exists in this site.'); ?>
385
  </p>
386
  </div>
387
- <?php
388
- } else if ($role_error) {
389
- ?>
390
  <div class="error below-h2">
391
  <p>
392
  <strong><?php echo $this->__('ERROR'); ?></strong>: <?php echo $this->__('There was an unexpected error while performing this action.'); ?>
393
  </p>
394
  </div>
395
- <?php
396
- }
397
- ?>
398
  <?php
399
- if ($edit_role == NULL) {
400
- ?>
401
- <p><?php echo $this->__('Create a brand new role and add it to this site.'); ?></p>
402
- <?php
403
  }
404
  ?>
 
405
  <form method="post" id="createuser" name="createuser" class="validate">
406
- <?php $this->create_nonce(); ?>
407
  <table class="form-table">
408
  <tbody>
409
- <tr class="form-field form-required <?php echo $valid_display_name ? '' : 'form-invalid' ?>">
410
- <th scope="row"><label for="display_name">
411
- <?php echo $this->__('Display Name'); ?> <span class="description">(<?php echo $this->__('required'); ?>)</span></label>
 
 
412
  </th>
413
  <td>
414
- <input name="display_name" type="text" id="display_name" value="<?php echo $display_name; ?>" aria-required="true" <?php echo $disabled ? 'disabled' : ''; ?> />
415
  </td>
416
  </tr>
417
- <tr class="form-field form-required <?php echo $valid_role_name ? '' : 'form-invalid' ?>">
418
- <th scope="row"><label for="role_name">
419
- <?php echo $this->__('Role Name'); ?> <span class="description">(<?php echo $this->__('required'); ?>)</span></label>
 
 
420
  </th>
421
  <td>
422
- <input name="role_name" type="text" id="role_name" value="<?php echo $role_name; ?>" aria-required="true" <?php echo $disabled || $edit_role != NULL ? 'disabled' : ''; ?> />
423
  </td>
424
  </tr>
425
  </tbody>
@@ -428,39 +91,70 @@ function wpfront_user_role_editor_list_capabilities($self, $capabilities, $post_
428
  <table class="form-table sub-head">
429
  <tbody>
430
  <tr>
431
- <th class="sub-head"><h3><?php echo $this->__('Capabilities'); ?></h3></th>
 
 
432
  <td class="sub-head-controls">
433
  <div>
434
- <select <?php echo $disabled ? 'disabled' : ''; ?>>
435
  <option value=""><?php echo $this->__('Copy from'); ?></option>
436
  <?php
437
- global $wp_roles;
438
- $names = $wp_roles->get_names();
439
- asort($names, SORT_STRING | SORT_FLAG_CASE);
440
- foreach ($names as $key => $value) {
441
- ?>
442
- <option value="<?php echo $key; ?>"><?php echo $value; ?></option>
443
- <?php
444
  }
445
  ?>
446
  </select>
447
- <input type="button" id="cap_apply" name="cap_apply" class="button action" value="<?php echo $this->__('Apply'); ?>" <?php echo $disabled ? 'disabled' : ''; ?> />
448
  </div>
449
  <div class="spacer"></div>
450
  <div>
451
- <input type="button" class="button action chk-helpers select-all" value="<?php echo $this->__('Select All'); ?>" <?php echo $disabled ? 'disabled' : ''; ?> />
452
- <input type="button" class="button action chk-helpers select-none" value="<?php echo $this->__('Select None'); ?>" <?php echo $disabled ? 'disabled' : ''; ?> />
453
  </div>
454
  </td>
455
  </tr>
456
  </tbody>
457
  </table>
458
- <?php wpfront_user_role_editor_list_capabilities($this, $capabilities, $post_capabilities, $this->options->display_deprecated(), $disabled); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
  <p class="submit">
460
- <input type="submit" name="createrole" id="createusersub" class="button button-primary" value="<?php echo $edit_role == NULL ? $this->__('Add New Role') : $this->__('Update Role'); ?>" <?php echo $disabled ? 'disabled' : ''; ?> />
461
  </p>
462
  </form>
463
- <div class="footer"><a target="_blank" href="http://wpfront.com/contact/">Feedback</a> | <a target="_blank" href="http://wpfront.com/">wpfront.com</a></div>
464
  </div>
465
 
466
  <script type="text/javascript">
@@ -493,7 +187,7 @@ function wpfront_user_role_editor_list_capabilities($self, $capabilities, $post_
493
  });
494
 
495
  <?php
496
- if ($edit_role == NULL) {
497
  ?>
498
  $("#display_name").keyup(function() {
499
  if ($.trim($(this).val()) == "")
29
  */
30
  ?>
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  <div class="wrap role-add-new">
33
  <h2 id="add-new-role">
 
34
  <?php
35
+ echo $this->role == NULL ? $this->__('Add New Role') : $this->__('Edit Role');
36
+ if ($this->role != NULL && $this->can_create()) {
37
+ printf('<a href="%s" class="add-new-h2">%s</a>', $this->add_new_url(), $this->__('Add New'));
 
38
  }
39
  ?>
40
  </h2>
41
+
42
+ <?php if ($this->is_role_exists()) { ?>
 
43
  <div class="error below-h2">
44
  <p>
45
  <strong><?php echo $this->__('ERROR'); ?></strong>: <?php echo $this->__('This role already exists in this site.'); ?>
46
  </p>
47
  </div>
48
+ <?php } ?>
49
+
50
+ <?php if ($this->is_error()) { ?>
51
  <div class="error below-h2">
52
  <p>
53
  <strong><?php echo $this->__('ERROR'); ?></strong>: <?php echo $this->__('There was an unexpected error while performing this action.'); ?>
54
  </p>
55
  </div>
56
+ <?php } ?>
57
+
 
58
  <?php
59
+ if ($this->role == NULL) {
60
+ printf('<p>%s</p>', $this->__('Create a brand new role and add it to this site.'));
 
 
61
  }
62
  ?>
63
+
64
  <form method="post" id="createuser" name="createuser" class="validate">
65
+ <?php $this->main->create_nonce(); ?>
66
  <table class="form-table">
67
  <tbody>
68
+ <tr class="form-field form-required <?php echo $this->is_display_name_valid() ? '' : 'form-invalid' ?>">
69
+ <th scope="row">
70
+ <label for="display_name">
71
+ <?php echo $this->__('Display Name'); ?> <span class="description">(<?php echo $this->__('required'); ?>)</span>
72
+ </label>
73
  </th>
74
  <td>
75
+ <input name="display_name" type="text" id="display_name" value="<?php echo $this->get_display_name(); ?>" aria-required="true" <?php echo $this->is_display_name_disabled() ? 'disabled' : ''; ?> />
76
  </td>
77
  </tr>
78
+ <tr class="form-field form-required <?php echo $this->is_role_name_valid() ? '' : 'form-invalid' ?>">
79
+ <th scope="row">
80
+ <label for="role_name">
81
+ <?php echo $this->__('Role Name'); ?> <span class="description">(<?php echo $this->__('required'); ?>)</span>
82
+ </label>
83
  </th>
84
  <td>
85
+ <input name="role_name" type="text" id="role_name" value="<?php echo $this->get_role_name(); ?>" aria-required="true" <?php echo $this->is_role_name_disabled() ? 'disabled' : ''; ?> />
86
  </td>
87
  </tr>
88
  </tbody>
91
  <table class="form-table sub-head">
92
  <tbody>
93
  <tr>
94
+ <th class="sub-head">
95
+ <h3> <?php echo $this->__('Capabilities'); ?></h3>
96
+ </th>
97
  <td class="sub-head-controls">
98
  <div>
99
+ <select <?php echo!$this->is_editable ? 'disabled' : ''; ?>>
100
  <option value=""><?php echo $this->__('Copy from'); ?></option>
101
  <?php
102
+ foreach ($this->get_copy_from() as $key => $value) {
103
+ printf('<option value="%s">%s</option>', $key, $value);
 
 
 
 
 
104
  }
105
  ?>
106
  </select>
107
+ <input type="button" id="cap_apply" name="cap_apply" class="button action" value="<?php echo $this->__('Apply'); ?>" <?php echo!$this->is_editable ? 'disabled' : ''; ?> />
108
  </div>
109
  <div class="spacer"></div>
110
  <div>
111
+ <input type="button" class="button action chk-helpers select-all" value="<?php echo $this->__('Select All'); ?>" <?php echo!$this->is_editable ? 'disabled' : ''; ?> />
112
+ <input type="button" class="button action chk-helpers select-none" value="<?php echo $this->__('Select None'); ?>" <?php echo!$this->is_editable ? 'disabled' : ''; ?> />
113
  </div>
114
  </td>
115
  </tr>
116
  </tbody>
117
  </table>
118
+
119
+ <div class="metabox-holder">
120
+ <?php
121
+ foreach ($this->get_capability_groups() as $key => $value) {
122
+ ?>
123
+ <div class="postbox <?php echo $value->deprecated ? 'deprecated' : 'active' ?> <?php echo $value->hidden ? 'hidden' : '' ?>">
124
+ <h3 class="hndle">
125
+ <input type="checkbox" class="select-all" id="<?php echo $value->key ?>" <?php echo $value->disabled ? 'disabled' : '' ?> />
126
+ <label for="<?php echo $value->key ?>"><?php echo $value->display_name; ?></label>
127
+ </h3>
128
+ <div class="inside">
129
+ <div class="main">
130
+ <?php
131
+ foreach ($value->caps as $cap) {
132
+ ?>
133
+ <div>
134
+ <input type="checkbox" id="<?php echo $cap; ?>" name="capabilities[<?php echo $cap; ?>]" <?php echo $value->disabled ? 'disabled' : '' ?> <?php echo $this->capability_checked($cap) ? 'checked' : '' ?> />
135
+ <label for="<?php echo $cap; ?>"><?php echo $cap; ?></label>
136
+ <?php if ($value->has_help) { ?>
137
+ <a target="_blank" href="<?php echo $this->get_help_url($cap); ?>">
138
+ <img class="help" src="<?php echo $this->image_url() . 'help.png'; ?>" />
139
+ </a>
140
+ <?php } ?>
141
+ </div>
142
+ <?php
143
+ }
144
+ ?>
145
+ </div>
146
+ </div>
147
+ </div>
148
+ <?php
149
+ }
150
+ ?>
151
+ </div>
152
+
153
  <p class="submit">
154
+ <input type="submit" name="createrole" id="createusersub" class="button button-primary" value="<?php echo $this->role == NULL ? $this->__('Add New Role') : $this->__('Update Role'); ?>" <?php echo $this->is_submit_disabled() ? 'disabled' : ''; ?> />
155
  </p>
156
  </form>
157
+ <?php $this->footer(); ?>
158
  </div>
159
 
160
  <script type="text/javascript">
187
  });
188
 
189
  <?php
190
+ if ($this->role == NULL) {
191
  ?>
192
  $("#display_name").keyup(function() {
193
  if ($.trim($(this).val()) == "")
templates/delete-role.php CHANGED
@@ -29,72 +29,34 @@
29
  */
30
  ?>
31
 
32
- <?php
33
- $this->verify_nonce();
34
- $url = admin_url('admin.php');
35
- $page_url = $url . '?page=' . self::PLUGIN_SLUG . '-all-roles';
36
-
37
- $delete_roles = $this->delete_roles;
38
-
39
- if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
40
- if (!empty($_POST['roles'])) {
41
- $delete_roles = $_POST['roles'];
42
- }
43
- }
44
-
45
- $status_messages = array();
46
 
47
- $editable_roles = get_editable_roles();
48
- global $user_ID;
49
- $user = new WP_User($user_ID);
50
- $current_roles = $user->roles;
51
-
52
- foreach ($delete_roles as $role) {
53
- if (!array_key_exists($role, $editable_roles)) {
54
- $status_messages[$role] = $this->__('This role cannot be deleted: Permission denied.');
55
- } else if ($role == 'administrator') {
56
- $status_messages[$role] = $this->__('\'administrator\' role cannot be deleted.');
57
- } else if (in_array($role, $current_roles)) {
58
- $status_messages[$role] = $this->__('Current user\'s role cannot be deleted.');
59
- }
60
- }
61
-
62
- if (!empty($_POST['confirm-delete'])) {
63
- foreach ($delete_roles as $role) {
64
- if (!array_key_exists($role, $status_messages)) {
65
- remove_role($role);
66
- }
67
- }
68
- echo '<script>document.location = "' . $page_url . '";</script>';
69
- exit();
70
- return;
71
- }
72
- ?>
73
 
74
  <div class="wrap delete-roles">
75
  <form method="post">
76
- <?php $this->create_nonce(); ?>
77
  <h2><?php echo $this->__('Delete Roles'); ?></h2>
78
  <p><?php echo $this->__('You have specified these roles for deletion'); ?>:</p>
79
  <ul>
80
  <?php
81
- global $wp_roles;
82
- foreach ($delete_roles as $role) {
83
  ?>
84
  <li>
85
- <?php echo $this->__('Role') . ': <strong>' . $role . '</strong> [<strong>' . $wp_roles->role_names[$role] . '</strong>] '; ?>
86
- <?php if (array_key_exists($role, $status_messages)) { ?>
87
- <strong> - <?php echo $status_messages[$role]; ?></strong>
88
- <?php } ?>
89
- <input type="hidden" name="roles[]" value="<?php echo $role; ?>" />
 
 
90
  </li>
91
  <?php
92
  }
93
  ?>
94
  </ul>
95
  <p class="submit">
96
- <input type="submit" name="confirm-delete" id="submit" class="button" value="Confirm Deletion" <?php echo count($delete_roles) == count($status_messages) ? 'disabled' : ''; ?>>
97
  </p>
98
  </form>
99
  </div>
100
 
 
29
  */
30
  ?>
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  <div class="wrap delete-roles">
35
  <form method="post">
36
+ <?php $this->main->create_nonce(); ?>
37
  <h2><?php echo $this->__('Delete Roles'); ?></h2>
38
  <p><?php echo $this->__('You have specified these roles for deletion'); ?>:</p>
39
  <ul>
40
  <?php
41
+ foreach ($this->get_deleting_roles() as $key => $value) {
 
42
  ?>
43
  <li>
44
+ <?php
45
+ printf('%s: <strong>%s</strong> [<strong>%s</strong>]', $this->__('Role'), $key, $value->display_name);
46
+ if($value->status_message != '') {
47
+ printf(' - <strong>%s</strong>', $value->status_message);
48
+ }
49
+ ?>
50
+ <input type="hidden" name="delete-roles[<?php echo $key; ?>]" value="1" />
51
  </li>
52
  <?php
53
  }
54
  ?>
55
  </ul>
56
  <p class="submit">
57
+ <input type="submit" name="confirm-delete" id="submit" class="button" value="<?php echo $this->__('Confirm Deletion'); ?>" <?php echo $this->is_submit_allowed() ? '' : 'disabled'; ?>>
58
  </p>
59
  </form>
60
  </div>
61
 
62
+
templates/list-roles.php CHANGED
@@ -29,260 +29,80 @@
29
  */
30
  ?>
31
 
32
- <?php
33
- $this->verify_nonce();
34
-
35
- function wpfront_user_role_editor_roles_table_header($self) {
36
- ?>
37
- <tr>
38
- <th scope="col" id="cb" class="manage-column column-cb check-column">
39
- <label class="screen-reader-text" for="cb-select-all-1"><?php echo $self->__('Select All'); ?></label>
40
- <input id="cb-select-all-1" type="checkbox" />
41
- </th>
42
- <th scope="col" id="rolename" class="manage-column column-rolename">
43
- <a><span><?php echo $self->__('Display Name'); ?></span></a>
44
- </th>
45
- <th scope="col" id="rolename" class="manage-column column-rolename">
46
- <a><span><?php echo $self->__('Role Name'); ?></span></a>
47
- </th>
48
- <th scope="col" id="roletype" class="manage-column column-roletype">
49
- <a><span><?php echo $self->__('Type'); ?></span></a>
50
- </th>
51
- <th scope="col" id="usercount" class="manage-column column-usercount num">
52
- <a><span><?php echo $self->__('Users'); ?></span></a>
53
- </th>
54
- <th scope="col" id="capscount" class="manage-column column-capscount num">
55
- <a><span><?php echo $self->__('Capabilities'); ?></span></a>
56
- </th>
57
- </tr>
58
- <?php
59
- }
60
-
61
- function wpfront_user_role_editor_roles_table_bulk_actions($self, $position, $role_data) {
62
- ?>
63
- <div class="tablenav <?php echo $position; ?>">
64
- <div class="alignleft actions bulkactions">
65
- <select name="action_<?php echo $position; ?>">
66
- <option value="-1" selected="selected"><?php echo $self->__('Bulk Actions'); ?></option>
67
- <?php if (current_user_can($self->get_capability_string('delete'))) { ?>
68
- <option value="delete"><?php echo $self->__('Delete'); ?></option>
69
- <?php } ?>
70
- </select>
71
- <input type="submit" name="doaction_<?php echo $position; ?>" class="button bulk action" value="<?php echo $self->__('Apply'); ?>">
72
- </div>
73
- <div class="tablenav-pages one-page"><span class="displaying-num"><?php echo sprintf($self->__('%s item(s)'), count($role_data)); ?></span>
74
- <br class="clear">
75
- </div>
76
- </div>
77
- <?php
78
- }
79
-
80
- $role_data = array();
81
- global $wp_roles;
82
- $roles = $wp_roles->role_names;
83
- asort($roles, SORT_STRING | SORT_FLAG_CASE);
84
- $builtin_count = 0;
85
- $custom_count = 0;
86
-
87
- foreach ($roles as $key => $value) {
88
- $role_data[$key] = array(
89
- 'role_name' => $key,
90
- 'display_name' => $value,
91
- 'role_type' => in_array($key, $this->builtin_roles) ? 'Built-In' : 'Custom',
92
- 'usercount' => count(get_users(array('role' => $key))),
93
- 'capscount' => count($wp_roles->roles[$key]['capabilities'])
94
- );
95
- if (in_array($key, $this->builtin_roles))
96
- $builtin_count++;
97
- else
98
- $custom_count++;
99
- }
100
-
101
- $url = admin_url('admin.php');
102
- $page_url = $url . '?page=' . self::PLUGIN_SLUG . '-all-roles';
103
-
104
- $list = 'all';
105
- if (!empty($_GET['list']))
106
- $list = $_GET['list'];
107
-
108
- switch ($list) {
109
- case 'all':
110
- case 'haveusers':
111
- case 'nousers':
112
- case 'builtin':
113
- case 'custom':
114
- break;
115
- default :
116
- $list = 'all';
117
- break;
118
- }
119
-
120
- $search = '';
121
- if (!empty($_POST['search']) && !empty($_POST['search-submit'])) {
122
- $search = trim($_POST['search']);
123
- }
124
- ?>
125
-
126
- <style type="text/css">
127
- div.wrap div.footer {
128
- text-align: center;
129
- }
130
- </style>
131
 
132
- <div class="wrap">
133
  <h2>
134
  <?php
135
  echo $this->__('Roles');
136
- if (current_user_can($this->get_capability_string('create'))) {
137
  ?>
138
- <a href="<?php echo $url . '?page=' . self::PLUGIN_SLUG . '-add-new'; ?>" class="add-new-h2"><?php echo $this->__('Add New'); ?></a>
139
  <?php
140
  }
141
- if ($search != '') {
142
- ?>
143
- <span class="subtitle"><?php echo sprintf($this->__('Search results for “%s”'), $search); ?> </span>
144
- <?php } ?>
145
  </h2>
146
- <ul class="subsubsub">
147
- <li class="all">
148
- <a href="<?php echo $page_url; ?>" class="<?php echo $list == 'all' ? 'current' : ''; ?>">
149
- <?php echo $this->__('All'); ?>
150
- <span class="count"><?php echo '(' . count($role_data) . ')'; ?></span>
151
- </a>
152
- |
153
- </li>
154
- <li class="haveusers">
155
- <a href="<?php echo $page_url . '&list=haveusers'; ?>" class="<?php echo $list == 'haveusers' ? 'current' : ''; ?>">
156
- <?php
157
- $count = 0;
158
- foreach ($role_data as $value) {
159
- if ($value['usercount'] > 0) {
160
- $count++;
161
- }
162
- }
163
- echo $this->__('Having Users');
164
- ?>
165
- <span class="count"><?php echo '(' . $count . ')'; ?></span>
166
- </a>
167
- |
168
- </li>
169
- <li class="nousers">
170
- <a href="<?php echo $page_url . '&list=nousers'; ?>" class="<?php echo $list == 'nousers' ? 'current' : ''; ?>">
171
- <?php echo $this->__('No Users'); ?>
172
- <span class="count"><?php echo '(' . (count($role_data) - $count) . ')'; ?></span>
173
 
174
- </a>
175
- |
176
- </li>
177
- <li class="built-in">
178
- <a href="<?php echo $page_url . '&list=builtin'; ?>" class="<?php echo $list == 'builtin' ? 'current' : ''; ?>">
179
- <?php echo $this->__('Built-In'); ?>
180
- <span class="count"><?php echo '(' . $builtin_count . ')'; ?></span>
181
- </a>
182
- |
183
- </li>
184
- <li class="custom">
185
- <a href="<?php echo $page_url . '&list=custom'; ?>" class="<?php echo $list == 'custom' ? 'current' : ''; ?>">
186
- <?php echo $this->__('Custom'); ?>
187
- <span class="count"><?php echo '(' . $custom_count . ')'; ?></span>
188
- </a>
189
  </li>
190
  </ul>
191
- <?php
192
- switch ($list) {
193
- case 'all':
194
- break;
195
- case 'haveusers':
196
- foreach ($role_data as $key => $value) {
197
- if ($value['usercount'] == 0)
198
- unset($role_data[$key]);
199
- }
200
- break;
201
- case 'nousers':
202
- foreach ($role_data as $key => $value) {
203
- if ($value['usercount'] > 0)
204
- unset($role_data[$key]);
205
- }
206
- break;
207
- case 'builtin':
208
- foreach ($role_data as $key => $value) {
209
- if ($value['role_type'] != 'Built-In')
210
- unset($role_data[$key]);
211
- }
212
- break;
213
- case 'custom':
214
- foreach ($role_data as $key => $value) {
215
- if ($value['role_type'] != 'Custom')
216
- unset($role_data[$key]);
217
- }
218
- break;
219
- default :
220
- $list = 'all';
221
- break;
222
- }
223
 
224
- if ($search != '') {
225
- foreach ($role_data as $key => $value) {
226
- if (strpos(strtolower($value['display_name']), strtolower($search)) === FALSE)
227
- unset($role_data[$key]);
228
- }
229
- }
230
- ?>
231
  <form method = "post">
232
- <?php $this->create_nonce(); ?>
233
  <p class = "search-box">
234
  <label class = "screen-reader-text" for = "role-search-input"><?php echo $this->__('Search Roles') . ':'; ?></label>
235
- <input type="search" id="role-search-input" name="search" value="<?php echo $search; ?>">
236
  <input type="submit" name="search-submit" id="search-submit" class="button" value="<?php echo $this->__('Search Roles'); ?>">
237
  </p>
238
- <?php wpfront_user_role_editor_roles_table_bulk_actions($this, 'top', $role_data) ?>
239
  <table class="wp-list-table widefat fixed users">
240
  <thead>
241
- <?php wpfront_user_role_editor_roles_table_header($this); ?>
242
  </thead>
243
  <tfoot>
244
- <?php wpfront_user_role_editor_roles_table_header($this); ?>
245
  </tfoot>
246
  <tbody id="the-list">
247
  <?php
248
  $index = 0;
249
- $editable_roles = get_editable_roles();
250
- foreach ($role_data as $key => $value) {
251
- $is_editable = array_key_exists($key, $editable_roles);
252
- if ($is_editable)
253
- $is_editable = $key != 'administrator';
254
  ?>
255
  <tr id="<?php echo $key; ?>" class="<?php echo $index % 2 == 0 ? 'alternate' : ''; ?>">
256
  <th scope="row" class="check-column">
257
  <label class="screen-reader-text" for="cb-select-<?php echo $key; ?>"><?php echo sprintf('Select %s', $value['display_name']) ?></label>
258
- <input type="checkbox" name="cb-select-<?php echo $key; ?>" id="cb-select-<?php echo $key; ?>" />
259
  </th>
260
  <td class="displayname column-displayname">
261
  <strong>
262
- <?php if (current_user_can($this->get_capability_string('edit'))) { ?>
263
- <a href="<?php echo $page_url . '&edit_role=' . $key ?>"><?php echo $value['display_name']; ?></a>
264
- <?php
265
- } else {
266
  echo $value['display_name'];
267
- }
 
268
  ?>
269
  </strong>
270
  <br />
271
  <div class="row-actions">
272
  <?php
273
  $links = array();
274
- if (current_user_can($this->get_capability_string('edit'))) {
275
- $links[] = '<span class="edit">
276
- <a href="' . $page_url . '&edit_role=' . $key . '">' . ($is_editable ? $this->__('Edit') : $this->__('View')) . '</a>
277
- </span>';
278
  }
279
-
280
- if ($is_editable && current_user_can($this->get_capability_string('delete'))) {
281
- $links[] = '<span class="delete">
282
- <a href="' . $page_url . '&delete_role=' . $key . '">' . $this->__('Delete') . '</a>
283
- </span>';
284
  }
285
-
286
  echo implode('|', $links);
287
  ?>
288
  </div>
@@ -291,13 +111,20 @@ if (!empty($_POST['search']) && !empty($_POST['search-submit'])) {
291
  <?php echo $key; ?>
292
  </td>
293
  <td class="roletype column-roletype">
294
- <?php echo $this->__($value['role_type']); ?>
 
 
 
 
 
 
 
295
  </td>
296
  <td class="usercount column-usercount num">
297
- <?php echo $value['usercount']; ?>
298
  </td>
299
  <td class="capscount column-capscount num">
300
- <?php echo $value['capscount']; ?>
301
  </td>
302
  </tr>
303
  <?php
@@ -306,16 +133,7 @@ if (!empty($_POST['search']) && !empty($_POST['search-submit'])) {
306
  ?>
307
  </tbody>
308
  </table>
309
- <?php wpfront_user_role_editor_roles_table_bulk_actions($this, 'bottom', $role_data) ?>
310
  </form>
311
- <div class="footer"><a target="_blank" href="http://wpfront.com/contact/">Feedback</a> | <a target="_blank" href="http://wpfront.com/">wpfront.com</a></div>
312
- </div>
313
-
314
- <script type="text/javascript">
315
- (function($) {
316
- $("input.button.bulk.action").click(function() {
317
- if ($(this).prev().val() == -1)
318
- return false;
319
- });
320
- })(jQuery);
321
- </script>
29
  */
30
  ?>
31
 
32
+ <?php $this->main->verify_nonce(); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ <div class="wrap list-roles">
35
  <h2>
36
  <?php
37
  echo $this->__('Roles');
38
+ if ($this->can_create()) {
39
  ?>
40
+ <a href="<?php echo $this->add_new_url(); ?>" class="add-new-h2"><?php echo $this->__('Add New'); ?></a>
41
  <?php
42
  }
43
+ ?>
 
 
 
44
  </h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
+ <ul class="subsubsub">
47
+ <li>
48
+ <?php
49
+ $filter_data = array();
50
+ $current_filter = $this->get_current_list_filter();
51
+ foreach ($this->get_list_filters() as $key => $value) {
52
+ $filter_data[] = sprintf('<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', $value['url'], ($current_filter == $key ? 'current' : ''), $value['display'], $value['count']);
53
+ }
54
+ echo implode('|</li><li>', $filter_data);
55
+ ?>
 
 
 
 
 
56
  </li>
57
  </ul>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
 
 
 
 
 
 
 
59
  <form method = "post">
60
+ <?php $this->main->create_nonce(); ?>
61
  <p class = "search-box">
62
  <label class = "screen-reader-text" for = "role-search-input"><?php echo $this->__('Search Roles') . ':'; ?></label>
63
+ <input type="search" id="role-search-input" name="search" value="<?php echo $this->get_search_term(); ?>">
64
  <input type="submit" name="search-submit" id="search-submit" class="button" value="<?php echo $this->__('Search Roles'); ?>">
65
  </p>
66
+ <?php $this->bulk_actions('top'); ?>
67
  <table class="wp-list-table widefat fixed users">
68
  <thead>
69
+ <?php $this->table_header(); ?>
70
  </thead>
71
  <tfoot>
72
+ <?php $this->table_header(); ?>
73
  </tfoot>
74
  <tbody id="the-list">
75
  <?php
76
  $index = 0;
77
+ foreach ($this->get_roles() as $key => $value) {
 
 
 
 
78
  ?>
79
  <tr id="<?php echo $key; ?>" class="<?php echo $index % 2 == 0 ? 'alternate' : ''; ?>">
80
  <th scope="row" class="check-column">
81
  <label class="screen-reader-text" for="cb-select-<?php echo $key; ?>"><?php echo sprintf('Select %s', $value['display_name']) ?></label>
82
+ <input type="checkbox" name="selected-roles[<?php echo $key; ?>]" id="cb-select-<?php echo $key; ?>" />
83
  </th>
84
  <td class="displayname column-displayname">
85
  <strong>
86
+ <?php
87
+ if (empty($value['edit_url']))
 
 
88
  echo $value['display_name'];
89
+ else
90
+ printf('<a href="%s">%s</a>', $value['edit_url'], $value['display_name']);
91
  ?>
92
  </strong>
93
  <br />
94
  <div class="row-actions">
95
  <?php
96
  $links = array();
97
+ if ($this->can_edit()) {
98
+ $links[] = sprintf('<span class="edit"><a href="%s">%s</a></span>', $value['edit_url'], ($value['is_editable'] ? $this->__('Edit') : $this->__('View')));
 
 
99
  }
100
+ if ($this->can_delete() && $value['is_deletable']) {
101
+ $links[] = sprintf('<span class="delete"><a href="%s">%s</a></span>', $value['delete_url'], $this->__('Delete'));
102
+ }
103
+ if(!empty($value['set_default_url'])) {
104
+ $links[] = sprintf('<span class="set-default"><a href="%s">%s</a></span>', $value['set_default_url'], $this->__('Default'));
105
  }
 
106
  echo implode('|', $links);
107
  ?>
108
  </div>
111
  <?php echo $key; ?>
112
  </td>
113
  <td class="roletype column-roletype">
114
+ <?php echo $value['is_default'] ? $this->__('Built-In') : $this->__('Custom'); ?>
115
+ </td>
116
+ <td class="userdefault column-userdefault num">
117
+ <?php
118
+ if ($value['user_default']) {
119
+ printf('<img class="user-default" src="%s" />', $this->image_url() . 'check-icon.png');
120
+ }
121
+ ?>
122
  </td>
123
  <td class="usercount column-usercount num">
124
+ <?php echo $value['user_count']; ?>
125
  </td>
126
  <td class="capscount column-capscount num">
127
+ <?php echo $value['caps_count']; ?>
128
  </td>
129
  </tr>
130
  <?php
133
  ?>
134
  </tbody>
135
  </table>
136
+ <?php $this->bulk_actions('bottom'); ?>
137
  </form>
138
+ <?php $this->footer(); ?>
139
+ </div>
 
 
 
 
 
 
 
 
 
wpfront-user-role-editor.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WPFront User Role Editor
4
  * Plugin URI: http://wpfront.com/user-role-editor-plugin/
5
  * Description: Allows you to manage user roles.
6
- * Version: 0.3.1
7
  * Author: Syam Mohan
8
  * Author URI: http://wpfront.com
9
  * License: GPL v3
3
  * Plugin Name: WPFront User Role Editor
4
  * Plugin URI: http://wpfront.com/user-role-editor-plugin/
5
  * Description: Allows you to manage user roles.
6
+ * Version: 1.0
7
  * Author: Syam Mohan
8
  * Author URI: http://wpfront.com
9
  * License: GPL v3