PluginProbe
Adminimize / 1.11.10
Adminimize v1.11.10
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.10, at adminimize.php

1,841 lines 56.7 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: https://bueltge.de/
10 * Version: 1.11.10
11 * License: GPLv2+
12 *
13 * Php Version 5.6
14 *
15 * @package WordPress
16 * @author Frank Bültge <frank@bueltge.de>
17 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
18 * @version 2023-11-23
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 $current_post_type = $GLOBALS[ 'post_type' ];
919 if ( ! isset( $current_post_type ) ) {
920 $current_post_type = get_post_type( $post_id );
921 }
922
923 if ( ! isset( $current_post_type ) || ! $current_post_type ) {
924 $current_post_type = str_replace( 'post_type=', '', esc_attr( $_SERVER[ 'QUERY_STRING' ] ) );
925 }
926
927 // set hard to post
928 if ( ! $current_post_type ) {
929 $current_post_type = 'post';
930 }
931
932 $user_roles = _mw_adminimize_get_all_user_roles();
933 $_mw_adminimize_admin_head = '';
934 $metaboxes = array();
935
936 foreach ( $user_roles as $role ) {
937 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
938 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
939 );
940
941 if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] ) ) {
942 $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] = '';
943
944 continue;
945 }
946
947 $user = $GLOBALS['current_user'];
948 if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
949 if ( _mw_adminimize_current_user_has_role( $role )
950 && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
951 && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
952 ) {
953 $metaboxes[] = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
954 }
955 }
956 }
957
958 $_mw_adminimize_admin_head .= '<!-- Set Adminimize post options -->' . "\n";
959 $_mw_adminimize_admin_head .= '<style type="text/css">' .
960 implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
961
962 if ( ! empty( $metaboxes ) ) {
963 echo $_mw_adminimize_admin_head;
964 }
965 }
966
967 /**
968 * Set link options in area links of back end.
969 */
970 function _mw_adminimize_set_link_option() {
971
972 // exclude super admin
973 if ( _mw_adminimize_exclude_super_admin() ) {
974 return NULL;
975 }
976
977 // Leave the settings screen from Adminimize to see all areas on settings.
978 if ( _mw_adminimize_exclude_settings_page() ) {
979 return;
980 }
981
982 $user_roles = _mw_adminimize_get_all_user_roles();
983 $_mw_adminimize_admin_head = '';
984
985 foreach ( $user_roles as $role ) {
986 $disabled_link_option_[ $role ] = _mw_adminimize_get_option_value(
987 'mw_adminimize_disabled_link_option_' . $role . '_items'
988 );
989 }
990
991 foreach ( $user_roles as $role ) {
992 if ( ! isset( $disabled_link_option_[ $role ][ '0' ] ) ) {
993 $disabled_link_option_[ $role ][ '0' ] = '';
994 }
995 }
996
997 $link_options = '';
998 foreach ( $user_roles as $role ) {
999 $user = wp_get_current_user();
1000 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1001 if ( _mw_adminimize_current_user_has_role( $role )
1002 && isset( $disabled_link_option_[ $role ] )
1003 && is_array( $disabled_link_option_[ $role ] )
1004 ) {
1005 $link_options = implode( ',', $disabled_link_option_[ $role ] );
1006 }
1007 }
1008 }
1009
1010 $_mw_adminimize_admin_head .= '<!-- Set Adminimize links options -->' . "\n";
1011 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1012 $link_options . ' {display:none !important;}</style>' . "\n";
1013
1014 if ( ! empty( $link_options ) ) {
1015 echo $_mw_adminimize_admin_head;
1016 }
1017 }
1018
1019 /**
1020 * Remove objects on wp nav menu.
1021 */
1022 function _mw_adminimize_set_nav_menu_option() {
1023
1024 // exclude super admin
1025 if ( _mw_adminimize_exclude_super_admin() ) {
1026 return NULL;
1027 }
1028
1029 // Leave the settings screen from Adminimize to see all areas on settings.
1030 if ( _mw_adminimize_exclude_settings_page() ) {
1031 return;
1032 }
1033
1034 $user_roles = _mw_adminimize_get_all_user_roles();
1035 $_mw_adminimize_admin_head = '';
1036
1037 foreach ( $user_roles as $role ) {
1038 $disabled_nav_menu_option_[ $role ] = _mw_adminimize_get_option_value(
1039 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items'
1040 );
1041 }
1042
1043 foreach ( $user_roles as $role ) {
1044 if ( ! isset( $disabled_nav_menu_option_[ $role ][ '0' ] ) ) {
1045 $disabled_nav_menu_option_[ $role ][ '0' ] = '';
1046 }
1047 }
1048
1049 $nav_menu_options = '';
1050 foreach ( $user_roles as $role ) {
1051 $user = wp_get_current_user();
1052 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1053 if ( _mw_adminimize_current_user_has_role( $role )
1054 && isset( $disabled_nav_menu_option_[ $role ] )
1055 && is_array( $disabled_nav_menu_option_[ $role ] )
1056 ) {
1057 $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
1058 }
1059 }
1060 }
1061
1062 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
1063 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1064 $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1065
1066 if ( $nav_menu_options ) {
1067 echo $_mw_adminimize_admin_head;
1068 }
1069 }
1070
1071 /**
1072 * Remove areas in Widget Settings
1073 */
1074 function _mw_adminimize_set_widget_option() {
1075
1076 // exclude super admin
1077 if ( _mw_adminimize_exclude_super_admin() ) {
1078 return NULL;
1079 }
1080
1081 // Leave the settings screen from Adminimize to see all areas on settings.
1082 if ( _mw_adminimize_exclude_settings_page() ) {
1083 return;
1084 }
1085
1086 $user_roles = _mw_adminimize_get_all_user_roles();
1087 $_mw_adminimize_admin_head = '';
1088
1089 foreach ( $user_roles as $role ) {
1090 $disabled_widget_option_[ $role ] = _mw_adminimize_get_option_value(
1091 'mw_adminimize_disabled_widget_option_' . $role . '_items'
1092 );
1093 }
1094
1095 foreach ( $user_roles as $role ) {
1096 if ( ! isset( $disabled_widget_option_[ $role ][ '0' ] ) ) {
1097 $disabled_widget_option_[ $role ][ '0' ] = '';
1098 }
1099 }
1100
1101 $widget_options = '';
1102 foreach ( $user_roles as $role ) {
1103 $user = wp_get_current_user();
1104 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1105 if ( _mw_adminimize_current_user_has_role( $role )
1106 && isset( $disabled_widget_option_[ $role ] )
1107 && is_array( $disabled_widget_option_[ $role ] )
1108 ) {
1109 $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
1110 }
1111 }
1112 }
1113
1114 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1115 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1116 $widget_options . ' {display: none !important;}</style>' . "\n";
1117
1118 if ( $widget_options ) {
1119 echo $_mw_adminimize_admin_head;
1120 }
1121 }
1122
1123 /**
1124 * Print small user-info.
1125 */
1126 function _mw_adminimize_small_user_info() {
1127
1128 ?>
1129 <div id="small_user_info">
1130 <p>
1131 <a href="<?php echo wp_nonce_url(
1132 site_url( 'wp-login.php?action=logout' ),
1133 'log-out'
1134 ) ?>"
1135 title="<?php esc_attr_e( 'Log Out' ) ?>"><?php esc_attr_e( 'Log Out' ); ?></a>
1136 </p>
1137 </div>
1138 <?php
1139 }
1140
1141 // include helping functions
1142 require_once 'inc-setup/DebugListener.php';
1143 require_once 'inc-setup/helping_hands.php';
1144
1145 // Include message class.
1146 require_once 'inc-setup/messages.php';
1147
1148 // inc. settings page
1149 require_once 'adminimize_page.php';
1150
1151 // dashboard options
1152 require_once 'inc-setup/dashboard.php';
1153
1154 // widget options
1155 require_once 'inc-setup/widget.php';
1156 require_once 'inc-setup/footer.php';
1157 require_once 'inc-setup/admin-footer.php';
1158
1159 // remove admin bar
1160 require_once 'inc-setup/remove-admin-bar.php';
1161
1162 // admin bar helper, setup
1163 // work always in frontend
1164 require_once 'inc-setup/admin-bar-items.php';
1165
1166 // meta boxes helper, setup
1167 // @TODO Meta Boxes: not ready for productive systems.
1168 //require_once( 'inc-setup/meta-boxes.php' );
1169
1170 // Remove Admin Notices.
1171 require_once 'inc-setup/remove-admin-notices.php';
1172
1173 // Add Ex-Import functions.
1174 require_once 'inc-setup/export.php';
1175 require_once 'inc-setup/import.php';
1176
1177 /**
1178 * Add action link(s) to plugins page
1179 *
1180 * @param array $links
1181 * @param string $file
1182 *
1183 * @return array $links
1184 */
1185 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1186
1187 /* create link */
1188 if ( FB_ADMINIMIZE_BASENAME === $file ) {
1189 array_unshift(
1190 $links,
1191 sprintf(
1192 '<a href="options-general.php?page=adminimize-options">%s</a>',
1193 esc_attr__( 'Settings' )
1194 )
1195 );
1196 }
1197
1198 return $links;
1199 }
1200
1201 /**
1202 * Add settings in plugin-admin-page.
1203 */
1204 function _mw_adminimize_add_settings_page() {
1205
1206 $pagehook = add_options_page(
1207 esc_attr__( 'Adminimize Options', 'adminimize' ),
1208 esc_attr__( 'Adminimize', 'adminimize' ),
1209 'manage_options',
1210 'adminimize-options',
1211 '_mw_adminimize_options'
1212 );
1213
1214 if ( ! is_network_admin() ) {
1215 add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
1216 }
1217 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
1218 }
1219
1220 /**
1221 * Enqueue script and styles for the settings page.
1222 */
1223 function _mw_adminimize_on_load_page() {
1224
1225 // Load translation files on options page.
1226 _mw_adminimize_textdomain();
1227
1228 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1229
1230 wp_enqueue_style( 'select2-style', plugins_url( 'css/select2' . $suffix . '.css', __FILE__ ), [], false );
1231 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1232 wp_enqueue_style( 'adminimize-style' );
1233
1234 wp_enqueue_script( 'select2-script', plugins_url( 'js/select2' . $suffix . '.js', __FILE__ ), array( 'jquery' ),'',false );
1235 wp_register_script(
1236 'adminimize-settings-script',
1237 plugins_url( 'js/adminimize' . $suffix . '.js', __FILE__ ),
1238 array( 'jquery' ),
1239 '',
1240 TRUE
1241 );
1242 wp_enqueue_script( 'adminimize-settings-script' );
1243 }
1244
1245 /**
1246 * Get setting value for each options key.
1247 *
1248 * @param string|bool $key
1249 *
1250 * @return string
1251 */
1252 function _mw_adminimize_get_option_value( $key = false ) {
1253
1254 $adminimizeoptions = false;
1255 if ( ! _mw_adminimize_exclude_settings_page() ) {
1256 $adminimizeoptions = wp_cache_get( 'mw_adminimize' );
1257 }
1258
1259 if ( false === $adminimizeoptions ) {
1260 // check for use on multisite.
1261 if ( _mw_adminimize_is_active_on_multisite() ) {
1262 $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1263 } else {
1264 $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
1265 }
1266 wp_cache_set( 'mw_adminimize', $adminimizeoptions );
1267 }
1268
1269 if ( ! $key ) {
1270 return $adminimizeoptions;
1271 }
1272
1273 return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : null;
1274 }
1275
1276 /**
1277 * Update options.
1278 *
1279 * @param array $options
1280 *
1281 * @return bool
1282 */
1283 function _mw_adminimize_update_option( $options ) {
1284
1285 if ( ! current_user_can( 'manage_options' ) ) {
1286 return FALSE;
1287 }
1288
1289 if ( _mw_adminimize_is_roles_options_import( $options ) ){
1290 $options = _mw_adminimize_roles_complete_options( $options );
1291 }
1292
1293 // Remove slashes always.
1294 foreach ( $options as $key => $value ) {
1295 $options[ $key ] = stripslashes_deep( $value );
1296 }
1297
1298 // Kill the cache for the settings page.
1299 wp_cache_delete( 'mw_adminimize' );
1300 if ( _mw_adminimize_is_active_on_multisite() ) {
1301 update_site_option( 'mw_adminimize', $options );
1302 } else {
1303 update_option( 'mw_adminimize', $options );
1304 }
1305 wp_cache_add( 'mw_adminimize', $options );
1306
1307 return TRUE;
1308 }
1309
1310 /**
1311 * Update options in database
1312 */
1313 function _mw_adminimize_update() {
1314
1315 $user_roles = _mw_adminimize_get_all_user_roles();
1316 $args = array( 'public' => TRUE, '_builtin' => FALSE );
1317 $post_types = get_post_types( $args );
1318
1319 // Admin Bar Back end settings
1320 $adminimizeoptions[ 'mw_adminimize_admin_bar_nodes' ] = _mw_adminimize_get_option_value(
1321 'mw_adminimize_admin_bar_nodes'
1322 );
1323 // admin bar back end options
1324 foreach ( $user_roles as $role ) {
1325 // admin bar back end options
1326 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] ) ) {
1327 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ];
1328 } else {
1329 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1330 }
1331 }
1332
1333 // Plugin Self Settings.
1334 if ( isset( $_POST[ 'mw_adminimize_debug' ] ) ) {
1335 $adminimizeoptions[ 'mw_adminimize_debug' ] = (int) $_POST[ 'mw_adminimize_debug' ];
1336 } else {
1337 $adminimizeoptions[ 'mw_adminimize_debug' ] = 0;
1338 }
1339
1340 if ( isset( $_POST[ 'mw_adminimize_multiple_roles' ] ) ) {
1341 $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = (int) $_POST[ 'mw_adminimize_multiple_roles' ];
1342 } else {
1343 $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = 0;
1344 }
1345
1346 if ( isset( $_POST[ 'mw_adminimize_support_bbpress' ] ) ) {
1347 $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = (int) $_POST[ 'mw_adminimize_support_bbpress' ];
1348 } else {
1349 $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = 0;
1350 }
1351
1352 if ( isset( $_POST[ 'mw_adminimize_prevent_page_access' ] ) ) {
1353 $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = (int) $_POST[ 'mw_adminimize_prevent_page_access' ];
1354 } else {
1355 $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = 0;
1356 }
1357
1358 // Admin Bar Front end settings
1359 $adminimizeoptions[ 'mw_adminimize_admin_bar_frontend_nodes' ] = _mw_adminimize_get_option_value(
1360 'mw_adminimize_admin_bar_frontend_nodes'
1361 );
1362 // admin bar front end options
1363 foreach ( $user_roles as $role ) {
1364 // admin bar front-end options
1365 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] ) ) {
1366 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ];
1367 } else {
1368 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = array();
1369 }
1370 }
1371
1372 if ( isset( $_POST[ '_mw_adminimize_user_info' ] ) ) {
1373 $adminimizeoptions[ '_mw_adminimize_user_info' ] = (int) $_POST[ '_mw_adminimize_user_info' ];
1374 } else {
1375 $adminimizeoptions[ '_mw_adminimize_user_info' ] = 0;
1376 }
1377
1378 if ( isset( $_POST[ '_mw_adminimize_footer' ] ) ) {
1379 $adminimizeoptions[ '_mw_adminimize_footer' ] = (int) $_POST[ '_mw_adminimize_footer' ];
1380 } else {
1381 $adminimizeoptions[ '_mw_adminimize_footer' ] = 0;
1382 }
1383
1384 if ( isset( $_POST[ '_mw_adminimize_header' ] ) ) {
1385 $adminimizeoptions[ '_mw_adminimize_header' ] = (int) $_POST[ '_mw_adminimize_header' ];
1386 } else {
1387 $adminimizeoptions[ '_mw_adminimize_header' ] = 0;
1388 }
1389
1390 if ( isset( $_POST[ '_mw_adminimize_exclude_super_admin' ] ) ) {
1391 $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = (int) $_POST[ '_mw_adminimize_exclude_super_admin' ];
1392 } else {
1393 $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = 0;
1394 }
1395
1396 if ( isset( $_POST[ '_mw_adminimize_tb_window' ] ) ) {
1397 $adminimizeoptions[ '_mw_adminimize_tb_window' ] = (int) $_POST[ '_mw_adminimize_tb_window' ];
1398 } else {
1399 $adminimizeoptions[ '_mw_adminimize_tb_window' ] = 0;
1400 }
1401
1402 if ( isset( $_POST[ '_mw_adminimize_cat_full' ] ) ) {
1403 $adminimizeoptions[ '_mw_adminimize_cat_full' ] = (int) $_POST[ '_mw_adminimize_cat_full' ];
1404 } else {
1405 $adminimizeoptions[ '_mw_adminimize_cat_full' ] = 0;
1406 }
1407
1408 if ( isset( $_POST[ '_mw_adminimize_db_redirect' ] ) ) {
1409 $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = (int) $_POST[ '_mw_adminimize_db_redirect' ];
1410 } else {
1411 $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = 0;
1412 }
1413
1414 if ( isset( $_POST[ '_mw_adminimize_ui_redirect' ] ) ) {
1415 $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = (int) $_POST[ '_mw_adminimize_ui_redirect' ];
1416 } else {
1417 $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = 0;
1418 }
1419
1420 if ( isset( $_POST[ '_mw_adminimize_advice' ] ) ) {
1421 $adminimizeoptions[ '_mw_adminimize_advice' ] = (int) $_POST[ '_mw_adminimize_advice' ];
1422 } else {
1423 $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
1424 }
1425
1426 if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
1427 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = wp_kses(
1428 $_POST[ '_mw_adminimize_advice_txt' ],
1429 array(
1430 'a' => array(
1431 'href' => array(),
1432 'title' => array()
1433 ),
1434 'br' => array(),
1435 'em' => array(),
1436 'strong' => array(),
1437 )
1438 );
1439 } else {
1440 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = '';
1441 }
1442
1443 if ( isset( $_POST[ '_mw_adminimize_timestamp' ] ) ) {
1444 $adminimizeoptions[ '_mw_adminimize_timestamp' ] = (int) $_POST[ '_mw_adminimize_timestamp' ];
1445 } else {
1446 $adminimizeoptions[ '_mw_adminimize_timestamp' ] = 0;
1447 }
1448
1449 if ( isset( $_POST[ '_mw_adminimize_db_redirect_txt' ] ) ) {
1450 $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = esc_url( $_POST[ '_mw_adminimize_db_redirect_txt' ] );
1451 } else {
1452 $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = '';
1453 }
1454
1455 // menu update
1456 foreach ( $user_roles as $role ) {
1457 if ( isset( $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] ) ) {
1458 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] =
1459 $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ];
1460 } else {
1461 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
1462 }
1463
1464 if ( isset( $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] ) ) {
1465 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] =
1466 $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ];
1467 } else {
1468 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1469 }
1470 }
1471
1472 // @ToDo After release of WP 4.7, switch to sanitize_textarea_field()
1473
1474 // own menu slug
1475 if ( isset( $_POST[ '_mw_adminimize_own_menu_slug' ] ) ) {
1476 $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = stripslashes(
1477 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_slug' ] )
1478 );
1479 } else {
1480 $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = '';
1481 }
1482 // own custom menu slug
1483 if ( isset( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] ) ) {
1484 $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = stripslashes(
1485 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] )
1486 );
1487 } else {
1488 $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = '';
1489 }
1490
1491 // global_options, metaboxes update
1492 foreach ( $user_roles as $role ) {
1493
1494 // global options
1495 if ( isset( $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] ) ) {
1496 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] =
1497 $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1498 } else {
1499 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1500 }
1501
1502 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] ) ) {
1503 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] =
1504 $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ];
1505 } else {
1506 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
1507 }
1508
1509 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] ) ) {
1510 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] =
1511 $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ];
1512 } else {
1513 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
1514 }
1515
1516 foreach ( $post_types as $post_type ) {
1517 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] ) ) {
1518 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] =
1519 $_POST[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ];
1520 } else {
1521 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = array();
1522 }
1523 }
1524
1525 if ( isset( $_POST[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] ) ) {
1526 $adminimizeoptions[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] =
1527 $_POST[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ];
1528 } else {
1529 $adminimizeoptions[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] = array();
1530 }
1531
1532 // wp nav menu options
1533 if ( isset( $_POST[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] ) ) {
1534 $adminimizeoptions[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] =
1535 $_POST[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ];
1536 } else {
1537 $adminimizeoptions[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] = array();
1538 }
1539
1540 // widget options
1541 if ( isset( $_POST[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] ) ) {
1542 $adminimizeoptions[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] =
1543 $_POST[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ];
1544 } else {
1545 $adminimizeoptions[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] = array();
1546 }
1547
1548 // wp dashboard option
1549 if ( isset( $_POST[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] ) ) {
1550 $adminimizeoptions[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] =
1551 $_POST[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ];
1552 } else {
1553 $adminimizeoptions[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] = array();
1554 }
1555 }
1556
1557 // own options
1558 if ( isset( $_POST[ '_mw_adminimize_own_values' ] ) ) {
1559 $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes(
1560 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values' ] )
1561 );
1562 } else {
1563 $adminimizeoptions[ '_mw_adminimize_own_values' ] = '';
1564 }
1565
1566 if ( isset( $_POST[ '_mw_adminimize_own_options' ] ) ) {
1567 $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes(
1568 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options' ] )
1569 );
1570 } else {
1571 $adminimizeoptions[ '_mw_adminimize_own_options' ] = '';
1572 }
1573
1574 // own post options
1575 if ( isset( $_POST[ '_mw_adminimize_own_post_values' ] ) ) {
1576 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = stripslashes(
1577 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_values' ] )
1578 );
1579 } else {
1580 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = '';
1581 }
1582
1583 if ( isset( $_POST[ '_mw_adminimize_own_post_options' ] ) ) {
1584 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = stripslashes(
1585 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_options' ] )
1586 );
1587 } else {
1588 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = '';
1589 }
1590
1591 // own page options
1592 if ( isset( $_POST[ '_mw_adminimize_own_page_values' ] ) ) {
1593 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = stripslashes(
1594 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_values' ] )
1595 );
1596 } else {
1597 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = '';
1598 }
1599
1600 if ( isset( $_POST[ '_mw_adminimize_own_page_options' ] ) ) {
1601 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = stripslashes(
1602 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_options' ] )
1603 );
1604 } else {
1605 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = '';
1606 }
1607
1608 // own custom post options
1609 foreach ( $post_types as $post_type ) {
1610 if ( isset( $_POST[ '_mw_adminimize_own_values_' . $post_type ] ) ) {
1611 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = stripslashes(
1612 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values_' . $post_type ] )
1613 );
1614 } else {
1615 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = '';
1616 }
1617
1618 if ( isset( $_POST[ '_mw_adminimize_own_options_' . $post_type ] ) ) {
1619 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = stripslashes(
1620 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options_' . $post_type ] )
1621 );
1622 } else {
1623 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = '';
1624 }
1625 }
1626
1627 // own link options
1628 if ( isset( $_POST[ '_mw_adminimize_own_link_values' ] ) ) {
1629 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = stripslashes(
1630 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_values' ] )
1631 );
1632 } else {
1633 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = '';
1634 }
1635
1636 if ( isset( $_POST[ '_mw_adminimize_own_link_options' ] ) ) {
1637 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = stripslashes(
1638 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_options' ] )
1639 );
1640 } else {
1641 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = '';
1642 }
1643
1644 // wp nav menu options
1645 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_values' ] ) ) {
1646 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = stripslashes(
1647 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_values' ] )
1648 );
1649 } else {
1650 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = '';
1651 }
1652
1653 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_options' ] ) ) {
1654 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = stripslashes(
1655 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_options' ] )
1656 );
1657 } else {
1658 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = '';
1659 }
1660
1661 // widget options
1662 if ( isset( $_POST[ '_mw_adminimize_own_widget_values' ] ) ) {
1663 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = stripslashes(
1664 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_values' ] )
1665 );
1666 } else {
1667 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = '';
1668 }
1669
1670 if ( isset( $_POST[ '_mw_adminimize_own_widget_options' ] ) ) {
1671 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = stripslashes(
1672 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_options' ] )
1673 );
1674 } else {
1675 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = '';
1676 }
1677
1678 // own dashboard options
1679 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_values' ] ) ) {
1680 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = stripslashes(
1681 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_values' ] )
1682 );
1683 } else {
1684 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = '';
1685 }
1686
1687 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_options' ] ) ) {
1688 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = stripslashes(
1689 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_options' ] )
1690 );
1691 } else {
1692 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = '';
1693 }
1694
1695 $adminimizeoptions[ 'mw_adminimize_dashboard_widgets' ] = _mw_adminimize_get_option_value(
1696 'mw_adminimize_dashboard_widgets'
1697 );
1698
1699 if ( isset( $GLOBALS[ 'menu' ] ) ) {
1700 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $GLOBALS[ 'menu' ];
1701 }
1702 if ( isset( $GLOBALS[ 'submenu' ] ) ) {
1703 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1704 }
1705
1706 /**
1707 * Filter the adminimize options.
1708 *
1709 * Make the options filterable, so we can modify what is saved before it's sent to the db
1710 *
1711 * @since 1.11.6
1712 *
1713 * @param array $adminimizeoptions the original options.
1714 * @param array $user_roles Array of the user roles.
1715 * @param array $_POST Post data.
1716 */
1717 $adminimizeoptions = apply_filters( 'mw_adminimize_options_before_update', $adminimizeoptions, $user_roles, $_POST );
1718
1719 // update
1720 $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1721
1722 $myErrors = new _mw_adminimize_message_class();
1723 if ( $update_status ) {
1724 $message = $myErrors->get_error(
1725 '_mw_adminimize_update'
1726 );
1727 } else {
1728 $message = $myErrors->get_error(
1729 '_mw_adminimize_access_denied'
1730 );
1731 }
1732 echo '<div id="message" class="notice notice-success"><p>' . $message . '</p></div>';
1733
1734 return TRUE;
1735 }
1736
1737 /**
1738 * Delete options in database
1739 */
1740 function _mw_adminimize_uninstall() {
1741
1742 wp_cache_delete( 'mw_adminimize' );
1743 delete_site_option( 'mw_adminimize' );
1744 delete_option( 'mw_adminimize' );
1745 }
1746
1747 /**
1748 * Install options in database
1749 */
1750 function _mw_adminimize_install() {
1751
1752 if ( ! is_admin() ) {
1753 return;
1754 }
1755
1756 // If is AJAX Call.
1757 if ( defined('DOING_AJAX') && DOING_AJAX ) {
1758 return;
1759 }
1760
1761 global $menu, $submenu;
1762
1763 $user_roles = _mw_adminimize_get_all_user_roles();
1764 $adminimizeoptions = array();
1765
1766 foreach ( $user_roles as $role ) {
1767 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
1768 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1769 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1770 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1771 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
1772 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
1773 $args = array(
1774 'public' => TRUE,
1775 '_builtin' => FALSE,
1776 );
1777 foreach ( get_post_types( $args ) as $post_type ) {
1778 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = array();
1779 }
1780 }
1781
1782 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
1783 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
1784
1785 if ( _mw_adminimize_is_active_on_multisite() ) {
1786 add_site_option( 'mw_adminimize', $adminimizeoptions );
1787 } else {
1788 add_option( 'mw_adminimize', $adminimizeoptions );
1789 }
1790 wp_cache_add( 'mw_adminimize', $adminimizeoptions );
1791 }
1792
1793 /**
1794 * Make sure adminimize option is complete when a role json file is imported
1795 *
1796 * @param array $roles_options
1797 *
1798 * @return array
1799 */
1800 function _mw_adminimize_roles_complete_options( $roles_options ){
1801
1802 $adminimizeoption = _mw_adminimize_get_option_value();
1803
1804 foreach ( $roles_options as $role_option_name => $role_option_value ){
1805 $adminimizeoption[$role_option_name] = $role_option_value;
1806 }
1807
1808 return $adminimizeoption;
1809 }
1810
1811 /**
1812 * Check if options comes from roles adminimize settings export
1813 *
1814 * @param array $options
1815 *
1816 * @return bool
1817 */
1818 function _mw_adminimize_is_roles_options_import( $options ){
1819 global $wp_roles;
1820
1821 $roles_options = [];
1822 foreach ( $wp_roles->role_names as $role_slug => $role_name ){
1823
1824 $role_options = array_filter(
1825 $options, function ( $option_key ) use ( $role_slug ) {
1826 return stripos( $option_key, '_' . $role_slug ) !== false;
1827 }, ARRAY_FILTER_USE_KEY
1828 );
1829
1830 if ( empty( $roles_options ) ){
1831 $roles_options = $role_options;
1832 } else {
1833 $roles_options = array_merge( $roles_options, $role_options );
1834 }
1835 }
1836
1837 if ( count( $options ) === count( $roles_options ) ){
1838 return true;
1839 }
1840 }
1841