PluginProbe
Adminimize / 1.11.7
Adminimize v1.11.7
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.7, at adminimize.php

1,830 lines 56.3 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.7
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 2020-07-15
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 // Check, if is Sub Menu item in the user role settings?
693 if (
694 isset( $mw_adminimize_submenu )
695 && _mw_adminimize_in_arrays(
696 array( $subitem[ 2 ], $menu_slug . '__' . $subindex ),
697 $mw_adminimize_submenu
698 )
699 ) {
700 remove_submenu_page( $menu_slug, $subitem[ 2 ] );
701 // Prevent access to the page with the slug, there was inactive.
702 _mw_adminimize_check_page_access( $subitem[ 2 ] );
703 }
704 }
705 }
706 }
707 }
708
709 }
710
711 /**
712 * Set global options in backend in all areas.
713 */
714 function _mw_adminimize_set_global_option() {
715
716 // exclude super admin
717 if ( _mw_adminimize_exclude_super_admin() ) {
718 return NULL;
719 }
720
721 // Leave the settings screen from Adminimize to see all areas on settings.
722 if ( _mw_adminimize_exclude_settings_page() ) {
723 return;
724 }
725
726 $user_roles = _mw_adminimize_get_all_user_roles();
727 $_mw_adminimize_admin_head = '';
728 $disabled_global_option = array();
729 $disabled_global_option_ = array();
730 $user = wp_get_current_user();
731
732 // Get settings for each role.
733 foreach ( $user_roles as $role ) {
734 $disabled_global_option_[ $role ] = (array) _mw_adminimize_get_option_value(
735 'mw_adminimize_disabled_global_option_' . $role . '_items'
736 );
737 }
738
739 // Write global options in an var.
740 foreach ( $user_roles as $role ) {
741 if ( in_array( $role, $user->roles, TRUE ) && _mw_adminimize_current_user_has_role( $role ) ) {
742
743 // Create array about all items with all affected roles, important for multiple roles.
744 foreach ( (array) $disabled_global_option_[ $role ] as $global_item ) {
745 $disabled_global_option[] = $global_item;
746 }
747 }
748 }
749
750 // Support Multiple Roles for users.
751 if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
752 $disabled_global_option = _mw_adminimize_get_duplicate( $disabled_global_option );
753 }
754 $global_options = implode( ', ', $disabled_global_option );
755
756 if ( 0 === strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
757 global $_wp_admin_css_colors;
758 $_wp_admin_css_colors = 0;
759 }
760 $_mw_adminimize_admin_head .= '<!-- Set Adminimize global options -->' . "\n";
761 $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display:none !important;}</style>' . "\n";
762
763 // List options if the debug option is active.
764 _mw_adminimize_debug($global_options, 'Adminimize: List active global options:');
765
766 if ( '' !== $global_options ) {
767 echo $_mw_adminimize_admin_head;
768 }
769 }
770
771 /**
772 * Set metabox options from database an area post.
773 */
774 function _mw_adminimize_set_metabox_post_option() {
775
776 // exclude super admin
777 if ( _mw_adminimize_exclude_super_admin() ) {
778 return;
779 }
780
781 // Leave the settings screen from Adminimize to see all areas on settings.
782 if ( _mw_adminimize_exclude_settings_page() ) {
783 return;
784 }
785
786 $user_roles = _mw_adminimize_get_all_user_roles();
787 $_mw_adminimize_admin_head = '';
788 // It's better to declare $metaboxes as an array for better manipulation later.
789 $metaboxes = array();
790
791 foreach ( $user_roles as $role ) {
792 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
793 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
794 );
795
796 if ( ! isset( $disabled_metaboxes_post_[ $role ]['0'] ) ) {
797 $disabled_metaboxes_post_[ $role ]['0'] = '';
798
799 /**
800 * @todo Think why keep going if $role does not even have boxes to hide? We may as well jump to the next $role.
801 */
802 continue;
803 }
804
805 /**
806 * @todo Think why call a function as we can use a global variable already declared by WordPress.
807 * @var WP_User $user Instance of WP_User.
808 * @since 1.7.8
809 * @version 1.11.4
810 */
811 $user = $GLOBALS['current_user'];
812 if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
813 if ( _mw_adminimize_current_user_has_role( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
814 && is_array(
815 $disabled_metaboxes_post_[ $role ]
816 )
817 ) {
818 // The previous way $metaboxes was being filled it could be at some point non empty and empty afterwards.
819 // For instance, if a $role has items to be hidden and the user has this $role, $metaboxes will be filled.
820 // 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.
821 $metaboxes[] = implode( ',', $disabled_metaboxes_post_[ $role ] );
822 }
823 }
824 }
825
826 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox post options -->' . "\n";
827 // And below we implode $metaboxes because it's an array now.
828 $_mw_adminimize_admin_head .= '<style type="text/css">' .
829 implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
830
831 if ( ! empty( $metaboxes ) ) {
832 echo $_mw_adminimize_admin_head;
833 }
834 }
835
836 /**
837 * Set metabox options from database an area page.
838 */
839 function _mw_adminimize_set_metabox_page_option() {
840
841 // exclude super admin
842 if ( _mw_adminimize_exclude_super_admin() ) {
843 return NULL;
844 }
845
846 // Leave the settings screen from Adminimize to see all areas on settings.
847 if ( _mw_adminimize_exclude_settings_page() ) {
848 return;
849 }
850
851 $user_roles = _mw_adminimize_get_all_user_roles();
852 $_mw_adminimize_admin_head = '';
853 $metaboxes = '';
854
855 foreach ( $user_roles as $role ) {
856 $disabled_metaboxes_page_[ $role ] = _mw_adminimize_get_option_value(
857 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items'
858 );
859
860 if ( ! isset( $disabled_metaboxes_page_[ $role ][ '0' ] ) ) {
861 $disabled_metaboxes_page_[ $role ][ '0' ] = '';
862 }
863
864 // New since version 1.7.8.
865 $user = wp_get_current_user();
866 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
867 if ( _mw_adminimize_current_user_has_role( $role )
868 && isset( $disabled_metaboxes_page_[ $role ] )
869 && is_array( $disabled_metaboxes_page_[ $role ] )
870 ) {
871 $metaboxes = implode( ',', $disabled_metaboxes_page_[ $role ] );
872 }
873 }
874 }
875
876 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox page options -->' . "\n";
877 $_mw_adminimize_admin_head .= '<style type="text/css">' .
878 $metaboxes . ' {display:none !important;}</style>' . "\n";
879
880 if ( ! empty( $metaboxes ) ) {
881 echo $_mw_adminimize_admin_head;
882 }
883 }
884
885 /**
886 * Set metabox options from database an area post.
887 */
888 function _mw_adminimize_set_metabox_cp_option() {
889
890 // exclude super admin
891 if ( _mw_adminimize_exclude_super_admin() ) {
892 return NULL;
893 }
894
895 // Leave the settings screen from Adminimize to see all areas on settings.
896 if ( _mw_adminimize_exclude_settings_page() ) {
897 return;
898 }
899
900 $post_id = 0;
901 if ( isset( $_GET[ 'post' ] ) ) {
902 $post_id = (int) $_GET[ 'post' ];
903 } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
904 $post_id = (int) $_POST[ 'post_ID' ];
905 }
906
907 $current_post_type = $GLOBALS[ 'post_type' ];
908 if ( ! isset( $current_post_type ) ) {
909 $current_post_type = get_post_type( $post_id );
910 }
911
912 if ( ! isset( $current_post_type ) || ! $current_post_type ) {
913 $current_post_type = str_replace( 'post_type=', '', esc_attr( $_SERVER[ 'QUERY_STRING' ] ) );
914 }
915
916 // set hard to post
917 if ( ! $current_post_type ) {
918 $current_post_type = 'post';
919 }
920
921 $user_roles = _mw_adminimize_get_all_user_roles();
922 $_mw_adminimize_admin_head = '';
923 $metaboxes = array();
924
925 foreach ( $user_roles as $role ) {
926 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
927 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
928 );
929
930 if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] ) ) {
931 $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] = '';
932
933 continue;
934 }
935
936 $user = $GLOBALS['current_user'];
937 if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
938 if ( _mw_adminimize_current_user_has_role( $role )
939 && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
940 && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
941 ) {
942 $metaboxes[] = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
943 }
944 }
945 }
946
947 $_mw_adminimize_admin_head .= '<!-- Set Adminimize post options -->' . "\n";
948 $_mw_adminimize_admin_head .= '<style type="text/css">' .
949 implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
950
951 if ( ! empty( $metaboxes ) ) {
952 echo $_mw_adminimize_admin_head;
953 }
954 }
955
956 /**
957 * Set link options in area links of back end.
958 */
959 function _mw_adminimize_set_link_option() {
960
961 // exclude super admin
962 if ( _mw_adminimize_exclude_super_admin() ) {
963 return NULL;
964 }
965
966 // Leave the settings screen from Adminimize to see all areas on settings.
967 if ( _mw_adminimize_exclude_settings_page() ) {
968 return;
969 }
970
971 $user_roles = _mw_adminimize_get_all_user_roles();
972 $_mw_adminimize_admin_head = '';
973
974 foreach ( $user_roles as $role ) {
975 $disabled_link_option_[ $role ] = _mw_adminimize_get_option_value(
976 'mw_adminimize_disabled_link_option_' . $role . '_items'
977 );
978 }
979
980 foreach ( $user_roles as $role ) {
981 if ( ! isset( $disabled_link_option_[ $role ][ '0' ] ) ) {
982 $disabled_link_option_[ $role ][ '0' ] = '';
983 }
984 }
985
986 $link_options = '';
987 foreach ( $user_roles as $role ) {
988 $user = wp_get_current_user();
989 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
990 if ( _mw_adminimize_current_user_has_role( $role )
991 && isset( $disabled_link_option_[ $role ] )
992 && is_array( $disabled_link_option_[ $role ] )
993 ) {
994 $link_options = implode( ',', $disabled_link_option_[ $role ] );
995 }
996 }
997 }
998
999 $_mw_adminimize_admin_head .= '<!-- Set Adminimize links options -->' . "\n";
1000 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1001 $link_options . ' {display:none !important;}</style>' . "\n";
1002
1003 if ( ! empty( $link_options ) ) {
1004 echo $_mw_adminimize_admin_head;
1005 }
1006 }
1007
1008 /**
1009 * Remove objects on wp nav menu.
1010 */
1011 function _mw_adminimize_set_nav_menu_option() {
1012
1013 // exclude super admin
1014 if ( _mw_adminimize_exclude_super_admin() ) {
1015 return NULL;
1016 }
1017
1018 // Leave the settings screen from Adminimize to see all areas on settings.
1019 if ( _mw_adminimize_exclude_settings_page() ) {
1020 return;
1021 }
1022
1023 $user_roles = _mw_adminimize_get_all_user_roles();
1024 $_mw_adminimize_admin_head = '';
1025
1026 foreach ( $user_roles as $role ) {
1027 $disabled_nav_menu_option_[ $role ] = _mw_adminimize_get_option_value(
1028 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items'
1029 );
1030 }
1031
1032 foreach ( $user_roles as $role ) {
1033 if ( ! isset( $disabled_nav_menu_option_[ $role ][ '0' ] ) ) {
1034 $disabled_nav_menu_option_[ $role ][ '0' ] = '';
1035 }
1036 }
1037
1038 $nav_menu_options = '';
1039 foreach ( $user_roles as $role ) {
1040 $user = wp_get_current_user();
1041 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1042 if ( _mw_adminimize_current_user_has_role( $role )
1043 && isset( $disabled_nav_menu_option_[ $role ] )
1044 && is_array( $disabled_nav_menu_option_[ $role ] )
1045 ) {
1046 $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
1047 }
1048 }
1049 }
1050
1051 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
1052 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1053 $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1054
1055 if ( $nav_menu_options ) {
1056 echo $_mw_adminimize_admin_head;
1057 }
1058 }
1059
1060 /**
1061 * Remove areas in Widget Settings
1062 */
1063 function _mw_adminimize_set_widget_option() {
1064
1065 // exclude super admin
1066 if ( _mw_adminimize_exclude_super_admin() ) {
1067 return NULL;
1068 }
1069
1070 // Leave the settings screen from Adminimize to see all areas on settings.
1071 if ( _mw_adminimize_exclude_settings_page() ) {
1072 return;
1073 }
1074
1075 $user_roles = _mw_adminimize_get_all_user_roles();
1076 $_mw_adminimize_admin_head = '';
1077
1078 foreach ( $user_roles as $role ) {
1079 $disabled_widget_option_[ $role ] = _mw_adminimize_get_option_value(
1080 'mw_adminimize_disabled_widget_option_' . $role . '_items'
1081 );
1082 }
1083
1084 foreach ( $user_roles as $role ) {
1085 if ( ! isset( $disabled_widget_option_[ $role ][ '0' ] ) ) {
1086 $disabled_widget_option_[ $role ][ '0' ] = '';
1087 }
1088 }
1089
1090 $widget_options = '';
1091 foreach ( $user_roles as $role ) {
1092 $user = wp_get_current_user();
1093 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
1094 if ( _mw_adminimize_current_user_has_role( $role )
1095 && isset( $disabled_widget_option_[ $role ] )
1096 && is_array( $disabled_widget_option_[ $role ] )
1097 ) {
1098 $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
1099 }
1100 }
1101 }
1102
1103 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1104 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1105 $widget_options . ' {display: none !important;}</style>' . "\n";
1106
1107 if ( $widget_options ) {
1108 echo $_mw_adminimize_admin_head;
1109 }
1110 }
1111
1112 /**
1113 * Print small user-info.
1114 */
1115 function _mw_adminimize_small_user_info() {
1116
1117 ?>
1118 <div id="small_user_info">
1119 <p>
1120 <a href="<?php echo wp_nonce_url(
1121 site_url( 'wp-login.php?action=logout' ),
1122 'log-out'
1123 ) ?>"
1124 title="<?php esc_attr_e( 'Log Out' ) ?>"><?php esc_attr_e( 'Log Out' ); ?></a>
1125 </p>
1126 </div>
1127 <?php
1128 }
1129
1130 // include helping functions
1131 require_once 'inc-setup/DebugListener.php';
1132 require_once 'inc-setup/helping_hands.php';
1133
1134 // Include message class.
1135 require_once 'inc-setup/messages.php';
1136
1137 // inc. settings page
1138 require_once 'adminimize_page.php';
1139
1140 // dashboard options
1141 require_once 'inc-setup/dashboard.php';
1142
1143 // widget options
1144 require_once 'inc-setup/widget.php';
1145 require_once 'inc-setup/footer.php';
1146 require_once 'inc-setup/admin-footer.php';
1147
1148 // remove admin bar
1149 require_once 'inc-setup/remove-admin-bar.php';
1150
1151 // admin bar helper, setup
1152 // work always in frontend
1153 require_once 'inc-setup/admin-bar-items.php';
1154
1155 // meta boxes helper, setup
1156 // @TODO Meta Boxes: not ready for productive systems.
1157 //require_once( 'inc-setup/meta-boxes.php' );
1158
1159 // Remove Admin Notices.
1160 require_once 'inc-setup/remove-admin-notices.php';
1161
1162 // Add Ex-Import functions.
1163 require_once 'inc-setup/export.php';
1164 require_once 'inc-setup/import.php';
1165
1166 /**
1167 * Add action link(s) to plugins page
1168 *
1169 * @param array $links
1170 * @param string $file
1171 *
1172 * @return array $links
1173 */
1174 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1175
1176 /* create link */
1177 if ( FB_ADMINIMIZE_BASENAME === $file ) {
1178 array_unshift(
1179 $links,
1180 sprintf(
1181 '<a href="options-general.php?page=adminimize-options">%s</a>',
1182 esc_attr__( 'Settings' )
1183 )
1184 );
1185 }
1186
1187 return $links;
1188 }
1189
1190 /**
1191 * Add settings in plugin-admin-page.
1192 */
1193 function _mw_adminimize_add_settings_page() {
1194
1195 $pagehook = add_options_page(
1196 esc_attr__( 'Adminimize Options', 'adminimize' ),
1197 esc_attr__( 'Adminimize', 'adminimize' ),
1198 'manage_options',
1199 'adminimize-options',
1200 '_mw_adminimize_options'
1201 );
1202
1203 if ( ! is_network_admin() ) {
1204 add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
1205 }
1206 add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
1207 }
1208
1209 /**
1210 * Enqueue script and styles for the settings page.
1211 */
1212 function _mw_adminimize_on_load_page() {
1213
1214 // Load translation files on options page.
1215 _mw_adminimize_textdomain();
1216
1217 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1218
1219 wp_enqueue_style( 'select2-style', plugins_url( 'css/select2' . $suffix . '.css', __FILE__ ), [], false );
1220 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1221 wp_enqueue_style( 'adminimize-style' );
1222
1223 wp_enqueue_script( 'select2-script', plugins_url( 'js/select2' . $suffix . '.js', __FILE__ ), array( 'jquery' ),'',false );
1224 wp_register_script(
1225 'adminimize-settings-script',
1226 plugins_url( 'js/adminimize' . $suffix . '.js', __FILE__ ),
1227 array( 'jquery' ),
1228 '',
1229 TRUE
1230 );
1231 wp_enqueue_script( 'adminimize-settings-script' );
1232 }
1233
1234 /**
1235 * Get setting value for each options key.
1236 *
1237 * @param string|bool $key
1238 *
1239 * @return string
1240 */
1241 function _mw_adminimize_get_option_value( $key = FALSE ) {
1242
1243 $adminimizeoptions = FALSE;
1244 if ( ! _mw_adminimize_exclude_settings_page() ) {
1245 $adminimizeoptions = wp_cache_get( 'mw_adminimize' );
1246 }
1247
1248 if ( FALSE === $adminimizeoptions ) {
1249 // check for use on multisite
1250 if ( _mw_adminimize_is_active_on_multisite() ) {
1251 $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1252 } else {
1253 $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
1254 }
1255 wp_cache_set( 'mw_adminimize', $adminimizeoptions );
1256 }
1257
1258 if ( ! $key ) {
1259 return $adminimizeoptions;
1260 }
1261
1262 return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : NULL;
1263 }
1264
1265 /**
1266 * Update options.
1267 *
1268 * @param array $options
1269 *
1270 * @return bool
1271 */
1272 function _mw_adminimize_update_option( $options ) {
1273
1274 if ( ! current_user_can( 'manage_options' ) ) {
1275 return FALSE;
1276 }
1277
1278 if ( _mw_adminimize_is_roles_options_import( $options ) ){
1279 $options = _mw_adminimize_roles_complete_options( $options );
1280 }
1281
1282 // Remove slashes always.
1283 foreach ( $options as $key => $value ) {
1284 $options[ $key ] = stripslashes_deep( $value );
1285 }
1286
1287 // Kill the cache for the settings page.
1288 wp_cache_delete( 'mw_adminimize' );
1289 if ( _mw_adminimize_is_active_on_multisite() ) {
1290 update_site_option( 'mw_adminimize', $options );
1291 } else {
1292 update_option( 'mw_adminimize', $options );
1293 }
1294 wp_cache_add( 'mw_adminimize', $options );
1295
1296 return TRUE;
1297 }
1298
1299 /**
1300 * Update options in database
1301 */
1302 function _mw_adminimize_update() {
1303
1304 $user_roles = _mw_adminimize_get_all_user_roles();
1305 $args = array( 'public' => TRUE, '_builtin' => FALSE );
1306 $post_types = get_post_types( $args );
1307
1308 // Admin Bar Back end settings
1309 $adminimizeoptions[ 'mw_adminimize_admin_bar_nodes' ] = _mw_adminimize_get_option_value(
1310 'mw_adminimize_admin_bar_nodes'
1311 );
1312 // admin bar back end options
1313 foreach ( $user_roles as $role ) {
1314 // admin bar back end options
1315 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] ) ) {
1316 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ];
1317 } else {
1318 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1319 }
1320 }
1321
1322 // Plugin Self Settings.
1323 if ( isset( $_POST[ 'mw_adminimize_debug' ] ) ) {
1324 $adminimizeoptions[ 'mw_adminimize_debug' ] = (int) $_POST[ 'mw_adminimize_debug' ];
1325 } else {
1326 $adminimizeoptions[ 'mw_adminimize_debug' ] = 0;
1327 }
1328
1329 if ( isset( $_POST[ 'mw_adminimize_multiple_roles' ] ) ) {
1330 $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = (int) $_POST[ 'mw_adminimize_multiple_roles' ];
1331 } else {
1332 $adminimizeoptions[ 'mw_adminimize_multiple_roles' ] = 0;
1333 }
1334
1335 if ( isset( $_POST[ 'mw_adminimize_support_bbpress' ] ) ) {
1336 $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = (int) $_POST[ 'mw_adminimize_support_bbpress' ];
1337 } else {
1338 $adminimizeoptions[ 'mw_adminimize_support_bbpress' ] = 0;
1339 }
1340
1341 if ( isset( $_POST[ 'mw_adminimize_prevent_page_access' ] ) ) {
1342 $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = (int) $_POST[ 'mw_adminimize_prevent_page_access' ];
1343 } else {
1344 $adminimizeoptions[ 'mw_adminimize_prevent_page_access' ] = 0;
1345 }
1346
1347 // Admin Bar Front end settings
1348 $adminimizeoptions[ 'mw_adminimize_admin_bar_frontend_nodes' ] = _mw_adminimize_get_option_value(
1349 'mw_adminimize_admin_bar_frontend_nodes'
1350 );
1351 // admin bar front end options
1352 foreach ( $user_roles as $role ) {
1353 // admin bar front-end options
1354 if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] ) ) {
1355 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ];
1356 } else {
1357 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_frontend_' . $role . '_items' ] = array();
1358 }
1359 }
1360
1361 if ( isset( $_POST[ '_mw_adminimize_user_info' ] ) ) {
1362 $adminimizeoptions[ '_mw_adminimize_user_info' ] = (int) $_POST[ '_mw_adminimize_user_info' ];
1363 } else {
1364 $adminimizeoptions[ '_mw_adminimize_user_info' ] = 0;
1365 }
1366
1367 if ( isset( $_POST[ '_mw_adminimize_footer' ] ) ) {
1368 $adminimizeoptions[ '_mw_adminimize_footer' ] = (int) $_POST[ '_mw_adminimize_footer' ];
1369 } else {
1370 $adminimizeoptions[ '_mw_adminimize_footer' ] = 0;
1371 }
1372
1373 if ( isset( $_POST[ '_mw_adminimize_header' ] ) ) {
1374 $adminimizeoptions[ '_mw_adminimize_header' ] = (int) $_POST[ '_mw_adminimize_header' ];
1375 } else {
1376 $adminimizeoptions[ '_mw_adminimize_header' ] = 0;
1377 }
1378
1379 if ( isset( $_POST[ '_mw_adminimize_exclude_super_admin' ] ) ) {
1380 $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = (int) $_POST[ '_mw_adminimize_exclude_super_admin' ];
1381 } else {
1382 $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = 0;
1383 }
1384
1385 if ( isset( $_POST[ '_mw_adminimize_tb_window' ] ) ) {
1386 $adminimizeoptions[ '_mw_adminimize_tb_window' ] = (int) $_POST[ '_mw_adminimize_tb_window' ];
1387 } else {
1388 $adminimizeoptions[ '_mw_adminimize_tb_window' ] = 0;
1389 }
1390
1391 if ( isset( $_POST[ '_mw_adminimize_cat_full' ] ) ) {
1392 $adminimizeoptions[ '_mw_adminimize_cat_full' ] = (int) $_POST[ '_mw_adminimize_cat_full' ];
1393 } else {
1394 $adminimizeoptions[ '_mw_adminimize_cat_full' ] = 0;
1395 }
1396
1397 if ( isset( $_POST[ '_mw_adminimize_db_redirect' ] ) ) {
1398 $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = (int) $_POST[ '_mw_adminimize_db_redirect' ];
1399 } else {
1400 $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = 0;
1401 }
1402
1403 if ( isset( $_POST[ '_mw_adminimize_ui_redirect' ] ) ) {
1404 $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = (int) $_POST[ '_mw_adminimize_ui_redirect' ];
1405 } else {
1406 $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = 0;
1407 }
1408
1409 if ( isset( $_POST[ '_mw_adminimize_advice' ] ) ) {
1410 $adminimizeoptions[ '_mw_adminimize_advice' ] = (int) $_POST[ '_mw_adminimize_advice' ];
1411 } else {
1412 $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
1413 }
1414
1415 if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
1416 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = wp_kses(
1417 $_POST[ '_mw_adminimize_advice_txt' ],
1418 array(
1419 'a' => array(
1420 'href' => array(),
1421 'title' => array()
1422 ),
1423 'br' => array(),
1424 'em' => array(),
1425 'strong' => array(),
1426 )
1427 );
1428 } else {
1429 $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = '';
1430 }
1431
1432 if ( isset( $_POST[ '_mw_adminimize_timestamp' ] ) ) {
1433 $adminimizeoptions[ '_mw_adminimize_timestamp' ] = (int) $_POST[ '_mw_adminimize_timestamp' ];
1434 } else {
1435 $adminimizeoptions[ '_mw_adminimize_timestamp' ] = 0;
1436 }
1437
1438 if ( isset( $_POST[ '_mw_adminimize_db_redirect_txt' ] ) ) {
1439 $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = esc_url( $_POST[ '_mw_adminimize_db_redirect_txt' ] );
1440 } else {
1441 $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = '';
1442 }
1443
1444 // menu update
1445 foreach ( $user_roles as $role ) {
1446 if ( isset( $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] ) ) {
1447 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] =
1448 $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ];
1449 } else {
1450 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
1451 }
1452
1453 if ( isset( $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] ) ) {
1454 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] =
1455 $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ];
1456 } else {
1457 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1458 }
1459 }
1460
1461 // @ToDo After release of WP 4.7, switch to sanitize_textarea_field()
1462
1463 // own menu slug
1464 if ( isset( $_POST[ '_mw_adminimize_own_menu_slug' ] ) ) {
1465 $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = stripslashes(
1466 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_slug' ] )
1467 );
1468 } else {
1469 $adminimizeoptions[ '_mw_adminimize_own_menu_slug' ] = '';
1470 }
1471 // own custom menu slug
1472 if ( isset( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] ) ) {
1473 $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = stripslashes(
1474 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_menu_custom_slug' ] )
1475 );
1476 } else {
1477 $adminimizeoptions[ '_mw_adminimize_own_menu_custom_slug' ] = '';
1478 }
1479
1480 // global_options, metaboxes update
1481 foreach ( $user_roles as $role ) {
1482
1483 // global options
1484 if ( isset( $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] ) ) {
1485 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] =
1486 $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1487 } else {
1488 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1489 }
1490
1491 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] ) ) {
1492 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] =
1493 $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ];
1494 } else {
1495 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
1496 }
1497
1498 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] ) ) {
1499 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] =
1500 $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ];
1501 } else {
1502 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
1503 }
1504
1505 foreach ( $post_types as $post_type ) {
1506 if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] ) ) {
1507 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] =
1508 $_POST[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ];
1509 } else {
1510 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = array();
1511 }
1512 }
1513
1514 if ( isset( $_POST[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] ) ) {
1515 $adminimizeoptions[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] =
1516 $_POST[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ];
1517 } else {
1518 $adminimizeoptions[ 'mw_adminimize_disabled_link_option_' . $role . '_items' ] = array();
1519 }
1520
1521 // wp nav menu options
1522 if ( isset( $_POST[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] ) ) {
1523 $adminimizeoptions[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] =
1524 $_POST[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ];
1525 } else {
1526 $adminimizeoptions[ 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items' ] = array();
1527 }
1528
1529 // widget options
1530 if ( isset( $_POST[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] ) ) {
1531 $adminimizeoptions[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] =
1532 $_POST[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ];
1533 } else {
1534 $adminimizeoptions[ 'mw_adminimize_disabled_widget_option_' . $role . '_items' ] = array();
1535 }
1536
1537 // wp dashboard option
1538 if ( isset( $_POST[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] ) ) {
1539 $adminimizeoptions[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] =
1540 $_POST[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ];
1541 } else {
1542 $adminimizeoptions[ 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' ] = array();
1543 }
1544 }
1545
1546 // own options
1547 if ( isset( $_POST[ '_mw_adminimize_own_values' ] ) ) {
1548 $adminimizeoptions[ '_mw_adminimize_own_values' ] = stripslashes(
1549 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values' ] )
1550 );
1551 } else {
1552 $adminimizeoptions[ '_mw_adminimize_own_values' ] = '';
1553 }
1554
1555 if ( isset( $_POST[ '_mw_adminimize_own_options' ] ) ) {
1556 $adminimizeoptions[ '_mw_adminimize_own_options' ] = stripslashes(
1557 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options' ] )
1558 );
1559 } else {
1560 $adminimizeoptions[ '_mw_adminimize_own_options' ] = '';
1561 }
1562
1563 // own post options
1564 if ( isset( $_POST[ '_mw_adminimize_own_post_values' ] ) ) {
1565 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = stripslashes(
1566 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_values' ] )
1567 );
1568 } else {
1569 $adminimizeoptions[ '_mw_adminimize_own_post_values' ] = '';
1570 }
1571
1572 if ( isset( $_POST[ '_mw_adminimize_own_post_options' ] ) ) {
1573 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = stripslashes(
1574 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_post_options' ] )
1575 );
1576 } else {
1577 $adminimizeoptions[ '_mw_adminimize_own_post_options' ] = '';
1578 }
1579
1580 // own page options
1581 if ( isset( $_POST[ '_mw_adminimize_own_page_values' ] ) ) {
1582 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = stripslashes(
1583 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_values' ] )
1584 );
1585 } else {
1586 $adminimizeoptions[ '_mw_adminimize_own_page_values' ] = '';
1587 }
1588
1589 if ( isset( $_POST[ '_mw_adminimize_own_page_options' ] ) ) {
1590 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = stripslashes(
1591 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_page_options' ] )
1592 );
1593 } else {
1594 $adminimizeoptions[ '_mw_adminimize_own_page_options' ] = '';
1595 }
1596
1597 // own custom post options
1598 foreach ( $post_types as $post_type ) {
1599 if ( isset( $_POST[ '_mw_adminimize_own_values_' . $post_type ] ) ) {
1600 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = stripslashes(
1601 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_values_' . $post_type ] )
1602 );
1603 } else {
1604 $adminimizeoptions[ '_mw_adminimize_own_values_' . $post_type ] = '';
1605 }
1606
1607 if ( isset( $_POST[ '_mw_adminimize_own_options_' . $post_type ] ) ) {
1608 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = stripslashes(
1609 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_options_' . $post_type ] )
1610 );
1611 } else {
1612 $adminimizeoptions[ '_mw_adminimize_own_options_' . $post_type ] = '';
1613 }
1614 }
1615
1616 // own link options
1617 if ( isset( $_POST[ '_mw_adminimize_own_link_values' ] ) ) {
1618 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = stripslashes(
1619 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_values' ] )
1620 );
1621 } else {
1622 $adminimizeoptions[ '_mw_adminimize_own_link_values' ] = '';
1623 }
1624
1625 if ( isset( $_POST[ '_mw_adminimize_own_link_options' ] ) ) {
1626 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = stripslashes(
1627 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_link_options' ] )
1628 );
1629 } else {
1630 $adminimizeoptions[ '_mw_adminimize_own_link_options' ] = '';
1631 }
1632
1633 // wp nav menu options
1634 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_values' ] ) ) {
1635 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = stripslashes(
1636 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_values' ] )
1637 );
1638 } else {
1639 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_values' ] = '';
1640 }
1641
1642 if ( isset( $_POST[ '_mw_adminimize_own_nav_menu_options' ] ) ) {
1643 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = stripslashes(
1644 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_nav_menu_options' ] )
1645 );
1646 } else {
1647 $adminimizeoptions[ '_mw_adminimize_own_nav_menu_options' ] = '';
1648 }
1649
1650 // widget options
1651 if ( isset( $_POST[ '_mw_adminimize_own_widget_values' ] ) ) {
1652 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = stripslashes(
1653 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_values' ] )
1654 );
1655 } else {
1656 $adminimizeoptions[ '_mw_adminimize_own_widget_values' ] = '';
1657 }
1658
1659 if ( isset( $_POST[ '_mw_adminimize_own_widget_options' ] ) ) {
1660 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = stripslashes(
1661 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_widget_options' ] )
1662 );
1663 } else {
1664 $adminimizeoptions[ '_mw_adminimize_own_widget_options' ] = '';
1665 }
1666
1667 // own dashboard options
1668 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_values' ] ) ) {
1669 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = stripslashes(
1670 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_values' ] )
1671 );
1672 } else {
1673 $adminimizeoptions[ '_mw_adminimize_own_dashboard_values' ] = '';
1674 }
1675
1676 if ( isset( $_POST[ '_mw_adminimize_own_dashboard_options' ] ) ) {
1677 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = stripslashes(
1678 wp_strip_all_tags( $_POST[ '_mw_adminimize_own_dashboard_options' ] )
1679 );
1680 } else {
1681 $adminimizeoptions[ '_mw_adminimize_own_dashboard_options' ] = '';
1682 }
1683
1684 $adminimizeoptions[ 'mw_adminimize_dashboard_widgets' ] = _mw_adminimize_get_option_value(
1685 'mw_adminimize_dashboard_widgets'
1686 );
1687
1688 if ( isset( $GLOBALS[ 'menu' ] ) ) {
1689 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $GLOBALS[ 'menu' ];
1690 }
1691 if ( isset( $GLOBALS[ 'submenu' ] ) ) {
1692 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1693 }
1694
1695 /**
1696 * Filter the adminimize options.
1697 *
1698 * Make the options filterable, so we can modify what is saved before it's sent to the db
1699 *
1700 * @since 1.11.6
1701 *
1702 * @param array $adminimizeoptions the original options.
1703 * @param array $user_roles Array of the user roles.
1704 * @param array $_POST Post data.
1705 */
1706 $adminimizeoptions = apply_filters( 'mw_adminimize_options_before_update', $adminimizeoptions, $user_roles, $_POST );
1707
1708 // update
1709 $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1710
1711 $myErrors = new _mw_adminimize_message_class();
1712 if ( $update_status ) {
1713 $message = $myErrors->get_error(
1714 '_mw_adminimize_update'
1715 );
1716 } else {
1717 $message = $myErrors->get_error(
1718 '_mw_adminimize_access_denied'
1719 );
1720 }
1721 echo '<div id="message" class="notice notice-success"><p>' . $message . '</p></div>';
1722
1723 return TRUE;
1724 }
1725
1726 /**
1727 * Delete options in database
1728 */
1729 function _mw_adminimize_uninstall() {
1730
1731 wp_cache_delete( 'mw_adminimize' );
1732 delete_site_option( 'mw_adminimize' );
1733 delete_option( 'mw_adminimize' );
1734 }
1735
1736 /**
1737 * Install options in database
1738 */
1739 function _mw_adminimize_install() {
1740
1741 if ( ! is_admin() ) {
1742 return;
1743 }
1744
1745 // If is AJAX Call.
1746 if ( defined('DOING_AJAX') && DOING_AJAX ) {
1747 return;
1748 }
1749
1750 global $menu, $submenu;
1751
1752 $user_roles = _mw_adminimize_get_all_user_roles();
1753 $adminimizeoptions = array();
1754
1755 foreach ( $user_roles as $role ) {
1756 $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
1757 $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
1758 $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
1759 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1760 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
1761 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
1762 $args = array(
1763 'public' => TRUE,
1764 '_builtin' => FALSE,
1765 );
1766 foreach ( get_post_types( $args ) as $post_type ) {
1767 $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items' ] = array();
1768 }
1769 }
1770
1771 $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
1772 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
1773
1774 if ( _mw_adminimize_is_active_on_multisite() ) {
1775 add_site_option( 'mw_adminimize', $adminimizeoptions );
1776 } else {
1777 add_option( 'mw_adminimize', $adminimizeoptions );
1778 }
1779 wp_cache_add( 'mw_adminimize', $adminimizeoptions );
1780 }
1781
1782 /**
1783 * Make sure adminimize option is complete when a role json file is imported
1784 *
1785 * @param array $roles_options
1786 *
1787 * @return array
1788 */
1789 function _mw_adminimize_roles_complete_options( $roles_options ){
1790
1791 $adminimizeoption = _mw_adminimize_get_option_value();
1792
1793 foreach ( $roles_options as $role_option_name => $role_option_value ){
1794 $adminimizeoption[$role_option_name] = $role_option_value;
1795 }
1796
1797 return $adminimizeoption;
1798 }
1799
1800 /**
1801 * Check if options comes from roles adminimize settings export
1802 *
1803 * @param array $options
1804 *
1805 * @return bool
1806 */
1807 function _mw_adminimize_is_roles_options_import( $options ){
1808 global $wp_roles;
1809
1810 $roles_options = [];
1811 foreach ( $wp_roles->role_names as $role_slug => $role_name ){
1812
1813 $role_options = array_filter(
1814 $options, function ( $option_key ) use ( $role_slug ) {
1815 return stripos( $option_key, '_' . $role_slug ) !== false;
1816 }, ARRAY_FILTER_USE_KEY
1817 );
1818
1819 if ( empty( $roles_options ) ){
1820 $roles_options = $role_options;
1821 } else {
1822 $roles_options = array_merge( $roles_options, $role_options );
1823 }
1824 }
1825
1826 if ( count( $options ) === count( $roles_options ) ){
1827 return true;
1828 }
1829 }
1830