User Role Editor - Version 4.23

Version Description

Download this release

Release Info

Developer shinephp
Plugin Icon 128x128 User Role Editor
Version 4.23
Comparing to
See all releases

Code changes from version 4.22 to 4.23

includes/class-garvs-wp-lib.php DELETED
@@ -1,242 +0,0 @@
1
- <?php
2
- /*
3
- * General stuff for usage at WordPress plugins
4
- * Author: Vladimir Garagulya
5
- * Author email: vladimir@shinephp.com
6
- * Author URI: http://shinephp.com
7
- *
8
- */
9
-
10
-
11
- /**
12
- * This class contains general stuff for usage at WordPress plugins
13
- */
14
- class Garvs_WP_Lib {
15
-
16
- private static $instance = null; // object exemplar reference
17
- protected $options_id = ''; // identifire to save/retrieve plugin options to/from wp_option DB table
18
- protected $options = array(); // plugin options data
19
- public $multisite = false;
20
- public $active_for_network = false;
21
- public $blog_ids = null;
22
- protected $main_blog_id = 0;
23
- public $log_to_file = false; // set to true in order to record data about critical actions to log file
24
- private $log_file_name = ''; // file name to write log messages
25
-
26
- /**
27
- * class constructor
28
- * @param string $option_name identifire to save/retrieve plugin options to/from wp_option DB table
29
- */
30
- public function __construct($options_id) {
31
-
32
- $this->multisite = function_exists('is_multisite') && is_multisite();
33
- if ($this->multisite) {
34
- $this->blog_ids = $this->get_blog_ids();
35
- // get Id of 1st (main) blog
36
- $this->main_blog_id = $this->blog_ids[0][0];
37
- }
38
-
39
- $this->init_options($options_id);
40
-
41
- //add_action('admin_notices', array(&$this, 'show_message')); // TODO: use WordPress notifications instead of my own
42
- }
43
- // end of __construct()
44
-
45
-
46
- /**
47
- * Returns the array of multisite WP blogs IDs
48
- * @global wpdb $wpdb
49
- * @return array
50
- */
51
- protected function get_blog_ids() {
52
- global $wpdb;
53
-
54
- $blog_ids = $wpdb->get_col("select blog_id from $wpdb->blogs order by blog_id asc");
55
-
56
- return $blog_ids;
57
- }
58
- // end of get_blog_ids()
59
-
60
-
61
- /**
62
- * get current options for this plugin
63
- */
64
- protected function init_options($options_id) {
65
- $this->options_id = $options_id;
66
- $this->options = get_option($options_id);
67
- }
68
- // end of init_options()
69
-
70
- /**
71
- * Return HTML formatted message
72
- *
73
- * @param string $message message text
74
- * @param string $error_style message div CSS style
75
- */
76
- public function show_message($message, $error_style=false) {
77
-
78
- if ($message) {
79
- if ($error_style) {
80
- echo '<div id="message" class="error" >';
81
- } else {
82
- echo '<div id="message" class="updated fade">';
83
- }
84
- echo $message . '</div>';
85
- }
86
-
87
- }
88
- // end of show_message()
89
-
90
-
91
- /**
92
- * Returns value by name from GET/POST/REQUEST. Minimal type checking is provided
93
- *
94
- * @param string $var_name Variable name to return
95
- * @param string $request_type type of request to process get/post/request (default)
96
- * @param string $var_type variable type to provide value checking
97
- * @return mix variable value from request
98
- */
99
- public function get_request_var($var_name, $request_type='request', $var_type='string') {
100
-
101
- $result = 0;
102
- if ($request_type == 'get') {
103
- if (isset($_GET[$var_name])) {
104
- $result = $_GET[$var_name];
105
- }
106
- } else if ($request_type == 'post') {
107
- if (isset($_POST[$var_name])) {
108
- if ($var_type!='checkbox') {
109
- $result = $_POST[$var_name];
110
- } else {
111
- $result = 1;
112
- }
113
- }
114
- } else {
115
- if (isset($_REQUEST[$var_name])) {
116
- $result = $_REQUEST[$var_name];
117
- }
118
- }
119
-
120
- if ($result) {
121
- if ($var_type == 'int' && !is_numeric($result)) {
122
- $result = 0;
123
- }
124
- if ($var_type!='int') {
125
- $result = esc_attr($result);
126
- }
127
- }
128
-
129
- return $result;
130
- }
131
- // end of get_request_var()
132
-
133
-
134
- /**
135
- * returns option value for option with name in $option_name
136
- */
137
- public function get_option($option_name, $default = false) {
138
-
139
- if ( isset( $this->options[ $option_name ] ) ) {
140
- return $this->options[$option_name];
141
- } else {
142
- return $default;
143
- }
144
-
145
- }
146
- // end of get_option()
147
-
148
-
149
- /**
150
- * puts option value according to $option_name option name into options array property
151
- */
152
- public function put_option($option_name, $option_value, $flush_options=false) {
153
-
154
- $this->options[$option_name] = $option_value;
155
- if ($flush_options) {
156
- $this->flush_options();
157
- }
158
-
159
- }
160
- // end of put_option()
161
-
162
-
163
- /**
164
- * Delete URE option with name option_name
165
- * @param string $option_name
166
- * @param bool $flush_options
167
- */
168
- public function delete_option($option_name, $flush_options=false) {
169
- if (array_key_exists($option_name, $this->options)) {
170
- unset($this->options[$option_name]);
171
- if ($flush_options) {
172
- $this->flush_options();
173
- }
174
- }
175
-
176
- }
177
- // end of delete_option()
178
-
179
-
180
- /**
181
- * saves options array into WordPress database wp_options table
182
- */
183
- public function flush_options() {
184
-
185
- update_option($this->options_id, $this->options);
186
-
187
- }
188
- // end of flush_options()
189
-
190
-
191
- /**
192
- * Check product versrion and stop execution if product version is not compatible
193
- * @param type $must_have_version
194
- * @param type $version_to_check
195
- * @param type $error_message
196
- * @return type
197
- */
198
- public static function check_version($must_have_version, $version_to_check, $error_message, $plugin_file_name) {
199
-
200
- if (version_compare( $must_have_version, $version_to_check, '<' ) ) {
201
- if ( is_admin() && ( !defined('DOING_AJAX') || !DOING_AJAX ) ) {
202
- require_once ABSPATH . '/wp-admin/includes/plugin.php';
203
- deactivate_plugins( $plugin_file_name );
204
- wp_die( $error_message );
205
- } else {
206
- return;
207
- }
208
- }
209
- }
210
- // end of check_version()
211
-
212
-
213
- /**
214
- * returns 'selected' HTML cluster if $value matches to $etalon
215
- *
216
- * @param string $value
217
- * @param string $etalon
218
- * @return string
219
- */
220
- public function option_selected($value, $etalon) {
221
- $selected = '';
222
- if (strcasecmp($value, $etalon) == 0) {
223
- $selected = 'selected="selected"';
224
- }
225
-
226
- return $selected;
227
- }
228
- // end of option_selected()
229
-
230
-
231
- public function get_current_url() {
232
- global $wp;
233
- $current_url = esc_url_raw(add_query_arg($wp->query_string, '', home_url($wp->request )));
234
-
235
- return $current_url;
236
- }
237
- // end of get_current_url()
238
-
239
-
240
- //
241
- }
242
- // end of Garvs_WP_Lib class
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-user-role-editor.php CHANGED
@@ -26,9 +26,9 @@ class User_Role_Editor {
26
  /**
27
  * class constructor
28
  */
29
- function __construct($library) {
30
 
31
- $this->lib = $library;
32
  $this->user_other_roles = new URE_User_Other_Roles($this->lib);
33
 
34
  if ($this->lib->is_pro()) {
@@ -45,7 +45,18 @@ class User_Role_Editor {
45
 
46
  // Who can use this plugin
47
  $this->key_capability = $this->lib->get_key_capability();
 
 
 
 
 
 
48
 
 
 
 
 
 
49
  if ($this->lib->multisite) {
50
  // new blog may be registered not at admin back-end only but automatically after new user registration, e.g.
51
  // Gravity Forms User Registration Addon does
@@ -76,10 +87,9 @@ class User_Role_Editor {
76
  // add a Settings link in the installed plugins page
77
  add_filter('plugin_action_links_'. URE_PLUGIN_BASE_NAME, array($this, 'plugin_action_links'), 10, 1);
78
  add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2);
79
-
80
  }
81
- // end of __construct()
82
-
83
 
84
  /**
85
  * True - if it's an instance of Pro version, false - for free version
@@ -716,34 +726,21 @@ class User_Role_Editor {
716
  }
717
  // end of edit_roles()
718
 
719
-
720
- // move old version option to the new storage 'user_role_editor' option, array, containing all URE options
721
- private function convert_option($option_name) {
722
-
723
- $option_value = get_option($option_name, 0);
724
- delete_option($option_name);
725
- $this->lib->put_option( $option_name, $option_value );
726
-
727
- }
728
 
729
  /**
730
  * execute on plugin activation
731
  */
732
  function setup() {
733
 
734
- $this->convert_option('ure_caps_readable');
735
- $this->convert_option('ure_show_deprecated_caps');
736
- $this->convert_option('ure_hide_pro_banner');
737
- $this->lib->flush_options();
738
-
739
  $this->lib->make_roles_backup();
740
  $this->lib->init_ure_caps();
741
-
742
-
743
- do_action('ure_activation');
 
744
  }
745
  // end of setup()
746
-
747
 
748
  /**
749
  * Load plugin javascript stuff
26
  /**
27
  * class constructor
28
  */
29
+ public function __construct() {
30
 
31
+ $this->lib = Ure_Lib::get_instance();
32
  $this->user_other_roles = new URE_User_Other_Roles($this->lib);
33
 
34
  if ($this->lib->is_pro()) {
45
 
46
  // Who can use this plugin
47
  $this->key_capability = $this->lib->get_key_capability();
48
+
49
+ // Process URE's internal tasks queue
50
+ $task_queue = URE_Task_Queue::get_instance();
51
+ $task_queue->process();
52
+
53
+ $this->set_hooks();
54
 
55
+ }
56
+ // end of __construct()
57
+
58
+
59
+ private function set_hooks() {
60
  if ($this->lib->multisite) {
61
  // new blog may be registered not at admin back-end only but automatically after new user registration, e.g.
62
  // Gravity Forms User Registration Addon does
87
  // add a Settings link in the installed plugins page
88
  add_filter('plugin_action_links_'. URE_PLUGIN_BASE_NAME, array($this, 'plugin_action_links'), 10, 1);
89
  add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2);
 
90
  }
91
+ // end of set_hooks()
92
+
93
 
94
  /**
95
  * True - if it's an instance of Pro version, false - for free version
726
  }
727
  // end of edit_roles()
728
 
 
 
 
 
 
 
 
 
 
729
 
730
  /**
731
  * execute on plugin activation
732
  */
733
  function setup() {
734
 
 
 
 
 
 
735
  $this->lib->make_roles_backup();
736
  $this->lib->init_ure_caps();
737
+
738
+ $task_queue = URE_Task_Queue::get_instance();
739
+ $task_queue->add('on_activation');
740
+
741
  }
742
  // end of setup()
743
+
744
 
745
  /**
746
  * Load plugin javascript stuff
includes/classes/base-lib.php ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * General stuff for usage at WordPress plugins
5
+ * Author: Vladimir Garagulya
6
+ * Author email: vladimir@shinephp.com
7
+ * Author URI: http://shinephp.com
8
+ *
9
+ */
10
+
11
+ /**
12
+ * This class contains general stuff for usage at WordPress plugins
13
+ */
14
+ class URE_Base_Lib {
15
+
16
+ private static $instance = null; // object exemplar reference
17
+ protected $options_id = ''; // identifire to save/retrieve plugin options to/from wp_option DB table
18
+ protected $options = array(); // plugin options data
19
+ public $multisite = false;
20
+ public $active_for_network = false;
21
+ public $blog_ids = null;
22
+ protected $main_blog_id = 0;
23
+
24
+
25
+ public static function get_instance($options_id = '') {
26
+
27
+ $class = get_called_class();
28
+ if (self::$instance === null) {
29
+ if (empty($options_id)) {
30
+ throw new Exception($class . '::get_inctance() - Error: plugin options ID string is required');
31
+ }
32
+ // new static() will work too
33
+ self::$instance = new $class($options_id);
34
+ }
35
+
36
+ return self::$instance;
37
+ }
38
+ // end of get_instance()
39
+
40
+
41
+ /**
42
+ * class constructor
43
+ * @param string $option_name identifire to save/retrieve plugin options to/from wp_option DB table
44
+ */
45
+ protected function __construct($options_id) {
46
+
47
+ $this->multisite = function_exists('is_multisite') && is_multisite();
48
+ if ($this->multisite) {
49
+ $this->blog_ids = $this->get_blog_ids();
50
+ // get Id of 1st (main) blog
51
+ $this->main_blog_id = $this->blog_ids[0][0];
52
+ }
53
+
54
+ $this->init_options($options_id);
55
+
56
+ }
57
+ // end of __construct()
58
+
59
+
60
+ /**
61
+ * Returns the array of multisite WP blogs IDs
62
+ * @global wpdb $wpdb
63
+ * @return array
64
+ */
65
+ protected function get_blog_ids() {
66
+ global $wpdb;
67
+
68
+ $blog_ids = $wpdb->get_col("select blog_id from $wpdb->blogs order by blog_id asc");
69
+
70
+ return $blog_ids;
71
+ }
72
+ // end of get_blog_ids()
73
+
74
+
75
+ /**
76
+ * get current options for this plugin
77
+ */
78
+ protected function init_options($options_id) {
79
+ $this->options_id = $options_id;
80
+ $this->options = get_option($options_id);
81
+ }
82
+ // end of init_options()
83
+
84
+ /**
85
+ * Return HTML formatted message
86
+ *
87
+ * @param string $message message text
88
+ * @param string $error_style message div CSS style
89
+ */
90
+ public function show_message($message, $error_style = false) {
91
+
92
+ if ($message) {
93
+ if ($error_style) {
94
+ echo '<div id="message" class="error" >';
95
+ } else {
96
+ echo '<div id="message" class="updated fade">';
97
+ }
98
+ echo $message . '</div>';
99
+ }
100
+ }
101
+ // end of show_message()
102
+
103
+ /**
104
+ * Returns value by name from GET/POST/REQUEST. Minimal type checking is provided
105
+ *
106
+ * @param string $var_name Variable name to return
107
+ * @param string $request_type type of request to process get/post/request (default)
108
+ * @param string $var_type variable type to provide value checking
109
+ * @return mix variable value from request
110
+ */
111
+ public function get_request_var($var_name, $request_type = 'request', $var_type = 'string') {
112
+
113
+ $result = 0;
114
+ if ($request_type == 'get') {
115
+ if (isset($_GET[$var_name])) {
116
+ $result = $_GET[$var_name];
117
+ }
118
+ } else if ($request_type == 'post') {
119
+ if (isset($_POST[$var_name])) {
120
+ if ($var_type != 'checkbox') {
121
+ $result = $_POST[$var_name];
122
+ } else {
123
+ $result = 1;
124
+ }
125
+ }
126
+ } else {
127
+ if (isset($_REQUEST[$var_name])) {
128
+ $result = $_REQUEST[$var_name];
129
+ }
130
+ }
131
+
132
+ if ($result) {
133
+ if ($var_type == 'int' && !is_numeric($result)) {
134
+ $result = 0;
135
+ }
136
+ if ($var_type != 'int') {
137
+ $result = esc_attr($result);
138
+ }
139
+ }
140
+
141
+ return $result;
142
+ }
143
+ // end of get_request_var()
144
+
145
+ /**
146
+ * returns option value for option with name in $option_name
147
+ */
148
+ public function get_option($option_name, $default = false) {
149
+
150
+ if (isset($this->options[$option_name])) {
151
+ return $this->options[$option_name];
152
+ } else {
153
+ return $default;
154
+ }
155
+ }
156
+ // end of get_option()
157
+
158
+ /**
159
+ * puts option value according to $option_name option name into options array property
160
+ */
161
+ public function put_option($option_name, $option_value, $flush_options = false) {
162
+
163
+ $this->options[$option_name] = $option_value;
164
+ if ($flush_options) {
165
+ $this->flush_options();
166
+ }
167
+ }
168
+ // end of put_option()
169
+
170
+ /**
171
+ * Delete URE option with name option_name
172
+ * @param string $option_name
173
+ * @param bool $flush_options
174
+ */
175
+ public function delete_option($option_name, $flush_options = false) {
176
+ if (array_key_exists($option_name, $this->options)) {
177
+ unset($this->options[$option_name]);
178
+ if ($flush_options) {
179
+ $this->flush_options();
180
+ }
181
+ }
182
+ }
183
+ // end of delete_option()
184
+
185
+ /**
186
+ * saves options array into WordPress database wp_options table
187
+ */
188
+ public function flush_options() {
189
+
190
+ update_option($this->options_id, $this->options);
191
+ }
192
+ // end of flush_options()
193
+
194
+ /**
195
+ * Check product versrion and stop execution if product version is not compatible
196
+ * @param type $must_have_version
197
+ * @param type $version_to_check
198
+ * @param type $error_message
199
+ * @return type
200
+ */
201
+ public static function check_version($must_have_version, $version_to_check, $error_message, $plugin_file_name) {
202
+
203
+ if (version_compare($must_have_version, $version_to_check, '<')) {
204
+ if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX )) {
205
+ require_once ABSPATH . '/wp-admin/includes/plugin.php';
206
+ deactivate_plugins($plugin_file_name);
207
+ wp_die($error_message);
208
+ } else {
209
+ return;
210
+ }
211
+ }
212
+ }
213
+ // end of check_version()
214
+
215
+ /**
216
+ * returns 'selected' HTML cluster if $value matches to $etalon
217
+ *
218
+ * @param string $value
219
+ * @param string $etalon
220
+ * @return string
221
+ */
222
+ public function option_selected($value, $etalon) {
223
+ $selected = '';
224
+ if (strcasecmp($value, $etalon) == 0) {
225
+ $selected = 'selected="selected"';
226
+ }
227
+
228
+ return $selected;
229
+ }
230
+ // end of option_selected()
231
+
232
+
233
+ public function get_current_url() {
234
+ global $wp;
235
+ $current_url = esc_url_raw(add_query_arg($wp->query_string, '', home_url($wp->request)));
236
+
237
+ return $current_url;
238
+ }
239
+ // end of get_current_url()
240
+
241
+
242
+ /**
243
+ * Private clone method to prevent cloning of the instance of the
244
+ * *Singleton* instance.
245
+ *
246
+ * @return void
247
+ */
248
+ private function __clone() {
249
+
250
+ }
251
+ // end of __clone()
252
+
253
+ /**
254
+ * Private unserialize method to prevent unserializing of the *Singleton*
255
+ * instance.
256
+ *
257
+ * @return void
258
+ */
259
+ private function __wakeup() {
260
+
261
+ }
262
+ // end of __wakeup()
263
+
264
+ }
265
+ // end of Garvs_WP_Lib class
includes/classes/task-queue.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * User Role Editor Pro WordPress plugin
4
+ * Author: Vladimir Garagulya
5
+ * Author email: support@role-editor.com
6
+ * Author URI: https://www.role-editor.com
7
+ * License: GPL v3
8
+ *
9
+ */
10
+
11
+ /*
12
+ * User Role Editor's internal tasks queue
13
+ * Usage: on URE plugin activation URE adds 'on_activation' task to this queue, which fires 'ure_on_activation' action
14
+ * on the next WordPress call. It's useful when some action is needed unavailable at standard plugin activation point,
15
+ * like 'admin_menu', which is used for the admin menu access data conversion - class URE_Admin_Menu_Hashes.
16
+ * Class User_Role_Editor_Pro adds execute_once method for the 'ure_on_activation' action, where
17
+ * URE_Admin_Menu_Hashes::require_data_conversion(); method is called which registers tasks for data coversion, including
18
+ * individual tasks for every site of the multisite network
19
+ *
20
+ */
21
+ class URE_Task_Queue {
22
+
23
+ private static $instance = null; // object exemplar reference according to singleton patern
24
+ const OPTION_NAME = 'ure_tasks_queue';
25
+ private $queue = null;
26
+
27
+
28
+ public static function get_instance() {
29
+
30
+ $class = get_called_class();
31
+ if (self::$instance===null) {
32
+ // new static() will work too
33
+ self::$instance = new $class();
34
+ }
35
+
36
+ return self::$instance;
37
+
38
+ }
39
+ // end of get_instance()
40
+
41
+
42
+ protected function __construct() {
43
+
44
+ $this->init();
45
+
46
+ }
47
+ // end of __construct()
48
+
49
+
50
+ private function init() {
51
+
52
+ $this->queue = get_option(self::OPTION_NAME, array());
53
+
54
+ }
55
+ // end of init()
56
+
57
+
58
+ public function reinit() {
59
+
60
+ $this->init();
61
+
62
+ }
63
+ // end of reinit()
64
+
65
+
66
+ /**
67
+ *
68
+ * @param string $task_id
69
+ * @param array $args=array('action'=>'action_name', 'routine'=>'routine_name', 'priority'=>99)
70
+ */
71
+ public function add($task_id, $args=array()) {
72
+
73
+ $this->queue[$task_id] = $args;
74
+ update_option(self::OPTION_NAME, $this->queue);
75
+
76
+ }
77
+ // end of add_task()
78
+
79
+
80
+ public function remove($task_id) {
81
+
82
+ if (isset($this->queue[$task_id])) {
83
+ unset($this->queue[$task_id]);
84
+ update_option(self::OPTION_NAME, $this->queue);
85
+ }
86
+ }
87
+ // end of remove_task()
88
+
89
+
90
+ /**
91
+ * Returns true in case a queue is empty
92
+ *
93
+ * @return boolean
94
+ */
95
+ public function is_empty() {
96
+
97
+ return count($this->queue)==0;
98
+ }
99
+ // end of is_empty()
100
+
101
+
102
+ /**
103
+ * Consumers should add there tasks with add_method and add 'ure_fulfil_task' action routine to work on it.
104
+ * Do not forget remove task after it was fulfilled.
105
+ *
106
+ * @return void
107
+ */
108
+
109
+ public function process() {
110
+
111
+ if ($this->is_empty()) {
112
+ return;
113
+ }
114
+
115
+ foreach($this->queue as $task_id=>$task) {
116
+ if ($task_id=='on_activation') {
117
+ do_action('ure_on_activation');
118
+ $this->remove('on_activation'); // remove this task after execution if it was defined
119
+ } elseif (!empty($task['action'])) {
120
+ $priority = empty($task['priority']) ? 10: $task['priority'];
121
+ add_action($task['action'], $task['routine'], $priority);
122
+ } else {
123
+ add_action('init', $task['routine']);
124
+ }
125
+ }
126
+ }
127
+ // end of process();
128
+
129
+ /**
130
+ * Private clone method to prevent cloning of the instance of the
131
+ * *Singleton* instance.
132
+ *
133
+ * @return void
134
+ */
135
+ private function __clone() {
136
+
137
+ }
138
+ // end of __clone()
139
+
140
+ /**
141
+ * Private unserialize method to prevent unserializing of the *Singleton*
142
+ * instance.
143
+ *
144
+ * @return void
145
+ */
146
+ private function __wakeup() {
147
+
148
+ }
149
+ // end of __wakeup()
150
+
151
+ }
152
+ // end of class URE_On_Activation
includes/{class-ure-lib.php → classes/ure-lib.php} RENAMED
@@ -11,7 +11,7 @@
11
  /**
12
  * This class contains general stuff for usage at WordPress plugins
13
  */
14
- class Ure_Lib extends Garvs_WP_Lib {
15
 
16
  public $roles = null;
17
  public $notification = ''; // notification message to show on page
@@ -27,7 +27,7 @@ class Ure_Lib extends Garvs_WP_Lib {
27
  protected $caps_readable = false;
28
  protected $hide_pro_banner = false;
29
  protected $full_capabilities = false;
30
- protected $ure_object = 'role'; // what to process, 'role' or 'user'
31
  public $role_default_html = '';
32
  protected $role_to_copy_html = '';
33
  protected $role_select_html = '';
@@ -340,11 +340,18 @@ if ($this->multisite && !is_network_admin()) {
340
  </div>
341
 
342
  <?php
343
- do_action('ure_dialogs_html');
344
  }
345
  // end of output_role_edit_dialogs()
346
 
347
 
 
 
 
 
 
 
 
348
  protected function output_confirmation_dialog() {
349
  ?>
350
  <div id="ure_confirmation_dialog" class="ure-modal-dialog">
@@ -391,7 +398,11 @@ if ($this->multisite && !is_network_admin()) {
391
 
392
  if ($this->ure_object == 'role') {
393
  $this->output_role_edit_dialogs();
 
 
394
  }
 
 
395
  $this->output_confirmation_dialog();
396
  ?>
397
  </div>
@@ -1840,7 +1851,7 @@ if ($this->multisite && !is_network_admin()) {
1840
  * @global wpdb $wpdb
1841
  * @return boolean
1842
  */
1843
- function direct_network_roles_update() {
1844
  global $wpdb;
1845
 
1846
  if (!$this->last_check_before_update()) {
@@ -1867,6 +1878,8 @@ if ($this->multisite && !is_network_admin()) {
1867
  $this->log_event($wpdb->last_error, true);
1868
  return false;
1869
  }
 
 
1870
  }
1871
 
1872
  return true;
@@ -1883,7 +1896,8 @@ if ($this->multisite && !is_network_admin()) {
1883
  $GLOBALS['_wp_switched_stack'] = array();
1884
  $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
1885
  }
1886
- // end of restore_after_blog_switching(
 
1887
 
1888
  protected function wp_api_network_roles_update() {
1889
  global $wpdb;
@@ -1942,7 +1956,6 @@ if ($this->multisite && !is_network_admin()) {
1942
  * @return boolean
1943
  */
1944
  protected function update_roles() {
1945
- global $wpdb;
1946
 
1947
  if ($this->multisite && is_super_admin() && $this->apply_to_all) { // update Role for the all blogs/sites in the network (permitted to superadmin only)
1948
  if (!$this->multisite_update_roles()) {
@@ -1967,13 +1980,13 @@ if ($this->multisite && !is_network_admin()) {
1967
  * @param boolean $show_message
1968
  */
1969
  protected function log_event($message, $show_message = false) {
1970
- global $wp_version;
1971
 
1972
  $file_name = URE_PLUGIN_DIR . 'user-role-editor.log';
1973
  $fh = fopen($file_name, 'a');
1974
  $cr = "\n";
1975
  $s = $cr . date("d-m-Y H:i:s") . $cr .
1976
- 'WordPress version: ' . $wp_version . ', PHP version: ' . phpversion() . ', MySQL version: ' . mysql_get_server_info() . $cr;
1977
  fwrite($fh, $s);
1978
  fwrite($fh, $message . $cr);
1979
  fclose($fh);
11
  /**
12
  * This class contains general stuff for usage at WordPress plugins
13
  */
14
+ class Ure_Lib extends URE_Base_Lib {
15
 
16
  public $roles = null;
17
  public $notification = ''; // notification message to show on page
27
  protected $caps_readable = false;
28
  protected $hide_pro_banner = false;
29
  protected $full_capabilities = false;
30
+ public $ure_object = 'role'; // what to process, 'role' or 'user'
31
  public $role_default_html = '';
32
  protected $role_to_copy_html = '';
33
  protected $role_select_html = '';
340
  </div>
341
 
342
  <?php
343
+
344
  }
345
  // end of output_role_edit_dialogs()
346
 
347
 
348
+ protected function output_user_caps_edit_dialogs() {
349
+
350
+
351
+ }
352
+ // end of output_user_caps_edit_dialogs()
353
+
354
+
355
  protected function output_confirmation_dialog() {
356
  ?>
357
  <div id="ure_confirmation_dialog" class="ure-modal-dialog">
398
 
399
  if ($this->ure_object == 'role') {
400
  $this->output_role_edit_dialogs();
401
+ } else {
402
+ $this->output_user_caps_edit_dialogs();
403
  }
404
+ do_action('ure_dialogs_html');
405
+
406
  $this->output_confirmation_dialog();
407
  ?>
408
  </div>
1851
  * @global wpdb $wpdb
1852
  * @return boolean
1853
  */
1854
+ public function direct_network_roles_update() {
1855
  global $wpdb;
1856
 
1857
  if (!$this->last_check_before_update()) {
1878
  $this->log_event($wpdb->last_error, true);
1879
  return false;
1880
  }
1881
+ // save role additional options
1882
+
1883
  }
1884
 
1885
  return true;
1896
  $GLOBALS['_wp_switched_stack'] = array();
1897
  $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
1898
  }
1899
+ // end of restore_after_blog_switching()
1900
+
1901
 
1902
  protected function wp_api_network_roles_update() {
1903
  global $wpdb;
1956
  * @return boolean
1957
  */
1958
  protected function update_roles() {
 
1959
 
1960
  if ($this->multisite && is_super_admin() && $this->apply_to_all) { // update Role for the all blogs/sites in the network (permitted to superadmin only)
1961
  if (!$this->multisite_update_roles()) {
1980
  * @param boolean $show_message
1981
  */
1982
  protected function log_event($message, $show_message = false) {
1983
+ global $wp_version, $wpdb;
1984
 
1985
  $file_name = URE_PLUGIN_DIR . 'user-role-editor.log';
1986
  $fh = fopen($file_name, 'a');
1987
  $cr = "\n";
1988
  $s = $cr . date("d-m-Y H:i:s") . $cr .
1989
+ 'WordPress version: ' . $wp_version . ', PHP version: ' . phpversion() . ', MySQL version: ' . $wpdb->db_version() . $cr;
1990
  fwrite($fh, $s);
1991
  fwrite($fh, $message . $cr);
1992
  fclose($fh);
includes/loader.php CHANGED
@@ -10,6 +10,7 @@
10
 
11
  require_once(URE_PLUGIN_DIR .'includes/define-constants.php');
12
  require_once(URE_PLUGIN_DIR .'includes/misc-support-stuff.php');
 
13
  require_once(URE_PLUGIN_DIR .'includes/classes/bbpress.php');
14
  require_once(URE_PLUGIN_DIR .'includes/class-assign-role.php');
15
  require_once(URE_PLUGIN_DIR .'includes/class-user-other-roles.php');
10
 
11
  require_once(URE_PLUGIN_DIR .'includes/define-constants.php');
12
  require_once(URE_PLUGIN_DIR .'includes/misc-support-stuff.php');
13
+ require_once(URE_PLUGIN_DIR .'includes/classes/task-queue.php');
14
  require_once(URE_PLUGIN_DIR .'includes/classes/bbpress.php');
15
  require_once(URE_PLUGIN_DIR .'includes/class-assign-role.php');
16
  require_once(URE_PLUGIN_DIR .'includes/class-user-other-roles.php');
js/ure-users.js CHANGED
@@ -1,40 +1,47 @@
1
  /* User Role Editor for users.php */
2
 
3
- function ure_move_users_from_no_role_dialog() {
4
- jQuery('#move_from_no_role_dialog').dialog({
5
- dialogClass: 'wp-dialog',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  modal: true,
7
- autoOpen: true,
8
- closeOnEscape: true,
9
  width: 400,
10
  height: 200,
11
  resizable: false,
12
  title: ure_users_data.move_from_no_role_title,
13
- 'buttons' : {
14
- 'OK': function () {
15
- ure_move_users_from_no_role();
16
-
17
  },
18
- Cancel: function() {
19
  jQuery(this).dialog('close');
20
  return false;
21
  }
22
- }
23
- });
24
-
25
- var options = jQuery("#new_role > option").clone();
26
- jQuery('#ure_new_role').empty().append(options);
27
- if (jQuery('#ure_new_role option[value="no_rights"]').length===0) {
28
- jQuery('#ure_new_role').append('<option value="no_rights">'+ ure_users_data.no_rights_caption +'</option>');
29
- }
30
-
31
- // Exclude change role to
32
- jQuery('#selectBox option[value=""]').remove();
33
- var new_role = jQuery('#new_role').find(":selected").val();
34
- if (new_role.length>0) {
35
- jQuery("#ure_new_role").val(new_role);
36
- }
37
- }
38
 
39
 
40
  function ure_move_users_from_no_role() {
1
  /* User Role Editor for users.php */
2
 
3
+ jQuery(document).ready(function() {
4
+ var options = jQuery("#new_role > option").clone();
5
+ jQuery('#ure_new_role').empty().append(options);
6
+ if (jQuery('#ure_new_role option[value="no_rights"]').length === 0) {
7
+ jQuery('#ure_new_role').append('<option value="no_rights">' + ure_users_data.no_rights_caption + '</option>');
8
+ }
9
+
10
+ // Exclude change role to
11
+ jQuery('#selectBox option[value=""]').remove();
12
+ var new_role = jQuery('#new_role').find(":selected").val();
13
+ if (new_role.length > 0) {
14
+ jQuery("#ure_new_role").val(new_role);
15
+ }
16
+ jQuery('#ure_new_role').trigger('updated');
17
+ });
18
+
19
+
20
+
21
+ function ure_move_users_from_no_role_dialog() {
22
+
23
+ jQuery('#move_from_no_role_dialog').dialog({
24
+ dialogClass: 'wp-dialog',
25
  modal: true,
26
+ autoOpen: true,
27
+ closeOnEscape: true,
28
  width: 400,
29
  height: 200,
30
  resizable: false,
31
  title: ure_users_data.move_from_no_role_title,
32
+ 'buttons': {
33
+ 'OK': function () {
34
+ ure_move_users_from_no_role();
35
+
36
  },
37
+ Cancel: function () {
38
  jQuery(this).dialog('close');
39
  return false;
40
  }
41
+ }
42
+ });
43
+
44
+ }
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
 
47
  function ure_move_users_from_no_role() {
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=vladi
4
  Tags: user, role, editor, security, access, permission, capability
5
  Requires at least: 4.0
6
  Tested up to: 4.4.1
7
- Stable tag: 4.22
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -24,7 +24,7 @@ Multi-site support is provided.
24
  To read more about 'User Role Editor' visit [this page](http://www.shinephp.com/user-role-editor-wordpress-plugin/) at [shinephp.com](http://shinephp.com)
25
 
26
  Short demo about 1st steps with User Role Editor:
27
- https://youtu.be/UmMtOmWGGxY
28
 
29
  Do you need more functionality with quality support in the real time? Do you wish to remove advertisements from User Role Editor pages?
30
  [Buy Pro version](https://www.role-editor.com).
@@ -76,6 +76,14 @@ If you wish to check available translations or help with plugin translation to y
76
  https://translate.wordpress.org/projects/wp-plugins/user-role-editor/
77
 
78
  == Changelog ==
 
 
 
 
 
 
 
 
79
  = [4.22] 15.01.2016 =
80
  * Unused 'add_users' capability was removed from the list of core capabilities as it was removed from WordPress starting from version 4.4
81
  * bbPress user capabilities are supported for use in the non-bbPress roles. You can not edit roles created by bbPress, as bbPress re-creates them dynamically for every request to the server. Full support for bbPress roles editing will be included into User Role Editor Pro version 4.22.
4
  Tags: user, role, editor, security, access, permission, capability
5
  Requires at least: 4.0
6
  Tested up to: 4.4.1
7
+ Stable tag: 4.23
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
24
  To read more about 'User Role Editor' visit [this page](http://www.shinephp.com/user-role-editor-wordpress-plugin/) at [shinephp.com](http://shinephp.com)
25
 
26
  Short demo about 1st steps with User Role Editor:
27
+ https://www.youtube.com/watch?v=UmMtOmWGGxY
28
 
29
  Do you need more functionality with quality support in the real time? Do you wish to remove advertisements from User Role Editor pages?
30
  [Buy Pro version](https://www.role-editor.com).
76
  https://translate.wordpress.org/projects/wp-plugins/user-role-editor/
77
 
78
  == Changelog ==
79
+
80
+ = [4.23] 31.01.2016 =
81
+ * Fix: "Users - Without Role" button showed empty roles drop down list on the 1st call.
82
+ * Update: Own task queue was added, so code which should executed once after plugin activation is executed by the next request to WP and may use a selected WordPress action to fire with a needed priority.
83
+ * Update: Call of deprecated mysql_server_info() is replaced with $wpdb->db_version().
84
+ * Update: Singleton patern is applied to the URE_Lib class.
85
+ * Minor code enhancements
86
+
87
  = [4.22] 15.01.2016 =
88
  * Unused 'add_users' capability was removed from the list of core capabilities as it was removed from WordPress starting from version 4.4
89
  * bbPress user capabilities are supported for use in the non-bbPress roles. You can not edit roles created by bbPress, as bbPress re-creates them dynamically for every request to the server. Full support for bbPress roles editing will be included into User Role Editor Pro version 4.22.
uninstall.php CHANGED
@@ -10,9 +10,10 @@ if (!defined('ABSPATH') || !defined('WP_UNINSTALL_PLUGIN')) {
10
  exit(); // silence is golden
11
  }
12
 
13
- global $wpdb;
14
 
15
- if (!is_multisite()) {
 
 
16
  $backup_option_name = $wpdb->prefix.'backup_user_roles';
17
  delete_option($backup_option_name);
18
  delete_option('ure_caps_readable');
@@ -20,19 +21,20 @@ if (!is_multisite()) {
20
  delete_option('ure_hide_pro_banner');
21
  delete_option('user_role_editor');
22
  delete_option('ure_role_additional_options_values');
 
 
 
 
 
 
 
23
  } else {
24
  $old_blog = $wpdb->blogid;
25
  // Get all blog ids
26
  $blogIds = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
27
  foreach ($blogIds as $blog_id) {
28
  switch_to_blog($blog_id);
29
- $backup_option_name = $wpdb->prefix.'backup_user_roles';
30
- delete_option($backup_option_name);
31
- delete_option('ure_caps_readable');
32
- delete_option('ure_show_deprecated_caps');
33
- delete_option('ure_hide_pro_banner');
34
- delete_option('user_role_editor');
35
- delete_option('ure_role_additional_options_values');
36
  }
37
  switch_to_blog($old_blog);
38
  }
10
  exit(); // silence is golden
11
  }
12
 
 
13
 
14
+ function ure_delete_options() {
15
+ global $wpdb;
16
+
17
  $backup_option_name = $wpdb->prefix.'backup_user_roles';
18
  delete_option($backup_option_name);
19
  delete_option('ure_caps_readable');
21
  delete_option('ure_hide_pro_banner');
22
  delete_option('user_role_editor');
23
  delete_option('ure_role_additional_options_values');
24
+ delete_option('ure_task_queue');
25
+
26
+ }
27
+
28
+
29
+ if (!is_multisite()) {
30
+ ure_delete_options();
31
  } else {
32
  $old_blog = $wpdb->blogid;
33
  // Get all blog ids
34
  $blogIds = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
35
  foreach ($blogIds as $blog_id) {
36
  switch_to_blog($blog_id);
37
+ ure_delete_options();
 
 
 
 
 
 
38
  }
39
  switch_to_blog($old_blog);
40
  }
user-role-editor.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: User Role Editor
4
  Plugin URI: https://www.role-editor.com
5
  Description: Change/add/delete WordPress user roles and capabilities.
6
- Version: 4.22
7
  Author: Vladimir Garagulya
8
  Author URI: https://www.role-editor.com
9
  Text Domain: ure
@@ -23,17 +23,15 @@ if (defined('URE_PLUGIN_URL')) {
23
  wp_die('It seems that other version of User Role Editor is active. Please deactivate it before use this version');
24
  }
25
 
26
- define('URE_VERSION', '4.22');
27
  define('URE_PLUGIN_URL', plugin_dir_url(__FILE__));
28
  define('URE_PLUGIN_DIR', plugin_dir_path(__FILE__));
29
  define('URE_PLUGIN_BASE_NAME', plugin_basename(__FILE__));
30
  define('URE_PLUGIN_FILE', basename(__FILE__));
31
  define('URE_PLUGIN_FULL_PATH', __FILE__);
32
 
33
- if (!class_exists('Garvs_WP_Lib')) {
34
- require_once(URE_PLUGIN_DIR.'includes/class-garvs-wp-lib.php');
35
- }
36
- require_once(URE_PLUGIN_DIR.'includes/class-ure-lib.php');
37
 
38
  // check PHP version
39
  $ure_required_php_version = '5.2.4';
@@ -49,5 +47,5 @@ Ure_Lib::check_version(get_bloginfo('version'), $ure_required_wp_version, $exit_
49
 
50
  require_once(URE_PLUGIN_DIR .'includes/loader.php');
51
 
52
- $ure_lib = new Ure_Lib('user_role_editor');
53
- $GLOBALS['user_role_editor'] = new User_Role_Editor($ure_lib);
3
  Plugin Name: User Role Editor
4
  Plugin URI: https://www.role-editor.com
5
  Description: Change/add/delete WordPress user roles and capabilities.
6
+ Version: 4.23
7
  Author: Vladimir Garagulya
8
  Author URI: https://www.role-editor.com
9
  Text Domain: ure
23
  wp_die('It seems that other version of User Role Editor is active. Please deactivate it before use this version');
24
  }
25
 
26
+ define('URE_VERSION', '4.23');
27
  define('URE_PLUGIN_URL', plugin_dir_url(__FILE__));
28
  define('URE_PLUGIN_DIR', plugin_dir_path(__FILE__));
29
  define('URE_PLUGIN_BASE_NAME', plugin_basename(__FILE__));
30
  define('URE_PLUGIN_FILE', basename(__FILE__));
31
  define('URE_PLUGIN_FULL_PATH', __FILE__);
32
 
33
+ require_once(URE_PLUGIN_DIR.'includes/classes/base-lib.php');
34
+ require_once(URE_PLUGIN_DIR.'includes/classes/ure-lib.php');
 
 
35
 
36
  // check PHP version
37
  $ure_required_php_version = '5.2.4';
47
 
48
  require_once(URE_PLUGIN_DIR .'includes/loader.php');
49
 
50
+ $ure_lib = Ure_Lib::get_instance('user_role_editor');
51
+ $GLOBALS['user_role_editor'] = new User_Role_Editor();