PluginProbe
Adminimize / 1.11.13
Adminimize v1.11.13
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.13, at adminimize.php

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