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 +399 -352 1.11.3 → 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.3
11 - * License: GPLv3+
10 + * Version: 1.9.1
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 2017-11-16
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,32 +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 - $screen = $page;
112 - if ( function_exists( 'get_current_screen' ) ) {
113 - $screen = get_current_screen();
114 - }
115 -
116 - if ( isset( $screen->id ) ) {
117 - $screen = $screen->id;
118 - }
119 -
120 - // Don't filter on settings page
121 - return FALSE !== strpos( $screen, 'adminimize' );
101 + return FALSE;
122 102 }
123 103
124 104 /**
125 105 * Get status, if the plugin active network wide.
@@ -128,12 +108,12 @@
128 108 */
129 109 function _mw_adminimize_is_active_on_multisite() {
130 110
131 111 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
132 - require_once ABSPATH . '/wp-admin/includes/plugin.php';
112 + require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
133 113 }
134 114
135 - if ( is_multisite() && is_plugin_active_for_network( FB_ADMINIMIZE_BASENAME ) ) {
115 + if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
136 116 return TRUE;
137 117 }
138 118
139 119 return FALSE;
@@ -147,27 +127,25 @@
147 127 * @return array $user_roles
148 128 */
149 129 function _mw_adminimize_get_all_user_roles() {
150 130
151 - /** @var $wp_roles WP_Roles */
152 131 global $wp_roles;
153 132
154 133 $user_roles = array();
155 134
156 135 if ( NULL !== $wp_roles->roles && is_array( $wp_roles->roles ) ) {
136 + /** @var array $wp_roles */
157 137 foreach ( $wp_roles->roles as $role => $data ) {
158 138 $user_roles[] = $role;
159 - // The $data var contains caps, maybe for later use.
139 + //$data contains caps, maybe for later use..
160 140 }
161 141 }
162 142
163 143 // Exclude the new bbPress roles.
164 - if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
165 - $user_roles = array_diff(
166 - $user_roles,
167 - array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
168 - );
169 - }
144 + $user_roles = array_diff(
145 + $user_roles,
146 + array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
147 + );
170 148
171 149 return $user_roles;
172 150 }
173 151
@@ -179,55 +157,56 @@
179 157 * @return array $user_roles_names
180 158 */
181 159 function _mw_adminimize_get_all_user_roles_names() {
182 160
183 - /** @var $wp_roles WP_Roles */
184 161 global $wp_roles;
162 +
185 163 $user_roles_names = array();
186 164
165 + /** @var array $wp_roles */
187 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 + }
188 172
189 - $data = translate_user_role( $data );
190 173 $user_roles_names[] = $data;
191 174 }
192 175
193 176 // exclude the new bbPress roles
194 - if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
195 - $user_roles_names = array_diff(
196 - $user_roles_names,
197 - array(
198 - esc_attr__( 'Keymaster', 'bbpress' ),
199 - esc_attr__( 'Moderator', 'bbpress' ),
200 - esc_attr__( 'Participant', 'bbpress' ),
201 - esc_attr__( 'Spectator', 'bbpress' ),
202 - esc_attr__( 'Blocked', 'bbpress' ),
203 - )
204 - );
205 - }
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 + );
206 187
207 188 return $user_roles_names;
208 189 }
209 190
210 191 /**
211 - * Get post type.
212 - *
213 - * @return null|string String of the post type.
192 + * return post type
214 193 */
215 -function _mw_adminimize_get_current_post_type() {
194 +function _mw_get_current_post_type() {
216 195
217 196 global $post, $typenow, $current_screen;
218 197
219 - // 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
220 199 if ( $post && $post->post_type ) {
221 200 return $post->post_type;
222 - } // Check the global $typenow - set in admin.php
223 - elseif ( $typenow ) {
201 + } //check the global $typenow - set in admin.php
202 + else if ( $typenow ) {
224 203 return $typenow;
225 204 } // check the global $current_screen object - set in sceen.php
226 - elseif ( $current_screen && $current_screen->post_type ) {
205 + else if ( $current_screen && $current_screen->post_type ) {
227 206 return $current_screen->post_type;
228 207 } // lastly check the post_type querystring
229 - elseif ( isset( $_REQUEST[ 'post_type' ] ) ) {
208 + else if ( isset( $_REQUEST[ 'post_type' ] ) ) {
230 209 return sanitize_key( $_REQUEST[ 'post_type' ] );
231 210 }
232 211
233 212 // we do not know the post type!
@@ -240,13 +219,14 @@
240 219 function _mw_adminimize_admin_init() {
241 220
242 221 global $pagenow, $post_type, $menu, $submenu;
243 222
244 - $post_id = 0;
245 223 if ( isset( $_GET[ 'post' ] ) && ! is_array( $_GET[ 'post' ] ) ) {
246 224 $post_id = (int) esc_attr( $_GET[ 'post' ] );
247 225 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
248 226 $post_id = (int) esc_attr( $_POST[ 'post_ID' ] );
227 + } else {
228 + $post_id = 0;
249 229 }
250 230
251 231 $current_post_type = $post_type;
252 232 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
@@ -252,15 +232,16 @@
252 232 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
253 233 $current_post_type = get_post_type( $post_id );
254 234 }
255 235 if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
256 - $current_post_type = _mw_adminimize_get_current_post_type();
236 + $current_post_type = _mw_get_current_post_type();
257 237 }
258 - if ( ! $current_post_type ) { // set hard to post
238 + if ( ! $current_post_type ) // set hard to post
239 + {
259 240 $current_post_type = 'post';
260 241 }
261 242
262 - // Get all user roles.
243 + // Get all user rolles.
263 244 $user_roles = _mw_adminimize_get_all_user_roles();
264 245
265 246 // Get settings.
266 247 $adminimizeoptions = _mw_adminimize_get_option_value();
@@ -284,9 +265,9 @@
284 265 // widget pages
285 266 $widget_pages = array( 'widgets.php' );
286 267
287 268 foreach ( $user_roles as $role ) {
288 - $disabled_admin_bar_[ $role ] = _mw_adminimize_get_option_value(
269 + $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
289 270 'mw_adminimize_disabled_admin_bar_' . $role . '_items'
290 271 );
291 272 $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
292 273 'mw_adminimize_disabled_global_option_' . $role . '_items'
@@ -316,11 +297,21 @@
316 297 }
317 298
318 299 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
319 300
320 - // Backend options
301 + // global options
321 302 // exclude super admin
322 - 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 + }
323 314
324 315 $_mw_adminimize_header = (int) _mw_adminimize_get_option_value( '_mw_adminimize_header' );
325 316 switch ( $_mw_adminimize_header ) {
326 317 case 1:
@@ -331,10 +322,10 @@
331 322 );
332 323 break;
333 324 }
334 325
335 - // Post-page options.
336 - if ( in_array( $pagenow, $def_post_pages, TRUE ) ) {
326 + //post-page options
327 + if ( in_array( $pagenow, $def_post_pages, FALSE ) ) {
337 328
338 329 $_mw_adminimize_tb_window = (int) _mw_adminimize_get_option_value( '_mw_adminimize_tb_window' );
339 330 switch ( $_mw_adminimize_tb_window ) {
340 331 case 1:
@@ -356,9 +347,9 @@
356 347 );
357 348 break;
358 349 }
359 350
360 - // Category options.
351 + //category options
361 352 $_mw_adminimize_cat_full = (int) _mw_adminimize_get_option_value( '_mw_adminimize_cat_full' );
362 353 switch ( $_mw_adminimize_cat_full ) {
363 354 case 1:
364 355 wp_enqueue_style(
@@ -367,9 +358,9 @@
367 358 );
368 359 break;
369 360 }
370 361
371 - // Set default editor tinymce
362 + // set default editor tinymce
372 363 if ( _mw_adminimize_recursive_in_array(
373 364 '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
374 365 $disabled_metaboxes_page_all
375 366 )
@@ -377,17 +368,12 @@
377 368 '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
378 369 $disabled_metaboxes_post_all
379 370 )
380 371 ) {
381 - add_filter(
382 - 'wp_default_editor',
383 - function() {
384 - return 'tinymce';
385 - }
386 - );
372 + add_filter( 'wp_default_editor', create_function( '', 'return "tinymce";' ) );
387 373 }
388 374
389 - // Remove media buttons
375 + // remove media bottons
390 376 if ( _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_page_all )
391 377 || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
392 378 ) {
393 379 remove_action( 'media_buttons', 'media_buttons' );
@@ -392,53 +378,77 @@
392 378 ) {
393 379 remove_action( 'media_buttons', 'media_buttons' );
394 380 }
395 381 }
382 +
396 383 }
397 384
398 - // set meta-box post option
399 - 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 ) ) {
400 392 add_action( 'admin_head', '_mw_adminimize_set_metabox_post_option', 1 );
401 393 }
402 - // set meta-box page option
403 - 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 ) ) {
404 396 add_action( 'admin_head', '_mw_adminimize_set_metabox_page_option', 1 );
405 397 }
406 398 // set custom post type options
407 - if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages, TRUE )
408 - && 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 + )
409 403 ) {
410 404 add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
411 405 }
412 406 // set link option
413 - if ( in_array( $pagenow, $link_pages, TRUE ) ) {
407 + if ( in_array( $pagenow, $link_pages, FALSE ) ) {
414 408 add_action( 'admin_head', '_mw_adminimize_set_link_option', 1 );
415 409 }
416 410 // set wp nav menu options
417 - if ( in_array( $pagenow, $nav_menu_pages, TRUE ) ) {
411 + if ( in_array( $pagenow, $nav_menu_pages, FALSE ) ) {
418 412 add_action( 'admin_head', '_mw_adminimize_set_nav_menu_option', 1 );
419 413 }
420 414 // set widget options
421 - if ( in_array( $pagenow, $widget_pages, TRUE ) ) {
415 + if ( in_array( $pagenow, $widget_pages, FALSE ) ) {
422 416 add_action( 'admin_head', '_mw_adminimize_set_widget_option', 1 );
423 417 }
418 +
419 + $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
420 + $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
424 421 }
425 422
426 -// Change menu via settings of Adminimize.
427 -add_action( 'custom_menu_order', '_mw_adminimize_set_menu_option', 99999 );
423 +/**
424 + * Init always with WP
425 + */
426 +function _mw_adminimize_init() {
428 427
429 -// global_options
430 -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 +
431 438 // on admin init
439 +define( 'MW_ADMIN_FILE', plugin_basename( __FILE__ ) );
432 440 if ( is_admin() ) {
433 - 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 );
434 443 add_action( 'admin_menu', '_mw_adminimize_add_settings_page' );
435 444 add_action( 'admin_menu', '_mw_adminimize_remove_dashboard' );
436 445 }
437 -add_action( 'init', '_mw_adminimize_set_logout_menu', 2 );
446 +add_action( 'init', '_mw_adminimize_init', 2 );
438 447
439 448 register_activation_hook( __FILE__, '_mw_adminimize_install' );
440 -register_uninstall_hook( __FILE__, '_mw_adminimize_uninstall' );
449 +register_uninstall_hook( __FILE__, '_mw_adminimize_deinstall' );
450 +//register_deactivation_hook(__FILE__, '_mw_adminimize_deinstall' );
441 451
442 452 /**
443 453 * Remove the dashboard
444 454 */
@@ -455,17 +465,17 @@
455 465 }
456 466
457 467 global $menu, $user_ID;
458 468
459 - $disabled_menu_ = array();
460 - $disabled_submenu_ = array();
469 + $disabled_menu_ = '';
470 + $disabled_submenu_ = '';
461 471 $user_roles = _mw_adminimize_get_all_user_roles();
462 472
463 473 foreach ( $user_roles as $role ) {
464 - $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
474 + $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
465 475 'mw_adminimize_disabled_menu_' . $role . '_items'
466 476 );
467 - $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
477 + $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
468 478 'mw_adminimize_disabled_submenu_' . $role . '_items'
469 479 );
470 480 }
471 481
@@ -490,9 +500,9 @@
490 500 }
491 501 }
492 502 }
493 503
494 - // Redirect option, if Dashboard is inactive
504 + // redirect option, if Dashboard is inactive
495 505 if ( $redirect ) {
496 506 $_mw_adminimize_db_redirect = (int) _mw_adminimize_get_option_value(
497 507 '_mw_adminimize_db_redirect'
498 508 );
@@ -527,14 +537,14 @@
527 537
528 538 $dashboard_core_string = esc_attr__( 'Dashboard' );
529 539 $dashboard = array( $menu[ $page ][ 0 ], $menu[ $page ][ 1 ] );
530 540 while (
531 - ! in_array( $dashboard_core_string, $dashboard, TRUE ) && next( $menu )
541 + ! in_array( $dashboard_core_string, $dashboard, FALSE ) && next( $menu )
532 542 ) {
533 543 $page = key( $menu );
534 544 }
535 545
536 - if ( in_array( $dashboard_core_string, $dashboard, TRUE ) ) {
546 + if ( in_array( $dashboard_core_string, $dashboard, FALSE ) ) {
537 547 unset( $menu[ $page ] );
538 548 }
539 549 reset( $menu );
540 550 $page = key( $menu );
@@ -543,15 +553,112 @@
543 553 $page = key( $menu );
544 554 }
545 555
546 556 if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER[ 'REQUEST_URI' ] ) ) {
547 - wp_safe_redirect( $_mw_adminimize_db_redirect );
557 + wp_redirect( $_mw_adminimize_db_redirect );
548 558 }
549 559 }
560 +
550 561 }
551 562 }
552 563
553 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 +/**
554 661 * Set menu for settings
555 662 */
556 663 function _mw_adminimize_set_menu_option() {
557 664
@@ -570,22 +677,17 @@
570 677 if ( ! isset( $menu ) || empty( $menu ) ) {
571 678 return;
572 679 }
573 680
574 - _mw_adminimize_debug( $menu, 'Adminimize, WordPress Menu:' );
575 - _mw_adminimize_debug( $submenu, 'Adminimize, WordPress Sub-Menu:' );
681 + $user_roles = _mw_adminimize_get_all_user_roles();
682 + $disabled_menu_ = '';
683 + $disabled_submenu_ = '';
576 684
577 - $disabled_menu_ = array();
578 - $disabled_submenu_ = array();
579 - $user = wp_get_current_user();
580 - $user_roles = $user->roles;
581 - _mw_adminimize_debug( $user, 'Adminimize, Current User:' );
582 -
583 685 foreach ( $user_roles as $role ) {
584 - $disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
686 + $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
585 687 'mw_adminimize_disabled_menu_' . $role . '_items'
586 688 );
587 - $disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
689 + $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
588 690 'mw_adminimize_disabled_submenu_' . $role . '_items'
589 691 );
590 692 }
591 693
@@ -593,69 +695,52 @@
593 695 $mw_adminimize_submenu = array();
594 696
595 697 // Set admin-menu.
596 698 foreach ( $user_roles as $role ) {
597 - if ( in_array( $role, $user->roles, TRUE )
598 - && _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 + )
599 706 ) {
600 - // Create array about all items with all affected roles.
601 - foreach ( (array) $disabled_menu_[ $role ] as $menu_item ) {
602 - $mw_adminimize_menu[] = $menu_item;
603 - }
604 - foreach ( (array) $disabled_submenu_[ $role ] as $submenu_item ) {
605 - $mw_adminimize_submenu[] = $submenu_item;
606 - }
707 + $mw_adminimize_menu = $disabled_menu_[ $role ];
708 + $mw_adminimize_submenu = $disabled_submenu_[ $role ];
607 709 }
608 710 }
609 711
610 - // Support Multiple Roles for users.
611 - // Leave only the items, there are active on each roles of the users.
612 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
613 - $mw_adminimize_menu = _mw_adminimize_get_intersection( $disabled_menu_ );
614 - $mw_adminimize_submenu = _mw_adminimize_get_intersection( $disabled_submenu_ );
615 - } else {
616 - // Alternative filter the array to remove duplicates, much faster.
617 - $mw_adminimize_menu = array_unique( $mw_adminimize_menu );
618 - $mw_adminimize_submenu = array_unique( $mw_adminimize_submenu );
619 - }
620 - _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Menu Slugs to hide after Filter.' );
621 - _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Sub-Menu Slugs to hide after Filter.' );
622 -
623 - /**
624 - * @ToDo Remove it after feedback from users.
625 - *
626 712 // Fallback on users.php on all user roles smaller admin.
627 - if ( in_array( 'users.php', $mw_adminimize_menu, TRUE ) ) {
713 + if ( is_array( $mw_adminimize_menu ) && in_array( 'users.php', $mw_adminimize_menu, FALSE ) ) {
628 714 $mw_adminimize_menu[] = 'profile.php';
629 715 }
630 - */
631 - foreach ( $menu as $key => $item ) {
632 716
633 - // Menu
717 + foreach ( $menu as $index => $item ) {
718 +
719 + if ( 'index.php' === $item ) {
720 + continue;
721 + }
722 +
634 723 if ( isset( $item[ 2 ] ) ) {
635 - $menu_slug = $item[ 2 ];
636 - // Check, if the Menu item in the current user role settings?
637 - if ( in_array( $menu_slug, $mw_adminimize_menu, TRUE )
724 + if ( isset( $mw_adminimize_menu ) && is_array( $mw_adminimize_menu )
725 + && in_array(
726 + $item[ 2 ], $mw_adminimize_menu, FALSE
727 + )
638 728 ) {
639 - remove_menu_page( $menu_slug );
640 - // Prevent access to the page with the slug, there was inactive.
641 - _mw_adminimize_check_page_access( $menu_slug );
729 + unset( $menu[ $index ] );
642 730 }
643 731
644 - // Sub Menu Settings.
645 - if ( isset( $submenu ) && ! empty( $submenu[ $menu_slug ] ) ) {
646 - foreach ( (array) $submenu[ $menu_slug ] as $subindex => $subitem ) {
647 - // 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?
648 735 if (
649 736 isset( $mw_adminimize_submenu )
650 737 && _mw_adminimize_in_arrays(
651 - array( $subitem[ 2 ], $menu_slug . '__' . $subindex ),
738 + array( $subitem[ 2 ], $item[ 2 ] . '__' . $subindex ),
652 739 $mw_adminimize_submenu
653 740 )
654 741 ) {
655 - remove_submenu_page( $menu_slug, $subitem[ 2 ] );
656 - // Prevent access to the page with the slug, there was inactive.
657 - _mw_adminimize_check_page_access( $subitem[ 2 ] );
742 + unset( $submenu[ $item[ 2 ] ][ $subindex ] );
658 743 }
659 744 }
660 745 }
661 746 }
@@ -663,12 +748,14 @@
663 748
664 749 }
665 750
666 751 /**
667 - * Set global options in backend in all areas.
752 + * set global options in backend in all areas
668 753 */
669 754 function _mw_adminimize_set_global_option() {
670 755
756 + global $_wp_admin_css_colors;
757 +
671 758 // exclude super admin
672 759 if ( _mw_adminimize_exclude_super_admin() ) {
673 760 return NULL;
674 761 }
@@ -679,56 +766,53 @@
679 766 }
680 767
681 768 $user_roles = _mw_adminimize_get_all_user_roles();
682 769 $_mw_adminimize_admin_head = '';
683 - $disabled_global_option = array();
684 - $disabled_global_option_ = array();
685 - $user = wp_get_current_user();
686 770
687 - // Get settings for each role.
688 771 foreach ( $user_roles as $role ) {
689 - $disabled_global_option_[ $role ] = (array) _mw_adminimize_get_option_value(
772 + $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
690 773 'mw_adminimize_disabled_global_option_' . $role . '_items'
691 774 );
692 775 }
693 776
694 - // Write global options in an var.
695 777 foreach ( $user_roles as $role ) {
696 - 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 + }
697 782
698 - // Create array about all items with all affected roles, important for multiple roles.
699 - foreach ( (array) $disabled_global_option_[ $role ] as $global_item ) {
700 - $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 ] );
701 793 }
702 794 }
703 795 }
704 -
705 - // Support Multiple Roles for users.
706 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
707 - $disabled_global_option = _mw_adminimize_get_duplicate( $disabled_global_option );
708 - }
709 - $global_options = implode( ', ', $disabled_global_option );
710 -
711 - if ( 0 === strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
712 - global $_wp_admin_css_colors;
796 + if ( isset( $global_options ) && 0 != strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
713 797 $_wp_admin_css_colors = 0;
714 798 }
715 799 $_mw_adminimize_admin_head .= '<!-- Set Adminimize global options -->' . "\n";
716 800 $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display:none !important;}</style>' . "\n";
717 801
718 - if ( '' !== $global_options ) {
802 + if ( ! empty( $global_options ) ) {
719 803 echo $_mw_adminimize_admin_head;
720 804 }
721 805 }
722 806
723 807 /**
724 - * Set metabox options from database an area post.
808 + * set metabox options from database an area post
725 809 */
726 810 function _mw_adminimize_set_metabox_post_option() {
727 811
728 812 // exclude super admin
729 813 if ( _mw_adminimize_exclude_super_admin() ) {
730 - return;
814 + return NULL;
731 815 }
732 816
733 817 // Leave the settings screen from Adminimize to see all areas on settings.
734 818 if ( _mw_adminimize_exclude_settings_page() ) {
@@ -747,11 +831,11 @@
747 831 if ( ! isset( $disabled_metaboxes_post_[ $role ][ '0' ] ) ) {
748 832 $disabled_metaboxes_post_[ $role ][ '0' ] = '';
749 833 }
750 834
751 - // New since version 1.7.8.
835 + // new 1.7.8
752 836 $user = wp_get_current_user();
753 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
837 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
754 838 if ( _mw_adminimize_current_user_has_role( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
755 839 && is_array(
756 840 $disabled_metaboxes_post_[ $role ]
757 841 )
@@ -770,9 +854,9 @@
770 854 }
771 855 }
772 856
773 857 /**
774 - * Set metabox options from database an area page.
858 + * set metabox options from database an area page
775 859 */
776 860 function _mw_adminimize_set_metabox_page_option() {
777 861
778 862 // exclude super admin
@@ -797,11 +881,11 @@
797 881 if ( ! isset( $disabled_metaboxes_page_[ $role ][ '0' ] ) ) {
798 882 $disabled_metaboxes_page_[ $role ][ '0' ] = '';
799 883 }
800 884
801 - // New since version 1.7.8.
885 + // new 1.7.8
802 886 $user = wp_get_current_user();
803 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
887 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
804 888 if ( _mw_adminimize_current_user_has_role( $role )
805 889 && isset( $disabled_metaboxes_page_[ $role ] )
806 890 && is_array( $disabled_metaboxes_page_[ $role ] )
807 891 ) {
@@ -819,9 +903,9 @@
819 903 }
820 904 }
821 905
822 906 /**
823 - * Set metabox options from database an area post.
907 + * set metabox options from database an area post
824 908 */
825 909 function _mw_adminimize_set_metabox_cp_option() {
826 910
827 911 // exclude super admin
@@ -833,13 +917,14 @@
833 917 if ( _mw_adminimize_exclude_settings_page() ) {
834 918 return;
835 919 }
836 920
837 - $post_id = 0;
838 921 if ( isset( $_GET[ 'post' ] ) ) {
839 922 $post_id = (int) $_GET[ 'post' ];
840 923 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
841 924 $post_id = (int) $_POST[ 'post_ID' ];
925 + } else {
926 + $post_id = 0;
842 927 }
843 928
844 929 $current_post_type = $GLOBALS[ 'post_type' ];
845 930 if ( ! isset( $current_post_type ) ) {
@@ -868,9 +953,9 @@
868 953 $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] = '';
869 954 }
870 955
871 956 $user = wp_get_current_user();
872 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
957 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
873 958 if ( _mw_adminimize_current_user_has_role( $role )
874 959 && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
875 960 && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
876 961 ) {
@@ -888,9 +973,9 @@
888 973 }
889 974 }
890 975
891 976 /**
892 - * Set link options in area links of back end.
977 + * set link options in area Links of Backend
893 978 */
894 979 function _mw_adminimize_set_link_option() {
895 980
896 981 // exclude super admin
@@ -918,11 +1003,12 @@
918 1003 }
919 1004 }
920 1005
921 1006 $link_options = '';
1007 + // new 1.7.8
922 1008 foreach ( $user_roles as $role ) {
923 1009 $user = wp_get_current_user();
924 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1010 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
925 1011 if ( _mw_adminimize_current_user_has_role( $role )
926 1012 && isset( $disabled_link_option_[ $role ] )
927 1013 && is_array( $disabled_link_option_[ $role ] )
928 1014 ) {
@@ -940,9 +1026,9 @@
940 1026 }
941 1027 }
942 1028
943 1029 /**
944 - * Remove objects on wp nav menu.
1030 + * remove objects on wp nav menu
945 1031 */
946 1032 function _mw_adminimize_set_nav_menu_option() {
947 1033
948 1034 // exclude super admin
@@ -970,11 +1056,12 @@
970 1056 }
971 1057 }
972 1058
973 1059 $nav_menu_options = '';
1060 + // new 1.7.8
974 1061 foreach ( $user_roles as $role ) {
975 1062 $user = wp_get_current_user();
976 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1063 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
977 1064 if ( _mw_adminimize_current_user_has_role( $role )
978 1065 && isset( $disabled_nav_menu_option_[ $role ] )
979 1066 && is_array( $disabled_nav_menu_option_[ $role ] )
980 1067 ) {
@@ -981,8 +1068,9 @@
981 1068 $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
982 1069 }
983 1070 }
984 1071 }
1072 + //remove_meta_box( $id, 'nav-menus', 'side' );
985 1073
986 1074 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
987 1075 $_mw_adminimize_admin_head .= '<style type="text/css">' .
988 1076 $nav_menu_options . ' {display: none !important;}</style>' . "\n";
@@ -1022,11 +1110,12 @@
1022 1110 }
1023 1111 }
1024 1112
1025 1113 $widget_options = '';
1114 + // new 1.7.8
1026 1115 foreach ( $user_roles as $role ) {
1027 1116 $user = wp_get_current_user();
1028 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1117 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, FALSE ) ) {
1029 1118 if ( _mw_adminimize_current_user_has_role( $role )
1030 1119 && isset( $disabled_widget_option_[ $role ] )
1031 1120 && is_array( $disabled_widget_option_[ $role ] )
1032 1121 ) {
@@ -1033,8 +1122,9 @@
1033 1122 $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
1034 1123 }
1035 1124 }
1036 1125 }
1126 + //remove_meta_box( $id, 'nav-menus', 'side' );
1037 1127
1038 1128 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1039 1129 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1040 1130 $widget_options . ' {display: none !important;}</style>' . "\n";
@@ -1044,9 +1134,9 @@
1044 1134 }
1045 1135 }
1046 1136
1047 1137 /**
1048 - * Print small user-info.
1138 + * small user-info
1049 1139 */
1050 1140 function _mw_adminimize_small_user_info() {
1051 1141
1052 1142 ?>
@@ -1061,14 +1151,13 @@
1061 1151 </div>
1062 1152 <?php
1063 1153 }
1064 1154
1155 +// Include message class.
1156 +require_once 'inc-setup/messages.php';
1065 1157 // include helping functions
1066 1158 require_once 'inc-setup/helping_hands.php';
1067 1159
1068 -// Include message class.
1069 -require_once 'inc-setup/messages.php';
1070 -
1071 1160 // inc. settings page
1072 1161 require_once 'adminimize_page.php';
1073 1162
1074 1163 // dashboard options
@@ -1075,9 +1164,8 @@
1075 1164 require_once 'inc-setup/dashboard.php';
1076 1165
1077 1166 // widget options
1078 1167 require_once 'inc-setup/widget.php';
1079 -require_once 'inc-setup/footer.php';
1080 1168 require_once 'inc-setup/admin-footer.php';
1081 1169
1082 1170 // global settings
1083 1171 // @TODO Testing, not ready for productive
@@ -1096,19 +1184,15 @@
1096 1184
1097 1185 // Remove Admin Notices.
1098 1186 require_once 'inc-setup/remove-admin-notices.php';
1099 1187
1100 -// Add Ex-Import functions.
1101 -require_once 'inc-setup/export.php';
1102 -require_once 'inc-setup/import.php';
1103 -
1104 1188 /**
1105 1189 * Add action link(s) to plugins page
1106 1190 *
1107 - * @param array $links
1108 - * @param string $file
1191 + * @param $links , $file
1192 + * @param $file
1109 1193 *
1110 - * @return string $links
1194 + * @return $links
1111 1195 */
1112 1196 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1113 1197
1114 1198 /* create link */
@@ -1114,13 +1198,9 @@
1114 1198 /* create link */
1115 1199 if ( FB_ADMINIMIZE_BASENAME === $file ) {
1116 1200 array_unshift(
1117 1201 $links,
1118 - sprintf(
1119 - '<a href="options-general.php?page=%s">%s</a>',
1120 - FB_ADMINIMIZE_BASENAME,
1121 - esc_attr__( 'Settings' )
1122 - )
1202 + sprintf( '<a href="options-general.php?page=%s">%s</a>', FB_ADMINIMIZE_BASENAME, esc_attr__( 'Settings' ) )
1123 1203 );
1124 1204 }
1125 1205
1126 1206 return $links;
@@ -1126,9 +1206,9 @@
1126 1206 return $links;
1127 1207 }
1128 1208
1129 1209 /**
1130 - * Add settings in plugin-admin-page.
1210 + * settings in plugin-admin-page
1131 1211 */
1132 1212 function _mw_adminimize_add_settings_page() {
1133 1213
1134 1214 $pagehook = add_options_page(
@@ -1134,12 +1214,11 @@
1134 1214 $pagehook = add_options_page(
1135 1215 esc_attr__( 'Adminimize Options', 'adminimize' ),
1136 1216 esc_attr__( 'Adminimize', 'adminimize' ),
1137 1217 'manage_options',
1138 - 'adminimize-options',
1218 + __FILE__,
1139 1219 '_mw_adminimize_options'
1140 1220 );
1141 -
1142 1221 if ( ! is_network_admin() ) {
1143 1222 add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
1144 1223 }
1145 1224 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
@@ -1144,16 +1223,10 @@
1144 1223 }
1145 1224 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
1146 1225 }
1147 1226
1148 -/**
1149 - * Enqueue script and styles for the settings page.
1150 - */
1151 1227 function _mw_adminimize_on_load_page() {
1152 1228
1153 - // Load translation files on options page.
1154 - _mw_adminimize_textdomain();
1155 -
1156 1229 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1157 1230
1158 1231 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1159 1232 wp_enqueue_style( 'adminimize-style' );
@@ -1170,9 +1243,8 @@
1170 1243
1171 1244 /**
1172 1245 * Set theme for users
1173 1246 * Kill with version 1.7.18
1174 - * @ToDo Remove for the feature releases.
1175 1247 */
1176 1248 function _mw_adminimize_set_theme() {
1177 1249
1178 1250 if ( ! current_user_can( 'edit_users' ) ) {
@@ -1178,9 +1250,9 @@
1178 1250 if ( ! current_user_can( 'edit_users' ) ) {
1179 1251 wp_die( esc_attr__( 'Cheatin&#8217; uh?' ) );
1180 1252 }
1181 1253
1182 - $user_ids = (array) $_POST[ 'mw_adminimize_theme_items' ];
1254 + $user_ids = $_POST[ 'mw_adminimize_theme_items' ];
1183 1255 $admin_color = htmlspecialchars( stripslashes( $_POST[ '_mw_adminimize_set_theme' ] ) );
1184 1256
1185 1257 if ( ! $user_ids ) {
1186 1258 return FALSE;
@@ -1197,31 +1269,24 @@
1197 1269 * Get setting value for each options key.
1198 1270 *
1199 1271 * @param string|bool $key
1200 1272 *
1201 - * @return string
1273 + * @return array
1202 1274 */
1203 1275 function _mw_adminimize_get_option_value( $key = FALSE ) {
1204 1276
1205 - $adminimizeoptions = FALSE;
1206 - if ( ! _mw_adminimize_exclude_settings_page() ) {
1207 - $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() );
1208 1282 }
1209 1283
1210 - if ( FALSE === $adminimizeoptions ) {
1211 - // check for use on multisite
1212 - if ( _mw_adminimize_is_active_on_multisite() ) {
1213 - $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1214 - } else {
1215 - $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
1216 - }
1217 - wp_cache_set( 'mw_adminimize', $adminimizeoptions );
1218 - }
1219 -
1220 1284 if ( ! $key ) {
1221 1285 return $adminimizeoptions;
1222 1286 }
1223 1287
1288 + /** @var array $adminimizeoptions */
1224 1289 return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : NULL;
1225 1290 }
1226 1291
1227 1292 /**
@@ -1227,32 +1292,20 @@
1227 1292 /**
1228 1293 * Update options.
1229 1294 *
1230 1295 * @param array $options
1231 - *
1232 - * @return bool
1233 1296 */
1234 1297 function _mw_adminimize_update_option( $options ) {
1235 1298
1236 1299 if ( ! current_user_can( 'manage_options' ) ) {
1237 - return FALSE;
1300 + return;
1238 1301 }
1239 1302
1240 - // Remove slashes always.
1241 - foreach ( $options as $key => $value ) {
1242 - $options[ $key ] = stripslashes_deep( $value );
1243 - }
1244 -
1245 - // Kill the cache for the settings page.
1246 - wp_cache_delete( 'mw_adminimize' );
1247 1303 if ( _mw_adminimize_is_active_on_multisite() ) {
1248 1304 update_site_option( 'mw_adminimize', $options );
1249 1305 } else {
1250 1306 update_option( 'mw_adminimize', $options );
1251 1307 }
1252 - wp_cache_add( 'mw_adminimize', $options );
1253 -
1254 - return TRUE;
1255 1308 }
1256 1309
1257 1310 /**
1258 1311 * Update options in database
@@ -1276,33 +1329,8 @@
1276 1329 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1277 1330 }
1278 1331 }
1279 1332
1280 - // Plugin Self Settings.
1281 - if ( isset( $_POST[ 'mw_adminimize_debug' ] ) ) {
1282 - $adminimizeoptions[ 'mw_adminimize_debug' ] = (int) $_POST[ 'mw_adminimize_debug' ];
1283 - } else {
1284 - $adminimizeoptions[ 'mw_adminimize_debug' ] = 0;
1285 - }
1286 -
1287 - if ( isset( $_POST[ 'mw_adminimize_multiple_roles' ] ) ) {
1288 - $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = (int) $_POST[ 'mw_adminimize_multiple_roles' ];
1289 - } else {
1290 - $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = 0;
1291 - }
1292 -
1293 - if ( isset( $_POST[ 'mw_adminimize_support_bbpress' ] ) ) {
1294 - $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = (int) $_POST[ 'mw_adminimize_support_bbpress' ];
1295 - } else {
1296 - $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = 0;
1297 - }
1298 -
1299 - if ( isset( $_POST[ 'mw_adminimize_prevent_page_access' ] ) ) {
1300 - $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = (int) $_POST[ 'mw_adminimize_prevent_page_access' ];
1301 - } else {
1302 - $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = 0;
1303 - }
1304 -
1305 1333 // Admin Bar Front end settings
1306 1334 $adminimizeoptions[ 'mw_adminimize_admin_bar_frontend_nodes' ] = _mw_adminimize_get_option_value(
1307 1335 'mw_adminimize_admin_bar_frontend_nodes'
1308 1336 );
@@ -1307,9 +1335,9 @@
1307 1335 'mw_adminimize_admin_bar_frontend_nodes'
1308 1336 );
1309 1337 // admin bar front end options
1310 1338 foreach ( $user_roles as $role ) {
1311 - // admin bar front-end options
1339 + // admin bar fron tend options
1312 1340 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] ) ) {
1313 1341 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ];
1314 1342 } else {
1315 1343 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = array();
@@ -1370,19 +1398,10 @@
1370 1398 $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
1371 1399 }
1372 1400
1373 1401 if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
1374 - $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = wp_kses(
1375 - $_POST[ '_mw_adminimize_advice_txt' ],
1376 - array(
1377 - 'a' => array(
1378 - 'href' => array(),
1379 - 'title' => array()
1380 - ),
1381 - 'br' => array(),
1382 - 'em' => array(),
1383 - 'strong' => array(),
1384 - )
1402 + $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = htmlspecialchars(
1403 + stripslashes( $_POST[ '_mw_adminimize_advice_txt' ] )
1385 1404 );
1386 1405 } else {
1387 1406 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = '';
1388 1407 }
@@ -1415,27 +1434,8 @@
1415 1434 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1416 1435 }
1417 1436 }
1418 1437
1419 - // @ToDo After release of WP 4.7, switch to sanitize_textarea_field()
1420 -
1421 - // own menu slug
1422 - if ( isset( $_POST[ '_mw_adminimize_own_menu_slug' ] ) ) {
1423 - $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = stripslashes(
1424 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_slug' ] )
1425 - );
1426 - } else {
1427 - $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = '';
1428 - }
1429 - // own custom menu slug
1430 - if ( isset( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] ) ) {
1431 - $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = stripslashes(
1432 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] )
1433 - );
1434 - } else {
1435 - $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = '';
1436 - }
1437 -
1438 1438 // global_options, metaboxes update
1439 1439 foreach ( $user_roles as $role ) {
1440 1440
1441 1441 // global options
@@ -1440,9 +1440,9 @@
1440 1440
1441 1441 // global options
1442 1442 if ( isset( $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] ) ) {
1443 1443 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] =
1444 - $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1444 + $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1445 1445 } else {
1446 1446 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1447 1447 }
1448 1448
@@ -1502,19 +1502,15 @@
1502 1502 }
1503 1503
1504 1504 // own options
1505 1505 if ( isset( $_POST[ '_mw_adminimize_own_values' ] ) ) {
1506 - $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes(
1507 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values' ] )
1508 - );
1506 + $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes( $_POST[ '_mw_adminimize_own_values' ] );
1509 1507 } else {
1510 1508 $adminimizeoptions[ '_mw_adminimize_own_values' ] = '';
1511 1509 }
1512 1510
1513 1511 if ( isset( $_POST[ '_mw_adminimize_own_options' ] ) ) {
1514 - $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes(
1515 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options' ] )
1516 - );
1512 + $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes( $_POST[ '_mw_adminimize_own_options' ] );
1517 1513 } else {
1518 1514 $adminimizeoptions[ '_mw_adminimize_own_options' ] = '';
1519 1515 }
1520 1516
@@ -1520,9 +1516,9 @@
1520 1516
1521 1517 // own post options
1522 1518 if ( isset( $_POST[ '_mw_adminimize_own_post_values' ] ) ) {
1523 1519 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = stripslashes(
1524 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_values' ] )
1520 + $_POST[ '_mw_adminimize_own_post_values' ]
1525 1521 );
1526 1522 } else {
1527 1523 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = '';
1528 1524 }
@@ -1528,9 +1524,9 @@
1528 1524 }
1529 1525
1530 1526 if ( isset( $_POST[ '_mw_adminimize_own_post_options' ] ) ) {
1531 1527 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = stripslashes(
1532 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_options' ] )
1528 + $_POST[ '_mw_adminimize_own_post_options' ]
1533 1529 );
1534 1530 } else {
1535 1531 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = '';
1536 1532 }
@@ -1537,9 +1533,9 @@
1537 1533
1538 1534 // own page options
1539 1535 if ( isset( $_POST[ '_mw_adminimize_own_page_values' ] ) ) {
1540 1536 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = stripslashes(
1541 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_values' ] )
1537 + $_POST[ '_mw_adminimize_own_page_values' ]
1542 1538 );
1543 1539 } else {
1544 1540 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = '';
1545 1541 }
@@ -1545,9 +1541,9 @@
1545 1541 }
1546 1542
1547 1543 if ( isset( $_POST[ '_mw_adminimize_own_page_options' ] ) ) {
1548 1544 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = stripslashes(
1549 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_options' ] )
1545 + $_POST[ '_mw_adminimize_own_page_options' ]
1550 1546 );
1551 1547 } else {
1552 1548 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = '';
1553 1549 }
@@ -1555,9 +1551,9 @@
1555 1551 // own custom post options
1556 1552 foreach ( $post_types as $post_type ) {
1557 1553 if ( isset( $_POST[ '_mw_adminimize_own_values_' . $post_type ] ) ) {
1558 1554 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = stripslashes(
1559 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values_' . $post_type ] )
1555 + $_POST[ '_mw_adminimize_own_values_' . $post_type ]
1560 1556 );
1561 1557 } else {
1562 1558 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = '';
1563 1559 }
@@ -1563,9 +1559,9 @@
1563 1559 }
1564 1560
1565 1561 if ( isset( $_POST[ '_mw_adminimize_own_options_' . $post_type ] ) ) {
1566 1562 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = stripslashes(
1567 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options_' . $post_type ] )
1563 + $_POST[ '_mw_adminimize_own_options_' . $post_type ]
1568 1564 );
1569 1565 } else {
1570 1566 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = '';
1571 1567 }
@@ -1573,9 +1569,9 @@
1573 1569
1574 1570 // own link options
1575 1571 if ( isset( $_POST[ '_mw_adminimize_own_link_values' ] ) ) {
1576 1572 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = stripslashes(
1577 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_values' ] )
1573 + $_POST[ '_mw_adminimize_own_link_values' ]
1578 1574 );
1579 1575 } else {
1580 1576 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = '';
1581 1577 }
@@ -1581,9 +1577,9 @@
1581 1577 }
1582 1578
1583 1579 if ( isset( $_POST[ '_mw_adminimize_own_link_options' ] ) ) {
1584 1580 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = stripslashes(
1585 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_options' ] )
1581 + $_POST[ '_mw_adminimize_own_link_options' ]
1586 1582 );
1587 1583 } else {
1588 1584 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = '';
1589 1585 }
@@ -1590,9 +1586,9 @@
1590 1586
1591 1587 // wp nav menu options
1592 1588 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_values' ] ) ) {
1593 1589 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = stripslashes(
1594 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_values' ] )
1590 + $_POST[ '_mw_adminimize_own_nav_menu_values' ]
1595 1591 );
1596 1592 } else {
1597 1593 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = '';
1598 1594 }
@@ -1598,9 +1594,9 @@
1598 1594 }
1599 1595
1600 1596 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_options' ] ) ) {
1601 1597 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = stripslashes(
1602 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_options' ] )
1598 + $_POST[ '_mw_adminimize_own_nav_menu_options' ]
1603 1599 );
1604 1600 } else {
1605 1601 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = '';
1606 1602 }
@@ -1607,9 +1603,9 @@
1607 1603
1608 1604 // widget options
1609 1605 if ( isset( $_POST[ '_mw_adminimize_own_widget_values' ] ) ) {
1610 1606 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = stripslashes(
1611 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_values' ] )
1607 + $_POST[ '_mw_adminimize_own_widget_values' ]
1612 1608 );
1613 1609 } else {
1614 1610 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = '';
1615 1611 }
@@ -1615,9 +1611,9 @@
1615 1611 }
1616 1612
1617 1613 if ( isset( $_POST[ '_mw_adminimize_own_widget_options' ] ) ) {
1618 1614 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = stripslashes(
1619 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_options' ] )
1615 + $_POST[ '_mw_adminimize_own_widget_options' ]
1620 1616 );
1621 1617 } else {
1622 1618 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = '';
1623 1619 }
@@ -1624,9 +1620,9 @@
1624 1620
1625 1621 // own dashboard options
1626 1622 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_values' ] ) ) {
1627 1623 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = stripslashes(
1628 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_values' ] )
1624 + $_POST[ '_mw_adminimize_own_dashboard_values' ]
1629 1625 );
1630 1626 } else {
1631 1627 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = '';
1632 1628 }
@@ -1632,9 +1628,9 @@
1632 1628 }
1633 1629
1634 1630 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_options' ] ) ) {
1635 1631 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = stripslashes(
1636 - wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_options' ] )
1632 + $_POST[ '_mw_adminimize_own_dashboard_options' ]
1637 1633 );
1638 1634 } else {
1639 1635 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = '';
1640 1636 }
@@ -1650,31 +1646,22 @@
1650 1646 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1651 1647 }
1652 1648
1653 1649 // update
1654 - $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1650 + _mw_adminimize_update_option( $adminimizeoptions );
1655 1651
1656 1652 $myErrors = new _mw_adminimize_message_class();
1657 - if ( $update_status ) {
1658 - $message = $myErrors->get_error(
1653 + $myErrors = '<div id="message" class="updated fade"><p>' . $myErrors->get_error(
1659 1654 '_mw_adminimize_update'
1660 - );
1661 - } else {
1662 - $message = $myErrors->get_error(
1663 - '_mw_adminimize_access_denied'
1664 - );
1665 - }
1666 - echo '<div id="message" class="notice notice-success"><p>' . $message . '</p></div>';
1667 -
1668 - return TRUE;
1655 + ) . '</p></div>';
1656 + echo $myErrors;
1669 1657 }
1670 1658
1671 1659 /**
1672 1660 * Delete options in database
1673 1661 */
1674 -function _mw_adminimize_uninstall() {
1662 +function _mw_adminimize_deinstall() {
1675 1663
1676 - wp_cache_delete( 'mw_adminimize' );
1677 1664 delete_site_option( 'mw_adminimize' );
1678 1665 delete_option( 'mw_adminimize' );
1679 1666 }
1680 1667
@@ -1683,16 +1670,11 @@
1683 1670 */
1684 1671 function _mw_adminimize_install() {
1685 1672
1686 1673 if ( ! is_admin() ) {
1687 - return;
1674 + return NULL;
1688 1675 }
1689 1676
1690 - // If is AJAX Call.
1691 - if ( defined('DOING_AJAX') && DOING_AJAX ) {
1692 - return;
1693 - }
1694 -
1695 1677 global $menu, $submenu;
1696 1678
1697 1679 $user_roles = _mw_adminimize_get_all_user_roles();
1698 1680 $adminimizeoptions = array();
@@ -1720,6 +1702,71 @@
1720 1702 add_site_option( 'mw_adminimize', $adminimizeoptions );
1721 1703 } else {
1722 1704 add_option( 'mw_adminimize', $adminimizeoptions );
1723 1705 }
1724 - wp_cache_add( 'mw_adminimize', $adminimizeoptions );
1706 +}
1707 +
1708 +/**
1709 + * Process a settings export that generates a .json file of the shop settings
1710 + */
1711 +function _mw_adminimize_export_json() {
1712 +
1713 + if ( empty( $_GET[ '_mw_adminimize_export' ] ) || 'true' !== $_GET[ '_mw_adminimize_export' ] ) {
1714 + return;
1715 + }
1716 +
1717 + require_once ABSPATH . 'wp-includes/pluggable.php';
1718 + if ( ! wp_verify_nonce( $_GET[ 'mw_adminimize_export_nonce' ], 'mw_adminimize_export_nonce' ) ) {
1719 + return;
1720 + }
1721 +
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();
1737 +}
1738 +
1739 +/**
1740 + * Process a settings import from a json file
1741 + */
1742 +function _mw_adminimize_import_json() {
1743 +
1744 + if ( empty( $_POST[ '_mw_adminimize_action' ] ) || '_mw_adminimize_import' !== $_POST[ '_mw_adminimize_action' ] ) {
1745 + return;
1746 + }
1747 +
1748 + if ( ! wp_verify_nonce( $_POST[ 'mw_adminimize_import_nonce' ], 'mw_adminimize_import_nonce' ) ) {
1749 + return;
1750 + }
1751 +
1752 + if ( ! current_user_can( 'manage_options' ) ) {
1753 + return;
1754 + }
1755 +
1756 + $extension = pathinfo( $_FILES[ 'import_file' ][ 'name' ], PATHINFO_EXTENSION );
1757 + if ( $extension !== 'json' ) {
1758 + wp_die( esc_attr__( 'Please upload a valid .json file' ) );
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 );
1725 1772 }