PluginProbe
Adminimize / 1.11.8
Adminimize v1.11.8
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.8, at adminimize.php

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