PluginProbe
Adminimize / 1.9.1
Adminimize v1.9.1
1.11.14 1.11.13 1.11.1 1.11.10 1.11.11 1.11.12 1.11.2 1.11.3 1.11.4 1.11.5 1.11.6 1.11.7 1.11.8 1.11.9 1.3 1.4.7 1.6 1.7.12 1.7.13 1.7.14 1.7.15 1.7.16 1.7.17 1.7.18 1.7.19 All 53 releases
← All changes | adminimize.php +453 -510 1.11.7 → 1.9.1 View file →
@@ -6,17 +6,15 @@
6 6 * Domain Path: /languages
7 7 * Description: Visually compresses the administrative meta-boxes so that more admin page content can be initially seen. The plugin that lets you hide 'unnecessary' items from the WordPress administration menu, for all roles of your install. You can also hide post meta controls on the edit-area to simplify the interface. It is possible to simplify the admin in different for all roles.
8 8 * Author: Frank Bültge
9 9 * Author URI: http://bueltge.de/
10 - * Version: 1.11.7
10 + * Version: 1.9.1
11 11 * License: GPLv2+
12 12 *
13 - * Php Version 5.6
14 - *
15 13 * @package WordPress
16 14 * @author Frank Bültge <[email protected]>
17 15 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
18 - * @version 2020-07-15
16 + * @version 2016-01-25
19 17 */
20 18
21 19 /**
22 20 * The stylesheet and the initial idea is from Eric A. Meyer http://meyerweb.com/
@@ -23,9 +21,8 @@
23 21 * I have written a plugin with many options on the basis idea
24 22 * of differently user-right and a user-friendly range in admin-area via reduce areas.
25 23 * :( grmpf i have so much wishes and hints form users, there use the plugin and
26 24 * it is not easy to development this on my free time.
27 - * Also I hate the source, old and hard to maintain, no OOP.
28 25 */
29 26
30 27 if ( ! function_exists( 'add_action' ) ) {
31 28 echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
@@ -33,17 +30,10 @@
33 30 }
34 31
35 32 // plugin definitions
36 33 define( 'FB_ADMINIMIZE_BASENAME', plugin_basename( __FILE__ ) );
37 -define( 'FB_ADMINIMIZE_BASEFOLDER', plugin_basename( __DIR__ ) );
34 +define( 'FB_ADMINIMIZE_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) );
38 35
39 -/**
40 - * Return data from the plugin.
41 - *
42 - * @param string $value
43 - *
44 - * @return mixed
45 - */
46 36 function _mw_adminimize_get_plugin_data( $value = 'Version' ) {
47 37
48 38 if ( ! function_exists( 'get_plugin_data' ) ) {
49 39 require_once ABSPATH . '/wp-admin/includes/plugin.php';
@@ -48,11 +38,12 @@
48 38 if ( ! function_exists( 'get_plugin_data' ) ) {
49 39 require_once ABSPATH . '/wp-admin/includes/plugin.php';
50 40 }
51 41
52 - $plugin_data = get_plugin_data( __FILE__ );
42 + $plugin_data = get_plugin_data( __FILE__ );
43 + $plugin_value = $plugin_data[ $value ];
53 44
54 - return $plugin_data[ $value ];
45 + return $plugin_value;
55 46 }
56 47
57 48 /**
58 49 * Load language files.
@@ -94,31 +85,21 @@
94 85 * @return bool
95 86 */
96 87 function _mw_adminimize_exclude_settings_page() {
97 88
98 - if ( ! is_admin() ) {
99 - return false;
89 + if ( ! function_exists( 'get_current_screen' ) ) {
90 + return TRUE;
100 91 }
101 92
102 - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
103 - return false;
104 - }
93 + // Get admin page
94 + $screen = get_current_screen();
105 95
106 - $page = '';
107 - if ( isset( $_GET['page'] ) ) {
108 - $page = esc_attr( $_GET['page'] );
96 + // Don't filter on settings page
97 + if ( isset( $screen->id ) && FALSE !== strpos( $screen->id, 'adminimize' ) ) {
98 + return TRUE;
109 99 }
110 100
111 - if ( function_exists( 'get_current_screen' ) ) {
112 - $screen_tmp = get_current_screen();
113 -
114 - if ( isset( $screen_tmp->id ) && null !== $screen_tmp->id ) {
115 - $page = $screen_tmp->id;
116 - }
117 - }
118 -
119 - // Don't filter on settings page
120 - return FALSE !== strpos( $page, 'adminimize' );
101 + return FALSE;
121 102 }
122 103
123 104 /**
124 105 * Get status, if the plugin active network wide.
@@ -127,23 +108,12 @@
127 108 */
128 109 function _mw_adminimize_is_active_on_multisite() {
129 110
130 111 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
131 - require_once ABSPATH . '/wp-admin/includes/plugin.php';
112 + require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
132 113 }
133 114
134 - /**
135 - * Allow different adminimize options per site on multisite.
136 - *
137 - * @since 1.11.6
138 - *
139 - * @param bool
140 - */
141 - $force_single_site_usage = apply_filters( 'adminimize_mu_force_options_per_site', false );
142 -
143 - if ( is_multisite()
144 - && is_plugin_active_for_network( FB_ADMINIMIZE_BASENAME )
145 - && ! $force_single_site_usage ) {
115 + if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
146 116 return TRUE;
147 117 }
148 118
149 119 return FALSE;
@@ -157,36 +127,27 @@
157 127 * @return array $user_roles
158 128 */
159 129 function _mw_adminimize_get_all_user_roles() {
160 130
161 - /** @var $wp_roles WP_Roles */
162 131 global $wp_roles;
163 132
164 133 $user_roles = array();
165 134
166 - if ( null !== $wp_roles->roles && is_array( $wp_roles->roles ) ) {
135 + if ( NULL !== $wp_roles->roles && is_array( $wp_roles->roles ) ) {
136 + /** @var array $wp_roles */
167 137 foreach ( $wp_roles->roles as $role => $data ) {
168 138 $user_roles[] = $role;
169 - // The $data var contains caps, maybe for later use.
139 + //$data contains caps, maybe for later use..
170 140 }
171 141 }
172 142
173 143 // Exclude the new bbPress roles.
174 - if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
175 - $user_roles = array_diff(
176 - $user_roles,
177 - array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
178 - );
179 - }
144 + $user_roles = array_diff(
145 + $user_roles,
146 + array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
147 + );
180 148
181 - /**
182 - * Use this filter to add or remove a role in Adminimize options.
183 - *
184 - * @since 1.11.6
185 - *
186 - * @param array
187 - */
188 - return apply_filters( 'adminimize_user_roles_filter', $user_roles );
149 + return $user_roles;
189 150 }
190 151
191 152 /**
192 153 * _mw_adminimize_get_all_user_roles_names() - Returns an array with all user roles_names in it.
@@ -196,68 +157,56 @@
196 157 * @return array $user_roles_names
197 158 */
198 159 function _mw_adminimize_get_all_user_roles_names() {
199 160
200 - /** @var $wp_roles WP_Roles */
201 161 global $wp_roles;
162 +
202 163 $user_roles_names = array();
203 164
165 + /** @var array $wp_roles */
204 166 foreach ( $wp_roles->role_names as $role_name => $data ) {
167 + if ( function_exists( 'translate_user_role' ) ) {
168 + $data = translate_user_role( $data );
169 + } else {
170 + $data = esc_attr_x( $data, 'Translate each user role.' );
171 + }
205 172
206 - $data = translate_user_role( $data );
207 173 $user_roles_names[] = $data;
208 174 }
209 175
210 176 // exclude the new bbPress roles
211 - if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
212 - $user_roles_names = array_diff(
213 - $user_roles_names,
214 - array(
215 - esc_attr__( 'Keymaster', 'bbpress' ),
216 - esc_attr__( 'Moderator', 'bbpress' ),
217 - esc_attr__( 'Participant', 'bbpress' ),
218 - esc_attr__( 'Spectator', 'bbpress' ),
219 - esc_attr__( 'Blocked', 'bbpress' ),
220 - )
221 - );
222 - }
177 + $user_roles_names = array_diff(
178 + $user_roles_names,
179 + array(
180 + esc_attr__( 'Keymaster', 'bbpress' ),
181 + esc_attr__( 'Moderator', 'bbpress' ),
182 + esc_attr__( 'Participant', 'bbpress' ),
183 + esc_attr__( 'Spectator', 'bbpress' ),
184 + esc_attr__( 'Blocked', 'bbpress' ),
185 + )
186 + );
223 187
224 - /**
225 - * Use this filter to add or remove a role-name in Adminimize options.
226 - *
227 - * @since 1.11.6
228 - *
229 - * @param array
230 - */
231 - return apply_filters( 'adminimize_user_roles_names_filter', $user_roles_names );
188 + return $user_roles_names;
232 189 }
233 190
234 191 /**
235 - * Get post type.
236 - *
237 - * @return null|string String of the post type.
192 + * return post type
238 193 */
239 -function _mw_adminimize_get_current_post_type() {
194 +function _mw_get_current_post_type() {
240 195
241 196 global $post, $typenow, $current_screen;
242 197
243 - // We have a post so we can just get the post type from that.
198 + //we have a post so we can just get the post type from that
244 199 if ( $post && $post->post_type ) {
245 200 return $post->post_type;
246 - }
247 -
248 - // Check the global $typenow - set in admin.php
249 - if ( $typenow ) {
201 + } //check the global $typenow - set in admin.php
202 + else if ( $typenow ) {
250 203 return $typenow;
251 - }
252 -
253 - // Check the global $current_screen object - set in screen.php
254 - if ( $current_screen && $current_screen->post_type ) {
204 + } // check the global $current_screen object - set in sceen.php
205 + else if ( $current_screen && $current_screen->post_type ) {
255 206 return $current_screen->post_type;
256 - }
257 -
258 - // lastly check the post_type querystring
259 - if ( isset( $_REQUEST['post_type'] ) ) {
207 + } // lastly check the post_type querystring
208 + else if ( isset( $_REQUEST[ 'post_type' ] ) ) {
260 209 return sanitize_key( $_REQUEST[ 'post_type' ] );
261 210 }
262 211
263 212 // we do not know the post type!
@@ -270,13 +219,14 @@
270 219 function _mw_adminimize_admin_init() {
271 220
272 221 global $pagenow, $post_type, $menu, $submenu;
273 222
274 - $post_id = 0;
275 223 if ( isset( $_GET[ 'post' ] ) && ! is_array( $_GET[ 'post' ] ) ) {
276 224 $post_id = (int) esc_attr( $_GET[ 'post' ] );
277 225 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
278 226 $post_id = (int) esc_attr( $_POST[ 'post_ID' ] );
227 + } else {
228 + $post_id = 0;
279 229 }
280 230
281 231 $current_post_type = $post_type;
282 232 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
@@ -282,22 +232,16 @@
282 232 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
283 233 $current_post_type = get_post_type( $post_id );
284 234 }
285 235 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
286 - $current_post_type = _mw_adminimize_get_current_post_type();
236 + $current_post_type = _mw_get_current_post_type();
287 237 }
288 - if ( ! $current_post_type ) { // set hard to post
238 + if ( ! $current_post_type ) // set hard to post
239 + {
289 240 $current_post_type = 'post';
290 241 }
291 242
292 - // Debug helper
293 - if ( class_exists( 'DebugListener' ) ) {
294 - $listener = new DebugListener();
295 - add_action( 'adminimize.log', [$listener, 'listen'], 10, 2 );
296 - add_action( 'wp_footer', array( $listener, 'dump' ), PHP_INT_MAX );
297 - }
298 -
299 - // Get all user roles.
243 + // Get all user rolles.
300 244 $user_roles = _mw_adminimize_get_all_user_roles();
301 245
302 246 // Get settings.
303 247 $adminimizeoptions = _mw_adminimize_get_option_value();
@@ -321,9 +265,9 @@
321 265 // widget pages
322 266 $widget_pages = array( 'widgets.php' );
323 267
324 268 foreach ( $user_roles as $role ) {
325 - $disabled_admin_bar_[ $role ] = _mw_adminimize_get_option_value(
269 + $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
326 270 'mw_adminimize_disabled_admin_bar_' . $role . '_items'
327 271 );
328 272 $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
329 273 'mw_adminimize_disabled_global_option_' . $role . '_items'
@@ -353,22 +297,35 @@
353 297 }
354 298
355 299 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
356 300
357 - // Backend options
301 + // global options
358 302 // exclude super admin
359 - if ( ! _mw_adminimize_exclude_super_admin() && ! _mw_adminimize_exclude_settings_page() ) {
303 + if ( ! _mw_adminimize_exclude_super_admin() ) {
304 + $_mw_adminimize_footer = (int) _mw_adminimize_get_option_value( '_mw_adminimize_footer' );
305 + switch ( $_mw_adminimize_footer ) {
306 + case 1:
307 + wp_enqueue_script(
308 + '_mw_adminimize_remove_footer',
309 + WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_footer' . $suffix . '.js',
310 + array( 'jquery' )
311 + );
312 + break;
313 + }
314 +
360 315 $_mw_adminimize_header = (int) _mw_adminimize_get_option_value( '_mw_adminimize_header' );
361 - if ( 1 === $_mw_adminimize_header ) {
362 - wp_enqueue_script(
363 - '_mw_adminimize_remove_header',
364 - WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_header' . $suffix . '.js',
365 - [ 'jquery' ]
366 - );
316 + switch ( $_mw_adminimize_header ) {
317 + case 1:
318 + wp_enqueue_script(
319 + '_mw_adminimize_remove_header',
320 + WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_header' . $suffix . '.js',
321 + array( 'jquery' )
322 + );
323 + break;
367 324 }
368 325
369 - // Post-page options.
370 - if ( in_array( $pagenow, $def_post_pages, TRUE ) ) {
326 + //post-page options
327 + if ( in_array( $pagenow, $def_post_pages, FALSE ) ) {
371 328
372 329 $_mw_adminimize_tb_window = (int) _mw_adminimize_get_option_value( '_mw_adminimize_tb_window' );
373 330 switch ( $_mw_adminimize_tb_window ) {
374 331 case 1:
@@ -390,9 +347,9 @@
390 347 );
391 348 break;
392 349 }
393 350
394 - // Category options.
351 + //category options
395 352 $_mw_adminimize_cat_full = (int) _mw_adminimize_get_option_value( '_mw_adminimize_cat_full' );
396 353 switch ( $_mw_adminimize_cat_full ) {
397 354 case 1:
398 355 wp_enqueue_style(
@@ -401,82 +358,97 @@
401 358 );
402 359 break;
403 360 }
404 361
405 - // Set default editor tinymce
362 + // set default editor tinymce
406 363 if ( _mw_adminimize_recursive_in_array(
407 - '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
408 - $disabled_metaboxes_page_all
409 - )
410 - || _mw_adminimize_recursive_in_array(
411 - '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
412 - $disabled_metaboxes_post_all
413 - )
364 + '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
365 + $disabled_metaboxes_page_all
366 + )
367 + || _mw_adminimize_recursive_in_array(
368 + '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
369 + $disabled_metaboxes_post_all
370 + )
414 371 ) {
415 - add_filter( 'wp_default_editor', '_mw_admininimize_return_tinmyce' );
416 - /**
417 - * Return string tinymce.
418 - * Necessary for php 5.2 usage :(; not possible to use an anonymous function.
419 - *
420 - * @return string
421 - */
422 - function _mw_admininimize_return_tinmyce() {
423 - return 'tinymce';
424 - }
372 + add_filter( 'wp_default_editor', create_function( '', 'return "tinymce";' ) );
425 373 }
426 374
427 - // Remove media buttons
375 + // remove media bottons
428 376 if ( _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_page_all )
429 - || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
377 + || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
430 378 ) {
431 379 remove_action( 'media_buttons', 'media_buttons' );
432 380 }
433 381 }
382 +
434 383 }
435 384
436 - // set meta-box post option
437 - if ( in_array( $pagenow, $def_post_pages, TRUE ) && in_array( $current_post_type, $def_post_types, TRUE ) ) {
385 + // set menu option
386 + add_action( 'admin_head', '_mw_adminimize_set_menu_option', 1 );
387 + // global_options
388 + add_action( 'admin_head', '_mw_adminimize_set_global_option', 1 );
389 +
390 + // set metabox post option
391 + if ( in_array( $pagenow, $def_post_pages, FALSE ) && in_array( $current_post_type, $def_post_types, FALSE ) ) {
438 392 add_action( 'admin_head', '_mw_adminimize_set_metabox_post_option', 1 );
439 393 }
440 - // set meta-box page option
441 - if ( in_array( $pagenow, $def_page_pages, TRUE ) && in_array( $current_post_type, $def_page_types, TRUE ) ) {
394 + // set metabox page option
395 + if ( in_array( $pagenow, $def_page_pages, FALSE ) && in_array( $current_post_type, $def_page_types, FALSE ) ) {
442 396 add_action( 'admin_head', '_mw_adminimize_set_metabox_page_option', 1 );
443 397 }
444 398 // set custom post type options
445 - if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages, TRUE )
446 - && in_array( $current_post_type, $def_custom_types, TRUE )
399 + if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages, FALSE )
400 + && in_array(
401 + $current_post_type, $def_custom_types, FALSE
402 + )
447 403 ) {
448 404 add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
449 405 }
450 406 // set link option
451 - if ( in_array( $pagenow, $link_pages, TRUE ) ) {
407 + if ( in_array( $pagenow, $link_pages, FALSE ) ) {
452 408 add_action( 'admin_head', '_mw_adminimize_set_link_option', 1 );
453 409 }
454 410 // set wp nav menu options
455 - if ( in_array( $pagenow, $nav_menu_pages, TRUE ) ) {
411 + if ( in_array( $pagenow, $nav_menu_pages, FALSE ) ) {
456 412 add_action( 'admin_head', '_mw_adminimize_set_nav_menu_option', 1 );
457 413 }
458 414 // set widget options
459 - if ( in_array( $pagenow, $widget_pages, TRUE ) ) {
415 + if ( in_array( $pagenow, $widget_pages, FALSE ) ) {
460 416 add_action( 'admin_head', '_mw_adminimize_set_widget_option', 1 );
461 417 }
418 +
419 + $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
420 + $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
462 421 }
463 422
464 -// Change menu via settings of Adminimize.
465 -//add_filter( 'custom_menu_order', '__return_true' );
466 -add_filter( 'admin_menu', '_mw_adminimize_set_menu_option', 99999 );
423 +/**
424 + * Init always with WP
425 + */
426 +function _mw_adminimize_init() {
467 427
468 -// global_options
469 -add_action( 'admin_head', '_mw_adminimize_set_global_option', 1 );
428 + // change Admin Bar and user Info
429 + if ( version_compare( $GLOBALS[ 'wp_version' ], '3.3alpha', '>=' ) ) {
430 + _mw_adminimize_set_menu_option_33();
431 + } else {
432 + add_action( 'admin_head', '_mw_adminimize_set_user_info' );
433 + add_action( 'wp_head', '_mw_adminimize_set_user_info' );
434 + }
435 +
436 +}
437 +
470 438 // on admin init
439 +define( 'MW_ADMIN_FILE', plugin_basename( __FILE__ ) );
471 440 if ( is_admin() ) {
472 - add_action( 'admin_init', '_mw_adminimize_admin_init' );
441 + add_action( 'admin_init', '_mw_adminimize_textdomain' );
442 + add_action( 'admin_init', '_mw_adminimize_admin_init', 2 );
473 443 add_action( 'admin_menu', '_mw_adminimize_add_settings_page' );
474 444 add_action( 'admin_menu', '_mw_adminimize_remove_dashboard' );
475 445 }
446 +add_action( 'init', '_mw_adminimize_init', 2 );
476 447
477 448 register_activation_hook( __FILE__, '_mw_adminimize_install' );
478 -register_uninstall_hook( __FILE__, '_mw_adminimize_uninstall' );
449 +register_uninstall_hook( __FILE__, '_mw_adminimize_deinstall' );
450 +//register_deactivation_hook(__FILE__, '_mw_adminimize_deinstall' );
479 451
480 452 /**
481 453 * Remove the dashboard
482 454 */
@@ -493,17 +465,17 @@
493 465 }
494 466
495 467 global $menu, $user_ID;
496 468
497 - $disabled_menu_ = array();
498 - $disabled_submenu_ = array();
469 + $disabled_menu_ = '';
470 + $disabled_submenu_ = '';
499 471 $user_roles = _mw_adminimize_get_all_user_roles();
500 472
501 473 foreach ( $user_roles as $role ) {
502 - $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
474 + $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
503 475 'mw_adminimize_disabled_menu_' . $role . '_items'
504 476 );
505 - $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
477 + $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
506 478 'mw_adminimize_disabled_submenu_' . $role . '_items'
507 479 );
508 480 }
509 481
@@ -521,9 +493,9 @@
521 493 $redirect = FALSE;
522 494 foreach ( $user_roles as $role ) {
523 495 if ( _mw_adminimize_current_user_has_role( $role ) ) {
524 496 if ( _mw_adminimize_recursive_in_array( 'index.php', $disabled_menu_[ $role ] )
525 - || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
497 + || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
526 498 ) {
527 499 $redirect = TRUE;
528 500 }
529 501 }
@@ -528,9 +500,9 @@
528 500 }
529 501 }
530 502 }
531 503
532 - // Redirect option, if Dashboard is inactive
504 + // redirect option, if Dashboard is inactive
533 505 if ( $redirect ) {
534 506 $_mw_adminimize_db_redirect = (int) _mw_adminimize_get_option_value(
535 507 '_mw_adminimize_db_redirect'
536 508 );
@@ -565,14 +537,14 @@
565 537
566 538 $dashboard_core_string = esc_attr__( 'Dashboard' );
567 539 $dashboard = array( $menu[ $page ][ 0 ], $menu[ $page ][ 1 ] );
568 540 while (
569 - ! in_array( $dashboard_core_string, $dashboard, TRUE ) && next( $menu )
541 + ! in_array( $dashboard_core_string, $dashboard, FALSE ) && next( $menu )
570 542 ) {
571 543 $page = key( $menu );
572 544 }
573 545
574 - if ( in_array( $dashboard_core_string, $dashboard, TRUE ) ) {
546 + if ( in_array( $dashboard_core_string, $dashboard, FALSE ) ) {
575 547 unset( $menu[ $page ] );
576 548 }
577 549 reset( $menu );
578 550 $page = key( $menu );
@@ -581,15 +553,112 @@
581 553 $page = key( $menu );
582 554 }
583 555
584 556 if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER[ 'REQUEST_URI' ] ) ) {
585 - wp_safe_redirect( $_mw_adminimize_db_redirect );
557 + wp_redirect( $_mw_adminimize_db_redirect );
586 558 }
587 559 }
560 +
588 561 }
589 562 }
590 563
591 564 /**
565 + * Set menu options from database.
566 + */
567 +function _mw_adminimize_set_user_info() {
568 +
569 + if ( _mw_adminimize_exclude_settings_page() ) {
570 + return;
571 + }
572 +
573 + // exclude super admin
574 + if ( _mw_adminimize_exclude_super_admin() ) {
575 + return;
576 + }
577 +
578 + global $user_identity;
579 +
580 + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
581 + $user_roles = _mw_adminimize_get_all_user_roles();
582 +
583 + foreach ( $user_roles as $role ) {
584 + $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
585 + 'mw_adminimize_disabled_menu_' . $role . '_items'
586 + );
587 + $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
588 + 'mw_adminimize_disabled_submenu_' . $role . '_items'
589 + );
590 + }
591 +
592 + $_mw_adminimize_admin_head = "\n";
593 + $_mw_adminimize_user_info = (int) _mw_adminimize_get_option_value( '_mw_adminimize_user_info' );
594 + $_mw_adminimize_ui_redirect = (int) _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' );
595 +
596 + // change user-info
597 + switch ( $_mw_adminimize_user_info ) {
598 + case 1:
599 + $_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
600 + $_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove(); });' . "\n";
601 + $_mw_adminimize_admin_head .= '</script>' . "\n";
602 + break;
603 + case 2:
604 + $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
605 + dirname( __FILE__ )
606 + ) . '/css/mw_small_user_info' . $suffix . '.css" type="text/css" />' . "\n";
607 +
608 + $_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
609 + $_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove();';
610 + if ( 1 === (int) $_mw_adminimize_ui_redirect ) {
611 + $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
612 + 'siteurl'
613 + ) . wp_nonce_url(
614 + ( '/wp-login.php?action=logout&amp;redirect_to=' ) . get_option( 'siteurl' ), 'log-out'
615 + ) . '" title="' . esc_attr__( 'Log Out' ) . '">' . esc_attr__(
616 + 'Log Out'
617 + ) . '</a></p></div>\' ) });' . "\n";
618 + } else {
619 + $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
620 + 'siteurl'
621 + ) . wp_nonce_url( ( '/wp-login.php?action=logout' ), 'log-out' ) . '" title="' . esc_attr__(
622 + 'Log Out'
623 + ) . '">' . esc_attr__( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
624 + }
625 + $_mw_adminimize_admin_head .= '</script>' . "\n";
626 + break;
627 + case 3:
628 + $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
629 + dirname( __FILE__ )
630 + ) . '/css/mw_small_user_info' . $suffix . '.css" type="text/css" />' . "\n";
631 +
632 + $_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
633 + $_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove();';
634 + if ( 1 === (int) $_mw_adminimize_ui_redirect ) {
635 + $_mw_adminimize_admin_head .= 'jQuery( \'div#wpcontent\' ).after( \'<div id="small_user_info"><p><a href="' . get_option(
636 + 'siteurl'
637 + ) . ( '/wp-admin/profile.php' ) . '">' . $user_identity . '</a> | <a href="' . get_option(
638 + 'siteurl'
639 + ) . wp_nonce_url(
640 + ( '/wp-login.php?action=logout&amp;redirect_to=' ) . get_option( 'siteurl' ), 'log-out'
641 + ) . '" title="' . esc_attr__( 'Log Out' ) . '">' . esc_attr__(
642 + 'Log Out'
643 + ) . '</a></p></div>\' ) });' . "\n";
644 + } else {
645 + $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
646 + 'siteurl'
647 + ) . ( '/wp-admin/profile.php' ) . '">' . $user_identity . '</a> | <a href="' . get_option(
648 + 'siteurl'
649 + ) . wp_nonce_url( ( '/wp-login.php?action=logout' ), 'log-out' ) . '" title="' . esc_attr__(
650 + 'Log Out'
651 + ) . '">' . esc_attr__( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
652 + }
653 + $_mw_adminimize_admin_head .= '</script>' . "\n";
654 + break;
655 + }
656 +
657 + echo $_mw_adminimize_admin_head;
658 +}
659 +
660 +/**
592 661 * Set menu for settings
593 662 */
594 663 function _mw_adminimize_set_menu_option() {
595 664
@@ -594,9 +663,9 @@
594 663 function _mw_adminimize_set_menu_option() {
595 664
596 665 // exclude super admin
597 666 if ( _mw_adminimize_exclude_super_admin() ) {
598 - return;
667 + return NULL;
599 668 }
600 669
601 670 // Leave the settings screen from Adminimize to see all areas on settings.
602 671 if ( _mw_adminimize_exclude_settings_page() ) {
@@ -603,40 +672,22 @@
603 672 return;
604 673 }
605 674
606 675 global $menu, $submenu;
607 - $wp_menu = (array) _mw_adminimize_get_option_value( 'mw_adminimize_default_menu' );
608 - $wp_submenu = (array) _mw_adminimize_get_option_value( 'mw_adminimize_default_submenu' );
609 676
610 - // Object to array
611 - if ( is_object( $wp_submenu ) ) {
612 - $wp_submenu = get_object_vars( $wp_submenu );
613 - }
614 -
615 - if ( ! isset( $wp_menu ) || empty( $wp_menu ) ) {
616 - $wp_menu = $menu;
617 - }
618 - if ( ! isset( $wp_submenu ) || empty( $wp_submenu ) ) {
619 - $wp_submenu = $submenu;
620 - }
621 677 if ( ! isset( $menu ) || empty( $menu ) ) {
622 678 return;
623 679 }
624 680
625 - _mw_adminimize_debug( $wp_menu, 'Adminimize, WordPress Menu:' );
626 - _mw_adminimize_debug( $wp_submenu, 'Adminimize, WordPress Sub-Menu:' );
681 + $user_roles = _mw_adminimize_get_all_user_roles();
682 + $disabled_menu_ = '';
683 + $disabled_submenu_ = '';
627 684
628 - $disabled_menu_ = array();
629 - $disabled_submenu_ = array();
630 - $user = wp_get_current_user();
631 - $user_roles = $user->roles;
632 - _mw_adminimize_debug( $user, 'Adminimize, Current User:' );
633 -
634 685 foreach ( $user_roles as $role ) {
635 - $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
686 + $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
636 687 'mw_adminimize_disabled_menu_' . $role . '_items'
637 688 );
638 - $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
689 + $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
639 690 'mw_adminimize_disabled_submenu_' . $role . '_items'
640 691 );
641 692 }
642 693
@@ -644,63 +695,52 @@
644 695 $mw_adminimize_submenu = array();
645 696
646 697 // Set admin-menu.
647 698 foreach ( $user_roles as $role ) {
648 - if ( in_array( $role, $user->roles, TRUE )
649 - && _mw_adminimize_current_user_has_role( $role )
699 +
700 + $user = wp_get_current_user();
701 +
702 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE )
703 + && _mw_adminimize_current_user_has_role(
704 + $role
705 + )
650 706 ) {
651 - // Create array about all items with all affected roles.
652 - foreach ( (array) $disabled_menu_[ $role ] as $menu_item ) {
653 - $mw_adminimize_menu[] = $menu_item;
654 - }
655 - foreach ( (array) $disabled_submenu_[ $role ] as $submenu_item ) {
656 - $mw_adminimize_submenu[] = $submenu_item;
657 - }
707 + $mw_adminimize_menu = $disabled_menu_[ $role ];
708 + $mw_adminimize_submenu = $disabled_submenu_[ $role ];
658 709 }
659 710 }
660 711
661 - // Support Multiple Roles for users.
662 - // Leave only the items, there are active on each roles of the users.
663 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
664 - $mw_adminimize_menu = _mw_adminimize_get_intersection( $disabled_menu_ );
665 - $mw_adminimize_submenu = _mw_adminimize_get_intersection( $disabled_submenu_ );
666 - } else {
667 - // Alternative filter the array to remove duplicates, much faster.
668 - $mw_adminimize_menu = array_unique( $mw_adminimize_menu );
669 - $mw_adminimize_submenu = array_unique( $mw_adminimize_submenu );
712 + // Fallback on users.php on all user roles smaller admin.
713 + if ( is_array( $mw_adminimize_menu ) && in_array( 'users.php', $mw_adminimize_menu, FALSE ) ) {
714 + $mw_adminimize_menu[] = 'profile.php';
670 715 }
671 - _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Menu Slugs to hide after Filter.' );
672 - _mw_adminimize_debug( $mw_adminimize_submenu, 'Adminimize, Sub-Menu Slugs to hide after Filter.' );
673 716
674 - foreach ( $wp_menu as $key => $item ) {
717 + foreach ( $menu as $index => $item ) {
675 718
676 - _mw_adminimize_debug( $item, 'Adminimize, Each Menu Item Array to check for hiding.' );
719 + if ( 'index.php' === $item ) {
720 + continue;
721 + }
677 722
678 - // Menu
679 723 if ( isset( $item[ 2 ] ) ) {
680 - $menu_slug = $item[ 2 ];
681 - // Check, if the Menu item in the current user role settings?
682 - if ( in_array( $menu_slug, $mw_adminimize_menu, false )
724 + if ( isset( $mw_adminimize_menu ) && is_array( $mw_adminimize_menu )
725 + && in_array(
726 + $item[ 2 ], $mw_adminimize_menu, FALSE
727 + )
683 728 ) {
684 - remove_menu_page( $menu_slug );
685 - // Prevent access to the page with the slug, there was inactive.
686 - _mw_adminimize_check_page_access( $menu_slug );
729 + unset( $menu[ $index ] );
687 730 }
688 731
689 - // Sub Menu Settings.
690 - if ( isset( $wp_submenu ) && ! empty( $wp_submenu[ $menu_slug ] ) ) {
691 - foreach ( (array) $wp_submenu[ $menu_slug ] as $subindex => $subitem ) {
692 - // Check, if is Sub Menu item in the user role settings?
732 + if ( isset( $submenu ) && ! empty( $submenu[ $item[ 2 ] ] ) ) {
733 + foreach ( $submenu[ $item[ 2 ] ] as $subindex => $subitem ) {
734 + // Check, if is menu item in the user role settings?
693 735 if (
694 736 isset( $mw_adminimize_submenu )
695 737 && _mw_adminimize_in_arrays(
696 - array( $subitem[ 2 ], $menu_slug . '__' . $subindex ),
738 + array( $subitem[ 2 ], $item[ 2 ] . '__' . $subindex ),
697 739 $mw_adminimize_submenu
698 740 )
699 741 ) {
700 - remove_submenu_page( $menu_slug, $subitem[ 2 ] );
701 - // Prevent access to the page with the slug, there was inactive.
702 - _mw_adminimize_check_page_access( $subitem[ 2 ] );
742 + unset( $submenu[ $item[ 2 ] ][ $subindex ] );
703 743 }
704 744 }
705 745 }
706 746 }
@@ -708,12 +748,14 @@
708 748
709 749 }
710 750
711 751 /**
712 - * Set global options in backend in all areas.
752 + * set global options in backend in all areas
713 753 */
714 754 function _mw_adminimize_set_global_option() {
715 755
756 + global $_wp_admin_css_colors;
757 +
716 758 // exclude super admin
717 759 if ( _mw_adminimize_exclude_super_admin() ) {
718 760 return NULL;
719 761 }
@@ -724,59 +766,53 @@
724 766 }
725 767
726 768 $user_roles = _mw_adminimize_get_all_user_roles();
727 769 $_mw_adminimize_admin_head = '';
728 - $disabled_global_option = array();
729 - $disabled_global_option_ = array();
730 - $user = wp_get_current_user();
731 770
732 - // Get settings for each role.
733 771 foreach ( $user_roles as $role ) {
734 - $disabled_global_option_[ $role ] = (array) _mw_adminimize_get_option_value(
772 + $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
735 773 'mw_adminimize_disabled_global_option_' . $role . '_items'
736 774 );
737 775 }
738 776
739 - // Write global options in an var.
740 777 foreach ( $user_roles as $role ) {
741 - if ( in_array( $role, $user->roles, TRUE ) && _mw_adminimize_current_user_has_role( $role ) ) {
778 + if ( ! isset( $disabled_global_option_[ $role ][ '0' ] ) ) {
779 + $disabled_global_option_[ $role ][ '0' ] = '';
780 + }
781 + }
742 782
743 - // Create array about all items with all affected roles, important for multiple roles.
744 - foreach ( (array) $disabled_global_option_[ $role ] as $global_item ) {
745 - $disabled_global_option[] = $global_item;
783 + $global_options = '';
784 + // new 1.7.8
785 + foreach ( $user_roles as $role ) {
786 + $user = wp_get_current_user();
787 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
788 + if ( _mw_adminimize_current_user_has_role( $role )
789 + && isset( $disabled_global_option_[ $role ] )
790 + && is_array( $disabled_global_option_[ $role ] )
791 + ) {
792 + $global_options = implode( ', ', $disabled_global_option_[ $role ] );
746 793 }
747 794 }
748 795 }
749 -
750 - // Support Multiple Roles for users.
751 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
752 - $disabled_global_option = _mw_adminimize_get_duplicate( $disabled_global_option );
753 - }
754 - $global_options = implode( ', ', $disabled_global_option );
755 -
756 - if ( 0 === strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
757 - global $_wp_admin_css_colors;
796 + if ( isset( $global_options ) && 0 != strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
758 797 $_wp_admin_css_colors = 0;
759 798 }
760 799 $_mw_adminimize_admin_head .= '<!-- Set Adminimize global options -->' . "\n";
761 800 $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display:none !important;}</style>' . "\n";
762 801
763 - // List options if the debug option is active.
764 - _mw_adminimize_debug($global_options, 'Adminimize: List active global options:');
765 -
766 - if ( '' !== $global_options ) {
802 + if ( ! empty( $global_options ) ) {
767 803 echo $_mw_adminimize_admin_head;
768 804 }
769 805 }
770 806
771 807 /**
772 - * Set metabox options from database an area post.
808 + * set metabox options from database an area post
773 809 */
774 810 function _mw_adminimize_set_metabox_post_option() {
775 811
776 812 // exclude super admin
777 813 if ( _mw_adminimize_exclude_super_admin() ) {
778 - return;
814 + return NULL;
779 815 }
780 816
781 817 // Leave the settings screen from Adminimize to see all areas on settings.
782 818 if ( _mw_adminimize_exclude_settings_page() ) {
@@ -784,10 +820,9 @@
784 820 }
785 821
786 822 $user_roles = _mw_adminimize_get_all_user_roles();
787 823 $_mw_adminimize_admin_head = '';
788 - // It's better to declare $metaboxes as an array for better manipulation later.
789 - $metaboxes = array();
824 + $metaboxes = '';
790 825
791 826 foreach ( $user_roles as $role ) {
792 827 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
793 828 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
@@ -792,42 +827,28 @@
792 827 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
793 828 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
794 829 );
795 830
796 - if ( ! isset( $disabled_metaboxes_post_[ $role ]['0'] ) ) {
797 - $disabled_metaboxes_post_[ $role ]['0'] = '';
798 -
799 - /**
800 - * @todo Think why keep going if $role does not even have boxes to hide? We may as well jump to the next $role.
801 - */
802 - continue;
831 + if ( ! isset( $disabled_metaboxes_post_[ $role ][ '0' ] ) ) {
832 + $disabled_metaboxes_post_[ $role ][ '0' ] = '';
803 833 }
804 834
805 - /**
806 - * @todo Think why call a function as we can use a global variable already declared by WordPress.
807 - * @var WP_User $user Instance of WP_User.
808 - * @since 1.7.8
809 - * @version 1.11.4
810 - */
811 - $user = $GLOBALS['current_user'];
812 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
835 + // new 1.7.8
836 + $user = wp_get_current_user();
837 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
813 838 if ( _mw_adminimize_current_user_has_role( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
814 - && is_array(
815 - $disabled_metaboxes_post_[ $role ]
816 - )
839 + && is_array(
840 + $disabled_metaboxes_post_[ $role ]
841 + )
817 842 ) {
818 - // The previous way $metaboxes was being filled it could be at some point non empty and empty afterwards.
819 - // For instance, if a $role has items to be hidden and the user has this $role, $metaboxes will be filled.
820 - // But in next loop $metaboxes may receive '' as the next $role might not have items to hide and the user might has the next $role.
821 - $metaboxes[] = implode( ',', $disabled_metaboxes_post_[ $role ] );
843 + $metaboxes = implode( ',', $disabled_metaboxes_post_[ $role ] );
822 844 }
823 845 }
824 846 }
825 847
826 848 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox post options -->' . "\n";
827 - // And below we implode $metaboxes because it's an array now.
828 849 $_mw_adminimize_admin_head .= '<style type="text/css">' .
829 - implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
850 + $metaboxes . ' {display:none !important;}</style>' . "\n";
830 851
831 852 if ( ! empty( $metaboxes ) ) {
832 853 echo $_mw_adminimize_admin_head;
833 854 }
@@ -833,9 +854,9 @@
833 854 }
834 855 }
835 856
836 857 /**
837 - * Set metabox options from database an area page.
858 + * set metabox options from database an area page
838 859 */
839 860 function _mw_adminimize_set_metabox_page_option() {
840 861
841 862 // exclude super admin
@@ -860,14 +881,14 @@
860 881 if ( ! isset( $disabled_metaboxes_page_[ $role ][ '0' ] ) ) {
861 882 $disabled_metaboxes_page_[ $role ][ '0' ] = '';
862 883 }
863 884
864 - // New since version 1.7.8.
885 + // new 1.7.8
865 886 $user = wp_get_current_user();
866 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
887 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
867 888 if ( _mw_adminimize_current_user_has_role( $role )
868 - && isset( $disabled_metaboxes_page_[ $role ] )
869 - && is_array( $disabled_metaboxes_page_[ $role ] )
889 + && isset( $disabled_metaboxes_page_[ $role ] )
890 + && is_array( $disabled_metaboxes_page_[ $role ] )
870 891 ) {
871 892 $metaboxes = implode( ',', $disabled_metaboxes_page_[ $role ] );
872 893 }
873 894 }
@@ -874,9 +895,9 @@
874 895 }
875 896
876 897 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox page options -->' . "\n";
877 898 $_mw_adminimize_admin_head .= '<style type="text/css">' .
878 - $metaboxes . ' {display:none !important;}</style>' . "\n";
899 + $metaboxes . ' {display:none !important;}</style>' . "\n";
879 900
880 901 if ( ! empty( $metaboxes ) ) {
881 902 echo $_mw_adminimize_admin_head;
882 903 }
@@ -882,9 +903,9 @@
882 903 }
883 904 }
884 905
885 906 /**
886 - * Set metabox options from database an area post.
907 + * set metabox options from database an area post
887 908 */
888 909 function _mw_adminimize_set_metabox_cp_option() {
889 910
890 911 // exclude super admin
@@ -896,13 +917,14 @@
896 917 if ( _mw_adminimize_exclude_settings_page() ) {
897 918 return;
898 919 }
899 920
900 - $post_id = 0;
901 921 if ( isset( $_GET[ 'post' ] ) ) {
902 922 $post_id = (int) $_GET[ 'post' ];
903 923 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
904 924 $post_id = (int) $_POST[ 'post_ID' ];
925 + } else {
926 + $post_id = 0;
905 927 }
906 928
907 929 $current_post_type = $GLOBALS[ 'post_type' ];
908 930 if ( ! isset( $current_post_type ) ) {
@@ -919,9 +941,9 @@
919 941 }
920 942
921 943 $user_roles = _mw_adminimize_get_all_user_roles();
922 944 $_mw_adminimize_admin_head = '';
923 - $metaboxes = array();
945 + $metaboxes = '';
924 946
925 947 foreach ( $user_roles as $role ) {
926 948 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
927 949 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
@@ -926,21 +948,19 @@
926 948 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
927 949 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
928 950 );
929 951
930 - if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] ) ) {
931 - $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] = '';
932 -
933 - continue;
952 + if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] ) ) {
953 + $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] = '';
934 954 }
935 955
936 - $user = $GLOBALS['current_user'];
937 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
956 + $user = wp_get_current_user();
957 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
938 958 if ( _mw_adminimize_current_user_has_role( $role )
939 - && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
940 - && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
959 + && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
960 + && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
941 961 ) {
942 - $metaboxes[] = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
962 + $metaboxes = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
943 963 }
944 964 }
945 965 }
946 966
@@ -945,9 +965,9 @@
945 965 }
946 966
947 967 $_mw_adminimize_admin_head .= '<!-- Set Adminimize post options -->' . "\n";
948 968 $_mw_adminimize_admin_head .= '<style type="text/css">' .
949 - implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
969 + $metaboxes . ' {display:none !important;}</style>' . "\n";
950 970
951 971 if ( ! empty( $metaboxes ) ) {
952 972 echo $_mw_adminimize_admin_head;
953 973 }
@@ -953,9 +973,9 @@
953 973 }
954 974 }
955 975
956 976 /**
957 - * Set link options in area links of back end.
977 + * set link options in area Links of Backend
958 978 */
959 979 function _mw_adminimize_set_link_option() {
960 980
961 981 // exclude super admin
@@ -983,11 +1003,12 @@
983 1003 }
984 1004 }
985 1005
986 1006 $link_options = '';
1007 + // new 1.7.8
987 1008 foreach ( $user_roles as $role ) {
988 1009 $user = wp_get_current_user();
989 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1010 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
990 1011 if ( _mw_adminimize_current_user_has_role( $role )
991 1012 && isset( $disabled_link_option_[ $role ] )
992 1013 && is_array( $disabled_link_option_[ $role ] )
993 1014 ) {
@@ -997,9 +1018,9 @@
997 1018 }
998 1019
999 1020 $_mw_adminimize_admin_head .= '<!-- Set Adminimize links options -->' . "\n";
1000 1021 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1001 - $link_options . ' {display:none !important;}</style>' . "\n";
1022 + $link_options . ' {display:none !important;}</style>' . "\n";
1002 1023
1003 1024 if ( ! empty( $link_options ) ) {
1004 1025 echo $_mw_adminimize_admin_head;
1005 1026 }
@@ -1005,9 +1026,9 @@
1005 1026 }
1006 1027 }
1007 1028
1008 1029 /**
1009 - * Remove objects on wp nav menu.
1030 + * remove objects on wp nav menu
1010 1031 */
1011 1032 function _mw_adminimize_set_nav_menu_option() {
1012 1033
1013 1034 // exclude super admin
@@ -1035,11 +1056,12 @@
1035 1056 }
1036 1057 }
1037 1058
1038 1059 $nav_menu_options = '';
1060 + // new 1.7.8
1039 1061 foreach ( $user_roles as $role ) {
1040 1062 $user = wp_get_current_user();
1041 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1063 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
1042 1064 if ( _mw_adminimize_current_user_has_role( $role )
1043 1065 && isset( $disabled_nav_menu_option_[ $role ] )
1044 1066 && is_array( $disabled_nav_menu_option_[ $role ] )
1045 1067 ) {
@@ -1046,12 +1068,13 @@
1046 1068 $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
1047 1069 }
1048 1070 }
1049 1071 }
1072 + //remove_meta_box( $id, 'nav-menus', 'side' );
1050 1073
1051 1074 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
1052 1075 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1053 - $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1076 + $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1054 1077
1055 1078 if ( $nav_menu_options ) {
1056 1079 echo $_mw_adminimize_admin_head;
1057 1080 }
@@ -1087,11 +1110,12 @@
1087 1110 }
1088 1111 }
1089 1112
1090 1113 $widget_options = '';
1114 + // new 1.7.8
1091 1115 foreach ( $user_roles as $role ) {
1092 1116 $user = wp_get_current_user();
1093 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1117 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
1094 1118 if ( _mw_adminimize_current_user_has_role( $role )
1095 1119 && isset( $disabled_widget_option_[ $role ] )
1096 1120 && is_array( $disabled_widget_option_[ $role ] )
1097 1121 ) {
@@ -1098,12 +1122,13 @@
1098 1122 $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
1099 1123 }
1100 1124 }
1101 1125 }
1126 + //remove_meta_box( $id, 'nav-menus', 'side' );
1102 1127
1103 1128 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1104 1129 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1105 - $widget_options . ' {display: none !important;}</style>' . "\n";
1130 + $widget_options . ' {display: none !important;}</style>' . "\n";
1106 1131
1107 1132 if ( $widget_options ) {
1108 1133 echo $_mw_adminimize_admin_head;
1109 1134 }
@@ -1109,9 +1134,9 @@
1109 1134 }
1110 1135 }
1111 1136
1112 1137 /**
1113 - * Print small user-info.
1138 + * small user-info
1114 1139 */
1115 1140 function _mw_adminimize_small_user_info() {
1116 1141
1117 1142 ?>
@@ -1126,15 +1151,13 @@
1126 1151 </div>
1127 1152 <?php
1128 1153 }
1129 1154
1155 +// Include message class.
1156 +require_once 'inc-setup/messages.php';
1130 1157 // include helping functions
1131 -require_once 'inc-setup/DebugListener.php';
1132 1158 require_once 'inc-setup/helping_hands.php';
1133 1159
1134 -// Include message class.
1135 -require_once 'inc-setup/messages.php';
1136 -
1137 1160 // inc. settings page
1138 1161 require_once 'adminimize_page.php';
1139 1162
1140 1163 // dashboard options
@@ -1141,11 +1164,14 @@
1141 1164 require_once 'inc-setup/dashboard.php';
1142 1165
1143 1166 // widget options
1144 1167 require_once 'inc-setup/widget.php';
1145 -require_once 'inc-setup/footer.php';
1146 1168 require_once 'inc-setup/admin-footer.php';
1147 1169
1170 +// global settings
1171 +// @TODO Testing, not ready for productive
1172 +//require_once( 'inc-options/settings_notice.php' );
1173 +
1148 1174 // remove admin bar
1149 1175 require_once 'inc-setup/remove-admin-bar.php';
1150 1176
1151 1177 // admin bar helper, setup
@@ -1158,19 +1184,15 @@
1158 1184
1159 1185 // Remove Admin Notices.
1160 1186 require_once 'inc-setup/remove-admin-notices.php';
1161 1187
1162 -// Add Ex-Import functions.
1163 -require_once 'inc-setup/export.php';
1164 -require_once 'inc-setup/import.php';
1165 -
1166 1188 /**
1167 1189 * Add action link(s) to plugins page
1168 1190 *
1169 - * @param array $links
1170 - * @param string $file
1191 + * @param $links , $file
1192 + * @param $file
1171 1193 *
1172 - * @return array $links
1194 + * @return $links
1173 1195 */
1174 1196 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1175 1197
1176 1198 /* create link */
@@ -1176,12 +1198,9 @@
1176 1198 /* create link */
1177 1199 if ( FB_ADMINIMIZE_BASENAME === $file ) {
1178 1200 array_unshift(
1179 1201 $links,
1180 - sprintf(
1181 - '<a href="options-general.php?page=adminimize-options">%s</a>',
1182 - esc_attr__( 'Settings' )
1183 - )
1202 + sprintf( '<a href="options-general.php?page=%s">%s</a>', FB_ADMINIMIZE_BASENAME, esc_attr__( 'Settings' ) )
1184 1203 );
1185 1204 }
1186 1205
1187 1206 return $links;
@@ -1187,9 +1206,9 @@
1187 1206 return $links;
1188 1207 }
1189 1208
1190 1209 /**
1191 - * Add settings in plugin-admin-page.
1210 + * settings in plugin-admin-page
1192 1211 */
1193 1212 function _mw_adminimize_add_settings_page() {
1194 1213
1195 1214 $pagehook = add_options_page(
@@ -1195,12 +1214,11 @@
1195 1214 $pagehook = add_options_page(
1196 1215 esc_attr__( 'Adminimize Options', 'adminimize' ),
1197 1216 esc_attr__( 'Adminimize', 'adminimize' ),
1198 1217 'manage_options',
1199 - 'adminimize-options',
1218 + __FILE__,
1200 1219 '_mw_adminimize_options'
1201 1220 );
1202 -
1203 1221 if ( ! is_network_admin() ) {
1204 1222 add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
1205 1223 }
1206 1224 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
@@ -1205,23 +1223,15 @@
1205 1223 }
1206 1224 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
1207 1225 }
1208 1226
1209 -/**
1210 - * Enqueue script and styles for the settings page.
1211 - */
1212 1227 function _mw_adminimize_on_load_page() {
1213 1228
1214 - // Load translation files on options page.
1215 - _mw_adminimize_textdomain();
1216 -
1217 1229 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1218 1230
1219 - wp_enqueue_style( 'select2-style', plugins_url( 'css/select2' . $suffix . '.css', __FILE__ ), [], false );
1220 1231 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1221 1232 wp_enqueue_style( 'adminimize-style' );
1222 1233
1223 - wp_enqueue_script( 'select2-script', plugins_url( 'js/select2' . $suffix . '.js', __FILE__ ), array( 'jquery' ),'',false );
1224 1234 wp_register_script(
1225 1235 'adminimize-settings-script',
1226 1236 plugins_url( 'js/adminimize' . $suffix . '.js', __FILE__ ),
1227 1237 array( 'jquery' ),
@@ -1231,35 +1241,52 @@
1231 1241 wp_enqueue_script( 'adminimize-settings-script' );
1232 1242 }
1233 1243
1234 1244 /**
1245 + * Set theme for users
1246 + * Kill with version 1.7.18
1247 + */
1248 +function _mw_adminimize_set_theme() {
1249 +
1250 + if ( ! current_user_can( 'edit_users' ) ) {
1251 + wp_die( esc_attr__( 'Cheatin&#8217; uh?' ) );
1252 + }
1253 +
1254 + $user_ids = $_POST[ 'mw_adminimize_theme_items' ];
1255 + $admin_color = htmlspecialchars( stripslashes( $_POST[ '_mw_adminimize_set_theme' ] ) );
1256 +
1257 + if ( ! $user_ids ) {
1258 + return FALSE;
1259 + }
1260 +
1261 + foreach ( $user_ids as $user_id ) {
1262 + update_user_meta( $user_id, 'admin_color', $admin_color );
1263 + }
1264 +
1265 + return TRUE;
1266 +}
1267 +
1268 +/**
1235 1269 * Get setting value for each options key.
1236 1270 *
1237 1271 * @param string|bool $key
1238 1272 *
1239 - * @return string
1273 + * @return array
1240 1274 */
1241 1275 function _mw_adminimize_get_option_value( $key = FALSE ) {
1242 1276
1243 - $adminimizeoptions = FALSE;
1244 - if ( ! _mw_adminimize_exclude_settings_page() ) {
1245 - $adminimizeoptions = wp_cache_get( 'mw_adminimize' );
1277 + // check for use on multisite
1278 + if ( _mw_adminimize_is_active_on_multisite() ) {
1279 + $adminimizeoptions = get_site_option( 'mw_adminimize', array() );
1280 + } else {
1281 + $adminimizeoptions = get_option( 'mw_adminimize', array() );
1246 1282 }
1247 1283
1248 - if ( FALSE === $adminimizeoptions ) {
1249 - // check for use on multisite
1250 - if ( _mw_adminimize_is_active_on_multisite() ) {
1251 - $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1252 - } else {
1253 - $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
1254 - }
1255 - wp_cache_set( 'mw_adminimize', $adminimizeoptions );
1256 - }
1257 -
1258 1284 if ( ! $key ) {
1259 1285 return $adminimizeoptions;
1260 1286 }
1261 1287
1288 + /** @var array $adminimizeoptions */
1262 1289 return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : NULL;
1263 1290 }
1264 1291
1265 1292 /**
@@ -1265,36 +1292,20 @@
1265 1292 /**
1266 1293 * Update options.
1267 1294 *
1268 1295 * @param array $options
1269 - *
1270 - * @return bool
1271 1296 */
1272 1297 function _mw_adminimize_update_option( $options ) {
1273 1298
1274 1299 if ( ! current_user_can( 'manage_options' ) ) {
1275 - return FALSE;
1300 + return;
1276 1301 }
1277 1302
1278 - if ( _mw_adminimize_is_roles_options_import( $options ) ){
1279 - $options = _mw_adminimize_roles_complete_options( $options );
1280 - }
1281 -
1282 - // Remove slashes always.
1283 - foreach ( $options as $key => $value ) {
1284 - $options[ $key ] = stripslashes_deep( $value );
1285 - }
1286 -
1287 - // Kill the cache for the settings page.
1288 - wp_cache_delete( 'mw_adminimize' );
1289 1303 if ( _mw_adminimize_is_active_on_multisite() ) {
1290 1304 update_site_option( 'mw_adminimize', $options );
1291 1305 } else {
1292 1306 update_option( 'mw_adminimize', $options );
1293 1307 }
1294 - wp_cache_add( 'mw_adminimize', $options );
1295 -
1296 - return TRUE;
1297 1308 }
1298 1309
1299 1310 /**
1300 1311 * Update options in database
@@ -1318,33 +1329,8 @@
1318 1329 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1319 1330 }
1320 1331 }
1321 1332
1322 - // Plugin Self Settings.
1323 - if ( isset( $_POST[ 'mw_adminimize_debug' ] ) ) {
1324 - $adminimizeoptions[ 'mw_adminimize_debug' ] = (int) $_POST[ 'mw_adminimize_debug' ];
1325 - } else {
1326 - $adminimizeoptions[ 'mw_adminimize_debug' ] = 0;
1327 - }
1328 -
1329 - if ( isset( $_POST[ 'mw_adminimize_multiple_roles' ] ) ) {
1330 - $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = (int) $_POST[ 'mw_adminimize_multiple_roles' ];
1331 - } else {
1332 - $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = 0;
1333 - }
1334 -
1335 - if ( isset( $_POST[ 'mw_adminimize_support_bbpress' ] ) ) {
1336 - $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = (int) $_POST[ 'mw_adminimize_support_bbpress' ];
1337 - } else {
1338 - $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = 0;
1339 - }
1340 -
1341 - if ( isset( $_POST[ 'mw_adminimize_prevent_page_access' ] ) ) {
1342 - $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = (int) $_POST[ 'mw_adminimize_prevent_page_access' ];
1343 - } else {
1344 - $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = 0;
1345 - }
1346 -
1347 1333 // Admin Bar Front end settings
1348 1334 $adminimizeoptions[ 'mw_adminimize_admin_bar_frontend_nodes' ] = _mw_adminimize_get_option_value(
1349 1335 'mw_adminimize_admin_bar_frontend_nodes'
1350 1336 );
@@ -1349,9 +1335,9 @@
1349 1335 'mw_adminimize_admin_bar_frontend_nodes'
1350 1336 );
1351 1337 // admin bar front end options
1352 1338 foreach ( $user_roles as $role ) {
1353 - // admin bar front-end options
1339 + // admin bar fron tend options
1354 1340 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] ) ) {
1355 1341 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ];
1356 1342 } else {
1357 1343 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = array();
@@ -1412,19 +1398,10 @@
1412 1398 $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
1413 1399 }
1414 1400
1415 1401 if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
1416 - $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = wp_kses(
1417 - $_POST[ '_mw_adminimize_advice_txt' ],
1418 - array(
1419 - 'a' => array(
1420 - 'href' => array(),
1421 - 'title' => array()
1422 - ),
1423 - 'br' => array(),
1424 - 'em' => array(),
1425 - 'strong' => array(),
1426 - )
1402 + $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = htmlspecialchars(
1403 + stripslashes( $_POST[ '_mw_adminimize_advice_txt' ] )
1427 1404 );
1428 1405 } else {
1429 1406 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = '';
1430 1407 }
@@ -1457,27 +1434,8 @@
1457 1434 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1458 1435 }
1459 1436 }
1460 1437
1461 - // @ToDo After release of WP 4.7, switch to sanitize_textarea_field()
1462 -
1463 - // own menu slug
1464 - if ( isset( $_POST[ '_mw_adminimize_own_menu_slug' ] ) ) {
1465 - $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = stripslashes(
1466 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_slug' ] )
1467 - );
1468 - } else {
1469 - $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = '';
1470 - }
1471 - // own custom menu slug
1472 - if ( isset( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] ) ) {
1473 - $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = stripslashes(
1474 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] )
1475 - );
1476 - } else {
1477 - $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = '';
1478 - }
1479 -
1480 1438 // global_options, metaboxes update
1481 1439 foreach ( $user_roles as $role ) {
1482 1440
1483 1441 // global options
@@ -1544,19 +1502,15 @@
1544 1502 }
1545 1503
1546 1504 // own options
1547 1505 if ( isset( $_POST[ '_mw_adminimize_own_values' ] ) ) {
1548 - $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes(
1549 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values' ] )
1550 - );
1506 + $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes( $_POST[ '_mw_adminimize_own_values' ] );
1551 1507 } else {
1552 1508 $adminimizeoptions[ '_mw_adminimize_own_values' ] = '';
1553 1509 }
1554 1510
1555 1511 if ( isset( $_POST[ '_mw_adminimize_own_options' ] ) ) {
1556 - $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes(
1557 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options' ] )
1558 - );
1512 + $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes( $_POST[ '_mw_adminimize_own_options' ] );
1559 1513 } else {
1560 1514 $adminimizeoptions[ '_mw_adminimize_own_options' ] = '';
1561 1515 }
1562 1516
@@ -1562,9 +1516,9 @@
1562 1516
1563 1517 // own post options
1564 1518 if ( isset( $_POST[ '_mw_adminimize_own_post_values' ] ) ) {
1565 1519 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = stripslashes(
1566 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_values' ] )
1520 + $_POST[ '_mw_adminimize_own_post_values' ]
1567 1521 );
1568 1522 } else {
1569 1523 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = '';
1570 1524 }
@@ -1570,9 +1524,9 @@
1570 1524 }
1571 1525
1572 1526 if ( isset( $_POST[ '_mw_adminimize_own_post_options' ] ) ) {
1573 1527 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = stripslashes(
1574 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_options' ] )
1528 + $_POST[ '_mw_adminimize_own_post_options' ]
1575 1529 );
1576 1530 } else {
1577 1531 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = '';
1578 1532 }
@@ -1579,9 +1533,9 @@
1579 1533
1580 1534 // own page options
1581 1535 if ( isset( $_POST[ '_mw_adminimize_own_page_values' ] ) ) {
1582 1536 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = stripslashes(
1583 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_values' ] )
1537 + $_POST[ '_mw_adminimize_own_page_values' ]
1584 1538 );
1585 1539 } else {
1586 1540 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = '';
1587 1541 }
@@ -1587,9 +1541,9 @@
1587 1541 }
1588 1542
1589 1543 if ( isset( $_POST[ '_mw_adminimize_own_page_options' ] ) ) {
1590 1544 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = stripslashes(
1591 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_options' ] )
1545 + $_POST[ '_mw_adminimize_own_page_options' ]
1592 1546 );
1593 1547 } else {
1594 1548 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = '';
1595 1549 }
@@ -1597,9 +1551,9 @@
1597 1551 // own custom post options
1598 1552 foreach ( $post_types as $post_type ) {
1599 1553 if ( isset( $_POST[ '_mw_adminimize_own_values_' . $post_type ] ) ) {
1600 1554 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = stripslashes(
1601 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values_' . $post_type ] )
1555 + $_POST[ '_mw_adminimize_own_values_' . $post_type ]
1602 1556 );
1603 1557 } else {
1604 1558 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = '';
1605 1559 }
@@ -1605,9 +1559,9 @@
1605 1559 }
1606 1560
1607 1561 if ( isset( $_POST[ '_mw_adminimize_own_options_' . $post_type ] ) ) {
1608 1562 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = stripslashes(
1609 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options_' . $post_type ] )
1563 + $_POST[ '_mw_adminimize_own_options_' . $post_type ]
1610 1564 );
1611 1565 } else {
1612 1566 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = '';
1613 1567 }
@@ -1615,9 +1569,9 @@
1615 1569
1616 1570 // own link options
1617 1571 if ( isset( $_POST[ '_mw_adminimize_own_link_values' ] ) ) {
1618 1572 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = stripslashes(
1619 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_values' ] )
1573 + $_POST[ '_mw_adminimize_own_link_values' ]
1620 1574 );
1621 1575 } else {
1622 1576 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = '';
1623 1577 }
@@ -1623,9 +1577,9 @@
1623 1577 }
1624 1578
1625 1579 if ( isset( $_POST[ '_mw_adminimize_own_link_options' ] ) ) {
1626 1580 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = stripslashes(
1627 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_options' ] )
1581 + $_POST[ '_mw_adminimize_own_link_options' ]
1628 1582 );
1629 1583 } else {
1630 1584 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = '';
1631 1585 }
@@ -1632,9 +1586,9 @@
1632 1586
1633 1587 // wp nav menu options
1634 1588 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_values' ] ) ) {
1635 1589 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = stripslashes(
1636 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_values' ] )
1590 + $_POST[ '_mw_adminimize_own_nav_menu_values' ]
1637 1591 );
1638 1592 } else {
1639 1593 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = '';
1640 1594 }
@@ -1640,9 +1594,9 @@
1640 1594 }
1641 1595
1642 1596 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_options' ] ) ) {
1643 1597 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = stripslashes(
1644 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_options' ] )
1598 + $_POST[ '_mw_adminimize_own_nav_menu_options' ]
1645 1599 );
1646 1600 } else {
1647 1601 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = '';
1648 1602 }
@@ -1649,9 +1603,9 @@
1649 1603
1650 1604 // widget options
1651 1605 if ( isset( $_POST[ '_mw_adminimize_own_widget_values' ] ) ) {
1652 1606 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = stripslashes(
1653 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_values' ] )
1607 + $_POST[ '_mw_adminimize_own_widget_values' ]
1654 1608 );
1655 1609 } else {
1656 1610 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = '';
1657 1611 }
@@ -1657,9 +1611,9 @@
1657 1611 }
1658 1612
1659 1613 if ( isset( $_POST[ '_mw_adminimize_own_widget_options' ] ) ) {
1660 1614 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = stripslashes(
1661 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_options' ] )
1615 + $_POST[ '_mw_adminimize_own_widget_options' ]
1662 1616 );
1663 1617 } else {
1664 1618 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = '';
1665 1619 }
@@ -1666,9 +1620,9 @@
1666 1620
1667 1621 // own dashboard options
1668 1622 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_values' ] ) ) {
1669 1623 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = stripslashes(
1670 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_values' ] )
1624 + $_POST[ '_mw_adminimize_own_dashboard_values' ]
1671 1625 );
1672 1626 } else {
1673 1627 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = '';
1674 1628 }
@@ -1674,9 +1628,9 @@
1674 1628 }
1675 1629
1676 1630 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_options' ] ) ) {
1677 1631 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = stripslashes(
1678 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_options' ] )
1632 + $_POST[ '_mw_adminimize_own_dashboard_options' ]
1679 1633 );
1680 1634 } else {
1681 1635 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = '';
1682 1636 }
@@ -1691,45 +1645,23 @@
1691 1645 if ( isset( $GLOBALS[ 'submenu' ] ) ) {
1692 1646 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1693 1647 }
1694 1648
1695 - /**
1696 - * Filter the adminimize options.
1697 - *
1698 - * Make the options filterable, so we can modify what is saved before it's sent to the db
1699 - *
1700 - * @since 1.11.6
1701 - *
1702 - * @param array $adminimizeoptions the original options.
1703 - * @param array $user_roles Array of the user roles.
1704 - * @param array $_POST Post data.
1705 - */
1706 - $adminimizeoptions = apply_filters( 'mw_adminimize_options_before_update', $adminimizeoptions, $user_roles, $_POST );
1707 -
1708 1649 // update
1709 - $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1650 + _mw_adminimize_update_option( $adminimizeoptions );
1710 1651
1711 1652 $myErrors = new _mw_adminimize_message_class();
1712 - if ( $update_status ) {
1713 - $message = $myErrors->get_error(
1653 + $myErrors = '<div id="message" class="updated fade"><p>' . $myErrors->get_error(
1714 1654 '_mw_adminimize_update'
1715 - );
1716 - } else {
1717 - $message = $myErrors->get_error(
1718 - '_mw_adminimize_access_denied'
1719 - );
1720 - }
1721 - echo '<div id="message" class="notice notice-success"><p>' . $message . '</p></div>';
1722 -
1723 - return TRUE;
1655 + ) . '</p></div>';
1656 + echo $myErrors;
1724 1657 }
1725 1658
1726 1659 /**
1727 1660 * Delete options in database
1728 1661 */
1729 -function _mw_adminimize_uninstall() {
1662 +function _mw_adminimize_deinstall() {
1730 1663
1731 - wp_cache_delete( 'mw_adminimize' );
1732 1664 delete_site_option( 'mw_adminimize' );
1733 1665 delete_option( 'mw_adminimize' );
1734 1666 }
1735 1667
@@ -1738,16 +1670,11 @@
1738 1670 */
1739 1671 function _mw_adminimize_install() {
1740 1672
1741 1673 if ( ! is_admin() ) {
1742 - return;
1674 + return NULL;
1743 1675 }
1744 1676
1745 - // If is AJAX Call.
1746 - if ( defined('DOING_AJAX') && DOING_AJAX ) {
1747 - return;
1748 - }
1749 -
1750 1677 global $menu, $submenu;
1751 1678
1752 1679 $user_roles = _mw_adminimize_get_all_user_roles();
1753 1680 $adminimizeoptions = array();
@@ -1775,55 +1702,71 @@
1775 1702 add_site_option( 'mw_adminimize', $adminimizeoptions );
1776 1703 } else {
1777 1704 add_option( 'mw_adminimize', $adminimizeoptions );
1778 1705 }
1779 - wp_cache_add( 'mw_adminimize', $adminimizeoptions );
1780 1706 }
1781 1707
1782 1708 /**
1783 - * Make sure adminimize option is complete when a role json file is imported
1784 - *
1785 - * @param array $roles_options
1786 - *
1787 - * @return array
1709 + * Process a settings export that generates a .json file of the shop settings
1788 1710 */
1789 -function _mw_adminimize_roles_complete_options( $roles_options ){
1711 +function _mw_adminimize_export_json() {
1790 1712
1791 - $adminimizeoption = _mw_adminimize_get_option_value();
1713 + if ( empty( $_GET[ '_mw_adminimize_export' ] ) || 'true' !== $_GET[ '_mw_adminimize_export' ] ) {
1714 + return;
1715 + }
1792 1716
1793 - foreach ( $roles_options as $role_option_name => $role_option_value ){
1794 - $adminimizeoption[$role_option_name] = $role_option_value;
1717 + require_once ABSPATH . 'wp-includes/pluggable.php';
1718 + if ( ! wp_verify_nonce( $_GET[ 'mw_adminimize_export_nonce' ], 'mw_adminimize_export_nonce' ) ) {
1719 + return;
1795 1720 }
1796 1721
1797 - return $adminimizeoption;
1722 + if ( ! current_user_can( 'manage_options' ) ) {
1723 + return;
1724 + }
1725 +
1726 + $settings = _mw_adminimize_get_option_value();
1727 +
1728 + ignore_user_abort( TRUE );
1729 +
1730 + nocache_headers();
1731 + header( 'Content-Type: application/json; charset=utf-8' );
1732 + header( 'Content-Disposition: attachment; filename=mw_adminimize-settings-export-' . date( 'm-d-Y' ) . '.json' );
1733 + header( 'Expires: 0' );
1734 +
1735 + echo json_encode( $settings );
1736 + exit();
1798 1737 }
1799 1738
1800 1739 /**
1801 - * Check if options comes from roles adminimize settings export
1802 - *
1803 - * @param array $options
1804 - *
1805 - * @return bool
1740 + * Process a settings import from a json file
1806 1741 */
1807 -function _mw_adminimize_is_roles_options_import( $options ){
1808 - global $wp_roles;
1742 +function _mw_adminimize_import_json() {
1809 1743
1810 - $roles_options = [];
1811 - foreach ( $wp_roles->role_names as $role_slug => $role_name ){
1744 + if ( empty( $_POST[ '_mw_adminimize_action' ] ) || '_mw_adminimize_import' !== $_POST[ '_mw_adminimize_action' ] ) {
1745 + return;
1746 + }
1812 1747
1813 - $role_options = array_filter(
1814 - $options, function ( $option_key ) use ( $role_slug ) {
1815 - return stripos( $option_key, '_' . $role_slug ) !== false;
1816 - }, ARRAY_FILTER_USE_KEY
1817 - );
1748 + if ( ! wp_verify_nonce( $_POST[ 'mw_adminimize_import_nonce' ], 'mw_adminimize_import_nonce' ) ) {
1749 + return;
1750 + }
1818 1751
1819 - if ( empty( $roles_options ) ){
1820 - $roles_options = $role_options;
1821 - } else {
1822 - $roles_options = array_merge( $roles_options, $role_options );
1823 - }
1752 + if ( ! current_user_can( 'manage_options' ) ) {
1753 + return;
1824 1754 }
1825 1755
1826 - if ( count( $options ) === count( $roles_options ) ){
1827 - return true;
1756 + $extension = pathinfo( $_FILES[ 'import_file' ][ 'name' ], PATHINFO_EXTENSION );
1757 + if ( $extension !== 'json' ) {
1758 + wp_die( esc_attr__( 'Please upload a valid .json file' ) );
1828 1759 }
1760 +
1761 + $import_file = $_FILES[ 'import_file' ][ 'tmp_name' ];
1762 +
1763 + if ( empty( $import_file ) ) {
1764 + wp_die( esc_attr__( 'Please upload a file to import' ) );
1765 + }
1766 +
1767 + // Retrieve the settings from the file and convert the json object to an array.
1768 + $settings = (array) json_decode( file_get_contents( $import_file ) );
1769 + unlink( $import_file );
1770 +
1771 + _mw_adminimize_update_option( $settings );
1829 1772 }