PluginProbe
Adminimize / 1.11.9
Adminimize v1.11.9
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
← All changes | adminimize.php +244 -134 1.11.31.11.9 View file →
@@ -4,12 +4,12 @@
4 4 * Plugin URI: https://wordpress.org/plugins/adminimize/
5 5 * Text Domain: adminimize
6 6 * Domain Path: /languages
7 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.3
11 - * License: GPLv3+
8 + * Author: WP MEDIA SAS
9 + * Author URI: https://wp-media.me/
10 + * Version: 1.11.9
11 + * License: GPLv2+
12 12 *
13 13 * Php Version 5.6
14 14 *
15 15 * @package WordPress
@@ -14,9 +14,9 @@
14 14 *
15 15 * @package WordPress
16 16 * @author Frank Bültge <frank@bueltge.de>
17 17 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
18 - * @version 2017-11-16
18 + * @version 2022-12-09
19 19 */
20 20
21 21 /**
22 22 * The stylesheet and the initial idea is from Eric A. Meyer http://meyerweb.com/
@@ -95,31 +95,30 @@
95 95 */
96 96 function _mw_adminimize_exclude_settings_page() {
97 97
98 98 if ( ! is_admin() ) {
99 - return FALSE;
99 + return false;
100 100 }
101 101
102 - if ( defined('DOING_AJAX') && DOING_AJAX ) {
103 - return FALSE;
102 + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
103 + return false;
104 104 }
105 105
106 106 $page = '';
107 - if ( isset( $_GET[ 'page' ] ) ) {
108 - $page = esc_attr( $_GET[ 'page' ] );
107 + if ( isset( $_GET['page'] ) ) {
108 + $page = esc_attr( $_GET['page'] );
109 109 }
110 110
111 - $screen = $page;
112 111 if ( function_exists( 'get_current_screen' ) ) {
113 - $screen = get_current_screen();
114 - }
112 + $screen_tmp = get_current_screen();
115 113
116 - if ( isset( $screen->id ) ) {
117 - $screen = $screen->id;
114 + if ( isset( $screen_tmp->id ) && null !== $screen_tmp->id ) {
115 + $page = $screen_tmp->id;
116 + }
118 117 }
119 118
120 119 // Don't filter on settings page
121 - return FALSE !== strpos( $screen, 'adminimize' );
120 + return FALSE !== strpos( $page, 'adminimize' );
122 121 }
123 122
124 123 /**
125 124 * Get status, if the plugin active network wide.
@@ -131,9 +130,20 @@
131 130 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
132 131 require_once ABSPATH . '/wp-admin/includes/plugin.php';
133 132 }
134 133
135 - if ( is_multisite() && is_plugin_active_for_network( FB_ADMINIMIZE_BASENAME ) ) {
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 ) {
136 146 return TRUE;
137 147 }
138 148
139 149 return FALSE;
@@ -152,9 +162,9 @@
152 162 global $wp_roles;
153 163
154 164 $user_roles = array();
155 165
156 - if ( NULL !== $wp_roles->roles && is_array( $wp_roles->roles ) ) {
166 + if ( null !== $wp_roles->roles && is_array( $wp_roles->roles ) ) {
157 167 foreach ( $wp_roles->roles as $role => $data ) {
158 168 $user_roles[] = $role;
159 169 // The $data var contains caps, maybe for later use.
160 170 }
@@ -167,9 +177,16 @@
167 177 array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
168 178 );
169 179 }
170 180
171 - return $user_roles;
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 );
172 189 }
173 190
174 191 /**
175 192 * _mw_adminimize_get_all_user_roles_names() - Returns an array with all user roles_names in it.
@@ -203,9 +220,16 @@
203 220 )
204 221 );
205 222 }
206 223
207 - return $user_roles_names;
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 );
208 232 }
209 233
210 234 /**
211 235 * Get post type.
@@ -218,16 +242,22 @@
218 242
219 243 // We have a post so we can just get the post type from that.
220 244 if ( $post && $post->post_type ) {
221 245 return $post->post_type;
222 - } // Check the global $typenow - set in admin.php
223 - elseif ( $typenow ) {
246 + }
247 +
248 + // Check the global $typenow - set in admin.php
249 + if ( $typenow ) {
224 250 return $typenow;
225 - } // check the global $current_screen object - set in sceen.php
226 - elseif ( $current_screen && $current_screen->post_type ) {
251 + }
252 +
253 + // Check the global $current_screen object - set in screen.php
254 + if ( $current_screen && $current_screen->post_type ) {
227 255 return $current_screen->post_type;
228 - } // lastly check the post_type querystring
229 - elseif ( isset( $_REQUEST[ 'post_type' ] ) ) {
256 + }
257 +
258 + // lastly check the post_type querystring
259 + if ( isset( $_REQUEST['post_type'] ) ) {
230 260 return sanitize_key( $_REQUEST[ 'post_type' ] );
231 261 }
232 262
233 263 // we do not know the post type!
@@ -258,8 +288,15 @@
258 288 if ( ! $current_post_type ) { // set hard to post
259 289 $current_post_type = 'post';
260 290 }
261 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 +
262 299 // Get all user roles.
263 300 $user_roles = _mw_adminimize_get_all_user_roles();
264 301
265 302 // Get settings.
@@ -319,18 +356,15 @@
319 356
320 357 // Backend options
321 358 // exclude super admin
322 359 if ( ! _mw_adminimize_exclude_super_admin() && ! _mw_adminimize_exclude_settings_page() ) {
323 -
324 360 $_mw_adminimize_header = (int) _mw_adminimize_get_option_value( '_mw_adminimize_header' );
325 - switch ( $_mw_adminimize_header ) {
326 - case 1:
327 - wp_enqueue_script(
328 - '_mw_adminimize_remove_header',
329 - WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_header' . $suffix . '.js',
330 - array( 'jquery' )
331 - );
332 - break;
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 + );
333 367 }
334 368
335 369 // Post-page options.
336 370 if ( in_array( $pagenow, $def_post_pages, TRUE ) ) {
@@ -369,27 +403,31 @@
369 403 }
370 404
371 405 // Set default editor tinymce
372 406 if ( _mw_adminimize_recursive_in_array(
373 - '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
374 - $disabled_metaboxes_page_all
375 - )
376 - || _mw_adminimize_recursive_in_array(
377 - '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
378 - $disabled_metaboxes_post_all
379 - )
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 + )
380 414 ) {
381 - add_filter(
382 - 'wp_default_editor',
383 - function() {
384 - return 'tinymce';
385 - }
386 - );
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 + }
387 425 }
388 426
389 427 // Remove media buttons
390 428 if ( _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_page_all )
391 - || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
429 + || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
392 430 ) {
393 431 remove_action( 'media_buttons', 'media_buttons' );
394 432 }
395 433 }
@@ -404,9 +442,9 @@
404 442 add_action( 'admin_head', '_mw_adminimize_set_metabox_page_option', 1 );
405 443 }
406 444 // set custom post type options
407 445 if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages, TRUE )
408 - && in_array( $current_post_type, $def_custom_types, TRUE )
446 + && in_array( $current_post_type, $def_custom_types, TRUE )
409 447 ) {
410 448 add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
411 449 }
412 450 // set link option
@@ -423,9 +461,10 @@
423 461 }
424 462 }
425 463
426 464 // Change menu via settings of Adminimize.
427 -add_action( 'custom_menu_order', '_mw_adminimize_set_menu_option', 99999 );
465 +//add_filter( 'custom_menu_order', '__return_true' );
466 +add_filter( 'admin_menu', '_mw_adminimize_set_menu_option', 99999 );
428 467
429 468 // global_options
430 469 add_action( 'admin_head', '_mw_adminimize_set_global_option', 1 );
431 470 // on admin init
@@ -433,9 +472,8 @@
433 472 add_action( 'admin_init', '_mw_adminimize_admin_init' );
434 473 add_action( 'admin_menu', '_mw_adminimize_add_settings_page' );
435 474 add_action( 'admin_menu', '_mw_adminimize_remove_dashboard' );
436 475 }
437 -add_action( 'init', '_mw_adminimize_set_logout_menu', 2 );
438 476
439 477 register_activation_hook( __FILE__, '_mw_adminimize_install' );
440 478 register_uninstall_hook( __FILE__, '_mw_adminimize_uninstall' );
441 479
@@ -483,9 +521,9 @@
483 521 $redirect = FALSE;
484 522 foreach ( $user_roles as $role ) {
485 523 if ( _mw_adminimize_current_user_has_role( $role ) ) {
486 524 if ( _mw_adminimize_recursive_in_array( 'index.php', $disabled_menu_[ $role ] )
487 - || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
525 + || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
488 526 ) {
489 527 $redirect = TRUE;
490 528 }
491 529 }
@@ -556,9 +594,9 @@
556 594 function _mw_adminimize_set_menu_option() {
557 595
558 596 // exclude super admin
559 597 if ( _mw_adminimize_exclude_super_admin() ) {
560 - return NULL;
598 + return;
561 599 }
562 600
563 601 // Leave the settings screen from Adminimize to see all areas on settings.
564 602 if ( _mw_adminimize_exclude_settings_page() ) {
@@ -565,15 +603,28 @@
565 603 return;
566 604 }
567 605
568 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' );
569 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 + }
570 621 if ( ! isset( $menu ) || empty( $menu ) ) {
571 622 return;
572 623 }
573 624
574 - _mw_adminimize_debug( $menu, 'Adminimize, WordPress Menu:' );
575 - _mw_adminimize_debug( $submenu, 'Adminimize, WordPress Sub-Menu:' );
625 + _mw_adminimize_debug( $wp_menu, 'Adminimize, WordPress Menu:' );
626 + _mw_adminimize_debug( $wp_submenu, 'Adminimize, WordPress Sub-Menu:' );
576 627
577 628 $disabled_menu_ = array();
578 629 $disabled_submenu_ = array();
579 630 $user = wp_get_current_user();
@@ -594,9 +645,9 @@
594 645
595 646 // Set admin-menu.
596 647 foreach ( $user_roles as $role ) {
597 648 if ( in_array( $role, $user->roles, TRUE )
598 - && _mw_adminimize_current_user_has_role( $role )
649 + && _mw_adminimize_current_user_has_role( $role )
599 650 ) {
600 651 // Create array about all items with all affected roles.
601 652 foreach ( (array) $disabled_menu_[ $role ] as $menu_item ) {
602 653 $mw_adminimize_menu[] = $menu_item;
@@ -617,25 +668,19 @@
617 668 $mw_adminimize_menu = array_unique( $mw_adminimize_menu );
618 669 $mw_adminimize_submenu = array_unique( $mw_adminimize_submenu );
619 670 }
620 671 _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Menu Slugs to hide after Filter.' );
621 - _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Sub-Menu Slugs to hide after Filter.' );
672 + _mw_adminimize_debug( $mw_adminimize_submenu, 'Adminimize, Sub-Menu Slugs to hide after Filter.' );
622 673
623 - /**
624 - * @ToDo Remove it after feedback from users.
625 - *
626 - // Fallback on users.php on all user roles smaller admin.
627 - if ( in_array( 'users.php', $mw_adminimize_menu, TRUE ) ) {
628 - $mw_adminimize_menu[] = 'profile.php';
629 - }
630 - */
631 - foreach ( $menu as $key => $item ) {
674 + foreach ( $wp_menu as $key => $item ) {
632 675
676 + _mw_adminimize_debug( $item, 'Adminimize, Each Menu Item Array to check for hiding.' );
677 +
633 678 // Menu
634 679 if ( isset( $item[ 2 ] ) ) {
635 680 $menu_slug = $item[ 2 ];
636 681 // Check, if the Menu item in the current user role settings?
637 - if ( in_array( $menu_slug, $mw_adminimize_menu, TRUE )
682 + if ( in_array( $menu_slug, $mw_adminimize_menu, false )
638 683 ) {
639 684 remove_menu_page( $menu_slug );
640 685 // Prevent access to the page with the slug, there was inactive.
641 686 _mw_adminimize_check_page_access( $menu_slug );
@@ -641,10 +686,16 @@
641 686 _mw_adminimize_check_page_access( $menu_slug );
642 687 }
643 688
644 689 // Sub Menu Settings.
645 - if ( isset( $submenu ) && ! empty( $submenu[ $menu_slug ] ) ) {
646 - foreach ( (array) $submenu[ $menu_slug ] as $subindex => $subitem ) {
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 +
647 698 // Check, if is Sub Menu item in the user role settings?
648 699 if (
649 700 isset( $mw_adminimize_submenu )
650 701 && _mw_adminimize_in_arrays(
@@ -714,8 +765,11 @@
714 765 }
715 766 $_mw_adminimize_admin_head .= '<!-- Set Adminimize global options -->' . "\n";
716 767 $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display:none !important;}</style>' . "\n";
717 768
769 + // List options if the debug option is active.
770 + _mw_adminimize_debug($global_options, 'Adminimize: List active global options:');
771 +
718 772 if ( '' !== $global_options ) {
719 773 echo $_mw_adminimize_admin_head;
720 774 }
721 775 }
@@ -736,9 +790,10 @@
736 790 }
737 791
738 792 $user_roles = _mw_adminimize_get_all_user_roles();
739 793 $_mw_adminimize_admin_head = '';
740 - $metaboxes = '';
794 + // It's better to declare $metaboxes as an array for better manipulation later.
795 + $metaboxes = array();
741 796
742 797 foreach ( $user_roles as $role ) {
743 798 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
744 799 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
@@ -743,28 +798,42 @@
743 798 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
744 799 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
745 800 );
746 801
747 - if ( ! isset( $disabled_metaboxes_post_[ $role ][ '0' ] ) ) {
748 - $disabled_metaboxes_post_[ $role ][ '0' ] = '';
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;
749 809 }
750 810
751 - // New since version 1.7.8.
752 - $user = wp_get_current_user();
753 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
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 ) ) {
754 819 if ( _mw_adminimize_current_user_has_role( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
755 - && is_array(
756 - $disabled_metaboxes_post_[ $role ]
757 - )
820 + && is_array(
821 + $disabled_metaboxes_post_[ $role ]
822 + )
758 823 ) {
759 - $metaboxes = implode( ',', $disabled_metaboxes_post_[ $role ] );
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 ] );
760 828 }
761 829 }
762 830 }
763 831
764 832 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox post options -->' . "\n";
833 + // And below we implode $metaboxes because it's an array now.
765 834 $_mw_adminimize_admin_head .= '<style type="text/css">' .
766 - $metaboxes . ' {display:none !important;}</style>' . "\n";
835 + implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
767 836
768 837 if ( ! empty( $metaboxes ) ) {
769 838 echo $_mw_adminimize_admin_head;
770 839 }
@@ -801,10 +870,10 @@
801 870 // New since version 1.7.8.
802 871 $user = wp_get_current_user();
803 872 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
804 873 if ( _mw_adminimize_current_user_has_role( $role )
805 - && isset( $disabled_metaboxes_page_[ $role ] )
806 - && is_array( $disabled_metaboxes_page_[ $role ] )
874 + && isset( $disabled_metaboxes_page_[ $role ] )
875 + && is_array( $disabled_metaboxes_page_[ $role ] )
807 876 ) {
808 877 $metaboxes = implode( ',', $disabled_metaboxes_page_[ $role ] );
809 878 }
810 879 }
@@ -811,9 +880,9 @@
811 880 }
812 881
813 882 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox page options -->' . "\n";
814 883 $_mw_adminimize_admin_head .= '<style type="text/css">' .
815 - $metaboxes . ' {display:none !important;}</style>' . "\n";
884 + $metaboxes . ' {display:none !important;}</style>' . "\n";
816 885
817 886 if ( ! empty( $metaboxes ) ) {
818 887 echo $_mw_adminimize_admin_head;
819 888 }
@@ -856,9 +925,9 @@
856 925 }
857 926
858 927 $user_roles = _mw_adminimize_get_all_user_roles();
859 928 $_mw_adminimize_admin_head = '';
860 - $metaboxes = '';
929 + $metaboxes = array();
861 930
862 931 foreach ( $user_roles as $role ) {
863 932 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
864 933 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
@@ -863,19 +932,21 @@
863 932 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
864 933 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
865 934 );
866 935
867 - if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] ) ) {
868 - $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] = '';
936 + if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] ) ) {
937 + $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] = '';
938 +
939 + continue;
869 940 }
870 941
871 - $user = wp_get_current_user();
872 - if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
942 + $user = $GLOBALS['current_user'];
943 + if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
873 944 if ( _mw_adminimize_current_user_has_role( $role )
874 - && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
875 - && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
945 + && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
946 + && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
876 947 ) {
877 - $metaboxes = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
948 + $metaboxes[] = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
878 949 }
879 950 }
880 951 }
881 952
@@ -880,9 +951,9 @@
880 951 }
881 952
882 953 $_mw_adminimize_admin_head .= '<!-- Set Adminimize post options -->' . "\n";
883 954 $_mw_adminimize_admin_head .= '<style type="text/css">' .
884 - $metaboxes . ' {display:none !important;}</style>' . "\n";
955 + implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
885 956
886 957 if ( ! empty( $metaboxes ) ) {
887 958 echo $_mw_adminimize_admin_head;
888 959 }
@@ -932,9 +1003,9 @@
932 1003 }
933 1004
934 1005 $_mw_adminimize_admin_head .= '<!-- Set Adminimize links options -->' . "\n";
935 1006 $_mw_adminimize_admin_head .= '<style type="text/css">' .
936 - $link_options . ' {display:none !important;}</style>' . "\n";
1007 + $link_options . ' {display:none !important;}</style>' . "\n";
937 1008
938 1009 if ( ! empty( $link_options ) ) {
939 1010 echo $_mw_adminimize_admin_head;
940 1011 }
@@ -984,9 +1055,9 @@
984 1055 }
985 1056
986 1057 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
987 1058 $_mw_adminimize_admin_head .= '<style type="text/css">' .
988 - $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1059 + $nav_menu_options . ' {display: none !important;}</style>' . "\n";
989 1060
990 1061 if ( $nav_menu_options ) {
991 1062 echo $_mw_adminimize_admin_head;
992 1063 }
@@ -1036,9 +1107,9 @@
1036 1107 }
1037 1108
1038 1109 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1039 1110 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1040 - $widget_options . ' {display: none !important;}</style>' . "\n";
1111 + $widget_options . ' {display: none !important;}</style>' . "\n";
1041 1112
1042 1113 if ( $widget_options ) {
1043 1114 echo $_mw_adminimize_admin_head;
1044 1115 }
@@ -1062,8 +1133,9 @@
1062 1133 <?php
1063 1134 }
1064 1135
1065 1136 // include helping functions
1137 +require_once 'inc-setup/DebugListener.php';
1066 1138 require_once 'inc-setup/helping_hands.php';
1067 1139
1068 1140 // Include message class.
1069 1141 require_once 'inc-setup/messages.php';
@@ -1078,12 +1150,8 @@
1078 1150 require_once 'inc-setup/widget.php';
1079 1151 require_once 'inc-setup/footer.php';
1080 1152 require_once 'inc-setup/admin-footer.php';
1081 1153
1082 -// global settings
1083 -// @TODO Testing, not ready for productive
1084 -//require_once( 'inc-options/settings_notice.php' );
1085 -
1086 1154 // remove admin bar
1087 1155 require_once 'inc-setup/remove-admin-bar.php';
1088 1156
1089 1157 // admin bar helper, setup
@@ -1106,9 +1174,9 @@
1106 1174 *
1107 1175 * @param array $links
1108 1176 * @param string $file
1109 1177 *
1110 - * @return string $links
1178 + * @return array $links
1111 1179 */
1112 1180 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1113 1181
1114 1182 /* create link */
@@ -1115,10 +1183,9 @@
1115 1183 if ( FB_ADMINIMIZE_BASENAME === $file ) {
1116 1184 array_unshift(
1117 1185 $links,
1118 1186 sprintf(
1119 - '<a href="options-general.php?page=%s">%s</a>',
1120 - FB_ADMINIMIZE_BASENAME,
1187 + '<a href="options-general.php?page=adminimize-options">%s</a>',
1121 1188 esc_attr__( 'Settings' )
1122 1189 )
1123 1190 );
1124 1191 }
@@ -1154,11 +1221,13 @@
1154 1221 _mw_adminimize_textdomain();
1155 1222
1156 1223 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1157 1224
1225 + wp_enqueue_style( 'select2-style', plugins_url( 'css/select2' . $suffix . '.css', __FILE__ ), [], false );
1158 1226 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1159 1227 wp_enqueue_style( 'adminimize-style' );
1160 1228
1229 + wp_enqueue_script( 'select2-script', plugins_url( 'js/select2' . $suffix . '.js', __FILE__ ), array( 'jquery' ),'',false );
1161 1230 wp_register_script(
1162 1231 'adminimize-settings-script',
1163 1232 plugins_url( 'js/adminimize' . $suffix . '.js', __FILE__ ),
1164 1233 array( 'jquery' ),
@@ -1168,33 +1237,8 @@
1168 1237 wp_enqueue_script( 'adminimize-settings-script' );
1169 1238 }
1170 1239
1171 1240 /**
1172 - * Set theme for users
1173 - * Kill with version 1.7.18
1174 - * @ToDo Remove for the feature releases.
1175 - */
1176 -function _mw_adminimize_set_theme() {
1177 -
1178 - if ( ! current_user_can( 'edit_users' ) ) {
1179 - wp_die( esc_attr__( 'Cheatin&#8217; uh?' ) );
1180 - }
1181 -
1182 - $user_ids = (array) $_POST[ 'mw_adminimize_theme_items' ];
1183 - $admin_color = htmlspecialchars( stripslashes( $_POST[ '_mw_adminimize_set_theme' ] ) );
1184 -
1185 - if ( ! $user_ids ) {
1186 - return FALSE;
1187 - }
1188 -
1189 - foreach ( $user_ids as $user_id ) {
1190 - update_user_meta( $user_id, 'admin_color', $admin_color );
1191 - }
1192 -
1193 - return TRUE;
1194 -}
1195 -
1196 -/**
1197 1241 * Get setting value for each options key.
1198 1242 *
1199 1243 * @param string|bool $key
1200 1244 *
@@ -1199,17 +1243,17 @@
1199 1243 * @param string|bool $key
1200 1244 *
1201 1245 * @return string
1202 1246 */
1203 -function _mw_adminimize_get_option_value( $key = FALSE ) {
1247 +function _mw_adminimize_get_option_value( $key = false ) {
1204 1248
1205 - $adminimizeoptions = FALSE;
1249 + $adminimizeoptions = false;
1206 1250 if ( ! _mw_adminimize_exclude_settings_page() ) {
1207 1251 $adminimizeoptions = wp_cache_get( 'mw_adminimize' );
1208 1252 }
1209 1253
1210 - if ( FALSE === $adminimizeoptions ) {
1211 - // check for use on multisite
1254 + if ( false === $adminimizeoptions ) {
1255 + // check for use on multisite.
1212 1256 if ( _mw_adminimize_is_active_on_multisite() ) {
1213 1257 $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1214 1258 } else {
1215 1259 $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
@@ -1220,9 +1264,9 @@
1220 1264 if ( ! $key ) {
1221 1265 return $adminimizeoptions;
1222 1266 }
1223 1267
1224 - return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : NULL;
1268 + return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : null;
1225 1269 }
1226 1270
1227 1271 /**
1228 1272 * Update options.
@@ -1236,8 +1280,12 @@
1236 1280 if ( ! current_user_can( 'manage_options' ) ) {
1237 1281 return FALSE;
1238 1282 }
1239 1283
1284 + if ( _mw_adminimize_is_roles_options_import( $options ) ){
1285 + $options = _mw_adminimize_roles_complete_options( $options );
1286 + }
1287 +
1240 1288 // Remove slashes always.
1241 1289 foreach ( $options as $key => $value ) {
1242 1290 $options[ $key ] = stripslashes_deep( $value );
1243 1291 }
@@ -1440,9 +1488,9 @@
1440 1488
1441 1489 // global options
1442 1490 if ( isset( $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] ) ) {
1443 1491 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] =
1444 - $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1492 + $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1445 1493 } else {
1446 1494 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1447 1495 }
1448 1496
@@ -1649,8 +1697,21 @@
1649 1697 if ( isset( $GLOBALS[ 'submenu' ] ) ) {
1650 1698 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1651 1699 }
1652 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 +
1653 1714 // update
1654 1715 $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1655 1716
1656 1717 $myErrors = new _mw_adminimize_message_class();
@@ -1721,5 +1782,54 @@
1721 1782 } else {
1722 1783 add_option( 'mw_adminimize', $adminimizeoptions );
1723 1784 }
1724 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 + }
1725 1835 }