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 +227 -85 1.11.41.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.4
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-12-14
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 112 $screen_tmp = get_current_screen();
114 - }
115 113
116 - if ( isset( $screen_tmp->id ) && null !== $screen_tmp->id ) {
117 - $screen = $screen_tmp->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,15 +403,15 @@
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 415 add_filter( 'wp_default_editor', '_mw_admininimize_return_tinmyce' );
382 416 /**
383 417 * Return string tinymce.
@@ -391,9 +425,9 @@
391 425 }
392 426
393 427 // Remove media buttons
394 428 if ( _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_page_all )
395 - || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
429 + || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
396 430 ) {
397 431 remove_action( 'media_buttons', 'media_buttons' );
398 432 }
399 433 }
@@ -408,9 +442,9 @@
408 442 add_action( 'admin_head', '_mw_adminimize_set_metabox_page_option', 1 );
409 443 }
410 444 // set custom post type options
411 445 if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages, TRUE )
412 - && in_array( $current_post_type, $def_custom_types, TRUE )
446 + && in_array( $current_post_type, $def_custom_types, TRUE )
413 447 ) {
414 448 add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
415 449 }
416 450 // set link option
@@ -487,9 +521,9 @@
487 521 $redirect = FALSE;
488 522 foreach ( $user_roles as $role ) {
489 523 if ( _mw_adminimize_current_user_has_role( $role ) ) {
490 524 if ( _mw_adminimize_recursive_in_array( 'index.php', $disabled_menu_[ $role ] )
491 - || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
525 + || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
492 526 ) {
493 527 $redirect = TRUE;
494 528 }
495 529 }
@@ -560,9 +594,9 @@
560 594 function _mw_adminimize_set_menu_option() {
561 595
562 596 // exclude super admin
563 597 if ( _mw_adminimize_exclude_super_admin() ) {
564 - return NULL;
598 + return;
565 599 }
566 600
567 601 // Leave the settings screen from Adminimize to see all areas on settings.
568 602 if ( _mw_adminimize_exclude_settings_page() ) {
@@ -569,15 +603,28 @@
569 603 return;
570 604 }
571 605
572 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' );
573 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 + }
574 621 if ( ! isset( $menu ) || empty( $menu ) ) {
575 622 return;
576 623 }
577 624
578 - _mw_adminimize_debug( $menu, 'Adminimize, WordPress Menu:' );
579 - _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:' );
580 627
581 628 $disabled_menu_ = array();
582 629 $disabled_submenu_ = array();
583 630 $user = wp_get_current_user();
@@ -598,9 +645,9 @@
598 645
599 646 // Set admin-menu.
600 647 foreach ( $user_roles as $role ) {
601 648 if ( in_array( $role, $user->roles, TRUE )
602 - && _mw_adminimize_current_user_has_role( $role )
649 + && _mw_adminimize_current_user_has_role( $role )
603 650 ) {
604 651 // Create array about all items with all affected roles.
605 652 foreach ( (array) $disabled_menu_[ $role ] as $menu_item ) {
606 653 $mw_adminimize_menu[] = $menu_item;
@@ -621,11 +668,11 @@
621 668 $mw_adminimize_menu = array_unique( $mw_adminimize_menu );
622 669 $mw_adminimize_submenu = array_unique( $mw_adminimize_submenu );
623 670 }
624 671 _mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Menu Slugs to hide after Filter.' );
625 - _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.' );
626 673
627 - foreach ( $menu as $key => $item ) {
674 + foreach ( $wp_menu as $key => $item ) {
628 675
629 676 _mw_adminimize_debug( $item, 'Adminimize, Each Menu Item Array to check for hiding.' );
630 677
631 678 // Menu
@@ -639,10 +686,16 @@
639 686 _mw_adminimize_check_page_access( $menu_slug );
640 687 }
641 688
642 689 // Sub Menu Settings.
643 - if ( isset( $submenu ) && ! empty( $submenu[ $menu_slug ] ) ) {
644 - 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 +
645 698 // Check, if is Sub Menu item in the user role settings?
646 699 if (
647 700 isset( $mw_adminimize_submenu )
648 701 && _mw_adminimize_in_arrays(
@@ -712,8 +765,11 @@
712 765 }
713 766 $_mw_adminimize_admin_head .= '<!-- Set Adminimize global options -->' . "\n";
714 767 $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display:none !important;}</style>' . "\n";
715 768
769 + // List options if the debug option is active.
770 + _mw_adminimize_debug($global_options, 'Adminimize: List active global options:');
771 +
716 772 if ( '' !== $global_options ) {
717 773 echo $_mw_adminimize_admin_head;
718 774 }
719 775 }
@@ -734,9 +790,10 @@
734 790 }
735 791
736 792 $user_roles = _mw_adminimize_get_all_user_roles();
737 793 $_mw_adminimize_admin_head = '';
738 - $metaboxes = '';
794 + // It's better to declare $metaboxes as an array for better manipulation later.
795 + $metaboxes = array();
739 796
740 797 foreach ( $user_roles as $role ) {
741 798 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
742 799 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
@@ -741,28 +798,42 @@
741 798 $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
742 799 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
743 800 );
744 801
745 - if ( ! isset( $disabled_metaboxes_post_[ $role ][ '0' ] ) ) {
746 - $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;
747 809 }
748 810
749 - // New since version 1.7.8.
750 - $user = wp_get_current_user();
751 - 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 ) ) {
752 819 if ( _mw_adminimize_current_user_has_role( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
753 - && is_array(
754 - $disabled_metaboxes_post_[ $role ]
755 - )
820 + && is_array(
821 + $disabled_metaboxes_post_[ $role ]
822 + )
756 823 ) {
757 - $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 ] );
758 828 }
759 829 }
760 830 }
761 831
762 832 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox post options -->' . "\n";
833 + // And below we implode $metaboxes because it's an array now.
763 834 $_mw_adminimize_admin_head .= '<style type="text/css">' .
764 - $metaboxes . ' {display:none !important;}</style>' . "\n";
835 + implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
765 836
766 837 if ( ! empty( $metaboxes ) ) {
767 838 echo $_mw_adminimize_admin_head;
768 839 }
@@ -799,10 +870,10 @@
799 870 // New since version 1.7.8.
800 871 $user = wp_get_current_user();
801 872 if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
802 873 if ( _mw_adminimize_current_user_has_role( $role )
803 - && isset( $disabled_metaboxes_page_[ $role ] )
804 - && is_array( $disabled_metaboxes_page_[ $role ] )
874 + && isset( $disabled_metaboxes_page_[ $role ] )
875 + && is_array( $disabled_metaboxes_page_[ $role ] )
805 876 ) {
806 877 $metaboxes = implode( ',', $disabled_metaboxes_page_[ $role ] );
807 878 }
808 879 }
@@ -809,9 +880,9 @@
809 880 }
810 881
811 882 $_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox page options -->' . "\n";
812 883 $_mw_adminimize_admin_head .= '<style type="text/css">' .
813 - $metaboxes . ' {display:none !important;}</style>' . "\n";
884 + $metaboxes . ' {display:none !important;}</style>' . "\n";
814 885
815 886 if ( ! empty( $metaboxes ) ) {
816 887 echo $_mw_adminimize_admin_head;
817 888 }
@@ -854,9 +925,9 @@
854 925 }
855 926
856 927 $user_roles = _mw_adminimize_get_all_user_roles();
857 928 $_mw_adminimize_admin_head = '';
858 - $metaboxes = '';
929 + $metaboxes = array();
859 930
860 931 foreach ( $user_roles as $role ) {
861 932 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
862 933 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
@@ -861,19 +932,21 @@
861 932 $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
862 933 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
863 934 );
864 935
865 - if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] ) ) {
866 - $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;
867 940 }
868 941
869 - $user = wp_get_current_user();
870 - 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 ) ) {
871 944 if ( _mw_adminimize_current_user_has_role( $role )
872 - && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
873 - && 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 ] )
874 947 ) {
875 - $metaboxes = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
948 + $metaboxes[] = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
876 949 }
877 950 }
878 951 }
879 952
@@ -878,9 +951,9 @@
878 951 }
879 952
880 953 $_mw_adminimize_admin_head .= '<!-- Set Adminimize post options -->' . "\n";
881 954 $_mw_adminimize_admin_head .= '<style type="text/css">' .
882 - $metaboxes . ' {display:none !important;}</style>' . "\n";
955 + implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
883 956
884 957 if ( ! empty( $metaboxes ) ) {
885 958 echo $_mw_adminimize_admin_head;
886 959 }
@@ -930,9 +1003,9 @@
930 1003 }
931 1004
932 1005 $_mw_adminimize_admin_head .= '<!-- Set Adminimize links options -->' . "\n";
933 1006 $_mw_adminimize_admin_head .= '<style type="text/css">' .
934 - $link_options . ' {display:none !important;}</style>' . "\n";
1007 + $link_options . ' {display:none !important;}</style>' . "\n";
935 1008
936 1009 if ( ! empty( $link_options ) ) {
937 1010 echo $_mw_adminimize_admin_head;
938 1011 }
@@ -982,9 +1055,9 @@
982 1055 }
983 1056
984 1057 $_mw_adminimize_admin_head .= '<!-- Set Adminimize WP Nav Menu options -->' . "\n";
985 1058 $_mw_adminimize_admin_head .= '<style type="text/css">' .
986 - $nav_menu_options . ' {display: none !important;}</style>' . "\n";
1059 + $nav_menu_options . ' {display: none !important;}</style>' . "\n";
987 1060
988 1061 if ( $nav_menu_options ) {
989 1062 echo $_mw_adminimize_admin_head;
990 1063 }
@@ -1034,9 +1107,9 @@
1034 1107 }
1035 1108
1036 1109 $_mw_adminimize_admin_head .= '<!-- Set Adminimize Widget options -->' . "\n";
1037 1110 $_mw_adminimize_admin_head .= '<style type="text/css">' .
1038 - $widget_options . ' {display: none !important;}</style>' . "\n";
1111 + $widget_options . ' {display: none !important;}</style>' . "\n";
1039 1112
1040 1113 if ( $widget_options ) {
1041 1114 echo $_mw_adminimize_admin_head;
1042 1115 }
@@ -1060,8 +1133,9 @@
1060 1133 <?php
1061 1134 }
1062 1135
1063 1136 // include helping functions
1137 +require_once 'inc-setup/DebugListener.php';
1064 1138 require_once 'inc-setup/helping_hands.php';
1065 1139
1066 1140 // Include message class.
1067 1141 require_once 'inc-setup/messages.php';
@@ -1100,9 +1174,9 @@
1100 1174 *
1101 1175 * @param array $links
1102 1176 * @param string $file
1103 1177 *
1104 - * @return string $links
1178 + * @return array $links
1105 1179 */
1106 1180 function _mw_adminimize_filter_plugin_meta( $links, $file ) {
1107 1181
1108 1182 /* create link */
@@ -1147,11 +1221,13 @@
1147 1221 _mw_adminimize_textdomain();
1148 1222
1149 1223 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1150 1224
1225 + wp_enqueue_style( 'select2-style', plugins_url( 'css/select2' . $suffix . '.css', __FILE__ ), [], false );
1151 1226 wp_register_style( 'adminimize-style', plugins_url( 'css/style' . $suffix . '.css', __FILE__ ) );
1152 1227 wp_enqueue_style( 'adminimize-style' );
1153 1228
1229 + wp_enqueue_script( 'select2-script', plugins_url( 'js/select2' . $suffix . '.js', __FILE__ ), array( 'jquery' ),'',false );
1154 1230 wp_register_script(
1155 1231 'adminimize-settings-script',
1156 1232 plugins_url( 'js/adminimize' . $suffix . '.js', __FILE__ ),
1157 1233 array( 'jquery' ),
@@ -1167,17 +1243,17 @@
1167 1243 * @param string|bool $key
1168 1244 *
1169 1245 * @return string
1170 1246 */
1171 -function _mw_adminimize_get_option_value( $key = FALSE ) {
1247 +function _mw_adminimize_get_option_value( $key = false ) {
1172 1248
1173 - $adminimizeoptions = FALSE;
1249 + $adminimizeoptions = false;
1174 1250 if ( ! _mw_adminimize_exclude_settings_page() ) {
1175 1251 $adminimizeoptions = wp_cache_get( 'mw_adminimize' );
1176 1252 }
1177 1253
1178 - if ( FALSE === $adminimizeoptions ) {
1179 - // check for use on multisite
1254 + if ( false === $adminimizeoptions ) {
1255 + // check for use on multisite.
1180 1256 if ( _mw_adminimize_is_active_on_multisite() ) {
1181 1257 $adminimizeoptions = (array) get_site_option( 'mw_adminimize', array() );
1182 1258 } else {
1183 1259 $adminimizeoptions = (array) get_option( 'mw_adminimize', array() );
@@ -1188,9 +1264,9 @@
1188 1264 if ( ! $key ) {
1189 1265 return $adminimizeoptions;
1190 1266 }
1191 1267
1192 - return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : NULL;
1268 + return array_key_exists( $key, $adminimizeoptions ) ? $adminimizeoptions[ $key ] : null;
1193 1269 }
1194 1270
1195 1271 /**
1196 1272 * Update options.
@@ -1204,8 +1280,12 @@
1204 1280 if ( ! current_user_can( 'manage_options' ) ) {
1205 1281 return FALSE;
1206 1282 }
1207 1283
1284 + if ( _mw_adminimize_is_roles_options_import( $options ) ){
1285 + $options = _mw_adminimize_roles_complete_options( $options );
1286 + }
1287 +
1208 1288 // Remove slashes always.
1209 1289 foreach ( $options as $key => $value ) {
1210 1290 $options[ $key ] = stripslashes_deep( $value );
1211 1291 }
@@ -1408,9 +1488,9 @@
1408 1488
1409 1489 // global options
1410 1490 if ( isset( $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] ) ) {
1411 1491 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] =
1412 - $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1492 + $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
1413 1493 } else {
1414 1494 $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
1415 1495 }
1416 1496
@@ -1617,8 +1697,21 @@
1617 1697 if ( isset( $GLOBALS[ 'submenu' ] ) ) {
1618 1698 $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $GLOBALS[ 'submenu' ];
1619 1699 }
1620 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 +
1621 1714 // update
1622 1715 $update_status = _mw_adminimize_update_option( $adminimizeoptions );
1623 1716
1624 1717 $myErrors = new _mw_adminimize_message_class();
@@ -1689,5 +1782,54 @@
1689 1782 } else {
1690 1783 add_option( 'mw_adminimize', $adminimizeoptions );
1691 1784 }
1692 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 + }
1693 1835 }