PluginProbe
Adminimize / 1.11.2
Adminimize v1.11.2
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
adminimize / adminimize.php

adminimize.php in Adminimize 1.11.2, at adminimize.php

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