-
Notifications
You must be signed in to change notification settings - Fork 30
/
adminimize.php
executable file
·1845 lines (1566 loc) · 56.9 KB
/
adminimize.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Plugin Name: Adminimize
* Plugin URI: https://wordpress.org/plugins/adminimize/
* Text Domain: adminimize
* Domain Path: /languages
* 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.
* Author: WP Media
* Author URI: https://wp-media.me
* Version: 1.11.11
* License: GPLv2+
*
* Php Version 5.6
*
* @package WordPress
* @author WP Media <[email protected]>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version 2024-05-03
*/
/**
* The stylesheet and the initial idea is from Eric A. Meyer http://meyerweb.com/
* I have written a plugin with many options on the basis idea
* of differently user-right and a user-friendly range in admin-area via reduce areas.
* :( grmpf i have so much wishes and hints form users, there use the plugin and
* it is not easy to development this on my free time.
* Also I hate the source, old and hard to maintain, no OOP.
*/
if ( ! function_exists( 'add_action' ) ) {
echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
exit;
}
// plugin definitions
define( 'FB_ADMINIMIZE_BASENAME', plugin_basename( __FILE__ ) );
define( 'FB_ADMINIMIZE_BASEFOLDER', plugin_basename( __DIR__ ) );
/**
* Return data from the plugin.
*
* @param string $value
*
* @return mixed
*/
function _mw_adminimize_get_plugin_data( $value = 'Version' ) {
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
$plugin_data = get_plugin_data( __FILE__ );
return $plugin_data[ $value ];
}
/**
* Load language files.
*/
function _mw_adminimize_textdomain() {
load_plugin_textdomain(
_mw_adminimize_get_plugin_data( 'TextDomain' ),
FALSE,
dirname( FB_ADMINIMIZE_BASENAME ) . _mw_adminimize_get_plugin_data( 'DomainPath' )
);
}
/**
* Exclude the Super Admin of Multisite.
*
* @return bool
*/
function _mw_adminimize_exclude_super_admin() {
if ( ! function_exists( 'is_super_admin' ) ) {
return FALSE;
}
if ( ! is_super_admin() ) {
return FALSE;
}
if ( 1 === (int) _mw_adminimize_get_option_value( '_mw_adminimize_exclude_super_admin' ) ) {
return TRUE;
}
return FALSE;
}
/**
* Get the status, if is on the settings page.
*
* @return bool
*/
function _mw_adminimize_exclude_settings_page() {
if ( ! is_admin() ) {
return false;
}
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return false;
}
$page = '';
if ( isset( $_GET['page'] ) ) {
$page = esc_attr( $_GET['page'] );
}
if ( function_exists( 'get_current_screen' ) ) {
$screen_tmp = get_current_screen();
if ( isset( $screen_tmp->id ) && null !== $screen_tmp->id ) {
$page = $screen_tmp->id;
}
}
// Don't filter on settings page
return FALSE !== strpos( $page, 'adminimize' );
}
/**
* Get status, if the plugin active network wide.
*
* @return bool
*/
function _mw_adminimize_is_active_on_multisite() {
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
/**
* Allow different adminimize options per site on multisite.
*
* @since 1.11.6
*
* @param bool
*/
$force_single_site_usage = apply_filters( 'adminimize_mu_force_options_per_site', false );
if ( is_multisite()
&& is_plugin_active_for_network( FB_ADMINIMIZE_BASENAME )
&& ! $force_single_site_usage ) {
return TRUE;
}
return FALSE;
}
/**
* Returns an array with all user roles(names) in it.
* Inclusive self defined roles (for example with the 'Role Manager' plugin).
*
* @uses $wp_roles
* @return array $user_roles
*/
function _mw_adminimize_get_all_user_roles() {
/** @var $wp_roles WP_Roles */
global $wp_roles;
$user_roles = array();
if ( null !== $wp_roles->roles && is_array( $wp_roles->roles ) ) {
foreach ( $wp_roles->roles as $role => $data ) {
$user_roles[] = $role;
// The $data var contains caps, maybe for later use.
}
}
// Exclude the new bbPress roles.
if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
$user_roles = array_diff(
$user_roles,
array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
);
}
/**
* Use this filter to add or remove a role in Adminimize options.
*
* @since 1.11.6
*
* @param array
*/
return apply_filters( 'adminimize_user_roles_filter', $user_roles );
}
/**
* _mw_adminimize_get_all_user_roles_names() - Returns an array with all user roles_names in it.
* Inclusive self defined roles (for example with the 'Role Manager' plugin).
*
* @uses $wp_roles
* @return array $user_roles_names
*/
function _mw_adminimize_get_all_user_roles_names() {
/** @var $wp_roles WP_Roles */
global $wp_roles;
$user_roles_names = array();
foreach ( $wp_roles->role_names as $role_name => $data ) {
$data = translate_user_role( $data );
$user_roles_names[] = $data;
}
// exclude the new bbPress roles
if ( ! _mw_adminimize_get_option_value( 'mw_adminimize_support_bbpress' ) ) {
$user_roles_names = array_diff(
$user_roles_names,
array(
esc_attr__( 'Keymaster', 'bbpress' ),
esc_attr__( 'Moderator', 'bbpress' ),
esc_attr__( 'Participant', 'bbpress' ),
esc_attr__( 'Spectator', 'bbpress' ),
esc_attr__( 'Blocked', 'bbpress' ),
)
);
}
/**
* Use this filter to add or remove a role-name in Adminimize options.
*
* @since 1.11.6
*
* @param array
*/
return apply_filters( 'adminimize_user_roles_names_filter', $user_roles_names );
}
/**
* Get post type.
*
* @return null|string String of the post type.
*/
function _mw_adminimize_get_current_post_type() {
global $post, $typenow, $current_screen;
// We have a post so we can just get the post type from that.
if ( $post && $post->post_type ) {
return $post->post_type;
}
// Check the global $typenow - set in admin.php
if ( $typenow ) {
return $typenow;
}
// Check the global $current_screen object - set in screen.php
if ( $current_screen && $current_screen->post_type ) {
return $current_screen->post_type;
}
// lastly check the post_type querystring
if ( isset( $_REQUEST['post_type'] ) ) {
return sanitize_key( $_REQUEST[ 'post_type' ] );
}
// we do not know the post type!
return NULL;
}
/**
* Check user-option and add new style.
*/
function _mw_adminimize_admin_init() {
global $pagenow, $menu, $submenu;
$post_id = 0;
if ( isset( $_GET[ 'post' ] ) && ! is_array( $_GET[ 'post' ] ) ) {
$post_id = (int) esc_attr( $_GET[ 'post' ] );
} elseif ( isset( $_POST[ 'post_ID' ] ) ) {
$post_id = (int) esc_attr( $_POST[ 'post_ID' ] );
}
// Fallback to get always the post type.
if ( isset( $_GET[ 'post_type' ] ) && ! is_array( $_GET[ 'post_type' ] ) ) {
$current_post_type = esc_attr( $_GET['post_type'] );
}
if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
$current_post_type = get_post_type( get_queried_object_id() );
}
if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
$current_post_type = get_post_type( $post_id );
}
if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
$current_post_type = _mw_adminimize_get_current_post_type();
}
if ( ! $current_post_type ) { // set hard to post
$current_post_type = 'post';
}
// Debug helper
if ( class_exists( 'DebugListener' ) ) {
$listener = new DebugListener();
add_action( 'adminimize.log', [$listener, 'listen'], 10, 2 );
add_action( 'wp_footer', array( $listener, 'dump' ), PHP_INT_MAX );
}
// Get all user roles.
$user_roles = _mw_adminimize_get_all_user_roles();
// Get settings.
$adminimizeoptions = _mw_adminimize_get_option_value();
// pages for post type Post
$def_post_pages = array( 'edit.php', 'post.php', 'post-new.php' );
$def_post_types = array( 'post' );
$disabled_metaboxes_post_all = array();
// pages for post type Page
$def_page_pages = array_merge( $def_post_pages, array( 'page-new.php', 'page.php' ) );
$def_page_types = array( 'page' );
$disabled_metaboxes_page_all = array();
// pages for custom post types
$def_custom_pages = $def_post_pages;
$args = array( 'public' => TRUE, '_builtin' => FALSE );
$def_custom_types = get_post_types( $args );
// pages for link pages
$link_pages = array( 'link.php', 'link-manager.php', 'link-add.php', 'edit-link-categories.php' );
// pages for nav menu
$nav_menu_pages = array( 'nav-menus.php' );
// widget pages
$widget_pages = array( 'widgets.php' );
foreach ( $user_roles as $role ) {
$disabled_admin_bar_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_admin_bar_' . $role . '_items'
);
$disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_global_option_' . $role . '_items'
);
$disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
);
$disabled_metaboxes_page_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_metaboxes_page_' . $role . '_items'
);
foreach ( $def_custom_types as $post_type ) {
$disabled_metaboxes_[ $post_type . '_' . $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items'
);
}
$disabled_link_option_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_link_option_' . $role . '_items'
);
$disabled_nav_menu_option_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_nav_menu_option_' . $role . '_items'
);
$disabled_widget_option_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_widget_option_' . $role . '_items'
);
$disabled_metaboxes_post_all[] = $disabled_metaboxes_post_[ $role ];
$disabled_metaboxes_page_all[] = $disabled_metaboxes_page_[ $role ];
}
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
// Backend options
// exclude super admin
if ( ! _mw_adminimize_exclude_super_admin() && ! _mw_adminimize_exclude_settings_page() ) {
$_mw_adminimize_header = (int) _mw_adminimize_get_option_value( '_mw_adminimize_header' );
if ( 1 === $_mw_adminimize_header ) {
wp_enqueue_script(
'_mw_adminimize_remove_header',
WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_header' . $suffix . '.js',
[ 'jquery' ]
);
}
// Post-page options.
if ( in_array( $pagenow, $def_post_pages, TRUE ) ) {
$_mw_adminimize_tb_window = (int) _mw_adminimize_get_option_value( '_mw_adminimize_tb_window' );
switch ( $_mw_adminimize_tb_window ) {
case 1:
wp_deregister_script( 'media-upload' );
wp_enqueue_script(
'media-upload',
WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/tb_window' . $suffix . '.js',
array( 'thickbox' )
);
break;
}
$_mw_adminimize_timestamp = (int) _mw_adminimize_get_option_value( '_mw_adminimize_timestamp' );
switch ( $_mw_adminimize_timestamp ) {
case 1:
wp_enqueue_script(
'_mw_adminimize_timestamp',
WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/timestamp' . $suffix . '.js',
array( 'jquery' )
);
break;
}
// Category options.
$_mw_adminimize_cat_full = (int) _mw_adminimize_get_option_value( '_mw_adminimize_cat_full' );
switch ( $_mw_adminimize_cat_full ) {
case 1:
wp_enqueue_style(
'adminimize-full-category',
WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/css/mw_cat_full' . $suffix . '.css'
);
break;
}
// Set default editor tinymce
if ( _mw_adminimize_recursive_in_array(
'#editor-toolbar #edButtonHTML, #quicktags, #content-html',
$disabled_metaboxes_page_all
)
|| _mw_adminimize_recursive_in_array(
'#editor-toolbar #edButtonHTML, #quicktags, #content-html',
$disabled_metaboxes_post_all
)
) {
add_filter( 'wp_default_editor', '_mw_admininimize_return_tinmyce' );
/**
* Return string tinymce.
* Necessary for php 5.2 usage :(; not possible to use an anonymous function.
*
* @return string
*/
function _mw_admininimize_return_tinmyce() {
return 'tinymce';
}
}
// Remove media buttons
if ( _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_page_all )
|| _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
) {
remove_action( 'media_buttons', 'media_buttons' );
}
}
}
// set meta-box post option
if ( in_array( $pagenow, $def_post_pages, TRUE ) && in_array( $current_post_type, $def_post_types, TRUE ) ) {
add_action( 'admin_head', '_mw_adminimize_set_metabox_post_option', 1 );
}
// set meta-box page option
if ( in_array( $pagenow, $def_page_pages, TRUE ) && in_array( $current_post_type, $def_page_types, TRUE ) ) {
add_action( 'admin_head', '_mw_adminimize_set_metabox_page_option', 1 );
}
// set custom post type options
if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages, TRUE )
&& in_array( $current_post_type, $def_custom_types, TRUE )
) {
add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
}
// set link option
if ( in_array( $pagenow, $link_pages, TRUE ) ) {
add_action( 'admin_head', '_mw_adminimize_set_link_option', 1 );
}
// set wp nav menu options
if ( in_array( $pagenow, $nav_menu_pages, TRUE ) ) {
add_action( 'admin_head', '_mw_adminimize_set_nav_menu_option', 1 );
}
// set widget options
if ( in_array( $pagenow, $widget_pages, TRUE ) ) {
add_action( 'admin_head', '_mw_adminimize_set_widget_option', 1 );
}
}
// Change menu via settings of Adminimize.
//add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'admin_menu', '_mw_adminimize_set_menu_option', 99999 );
// global_options
add_action( 'admin_head', '_mw_adminimize_set_global_option', 1 );
// on admin init
if ( is_admin() ) {
add_action( 'admin_init', '_mw_adminimize_admin_init' );
add_action( 'admin_menu', '_mw_adminimize_add_settings_page' );
add_action( 'admin_menu', '_mw_adminimize_remove_dashboard' );
}
register_activation_hook( __FILE__, '_mw_adminimize_install' );
register_uninstall_hook( __FILE__, '_mw_adminimize_uninstall' );
/**
* Remove the dashboard
*/
function _mw_adminimize_remove_dashboard() {
// exclude super admin
if ( _mw_adminimize_exclude_super_admin() ) {
return;
}
// Leave the settings screen from Adminimize to see all areas on settings.
if ( _mw_adminimize_exclude_settings_page() ) {
return;
}
global $menu, $user_ID;
$disabled_menu_ = array();
$disabled_submenu_ = array();
$user_roles = _mw_adminimize_get_all_user_roles();
foreach ( $user_roles as $role ) {
$disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
'mw_adminimize_disabled_menu_' . $role . '_items'
);
$disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
'mw_adminimize_disabled_submenu_' . $role . '_items'
);
}
$disabled_menu_all = array();
$disabled_submenu_all = array();
foreach ( $user_roles as $role ) {
$disabled_menu_all[] = $disabled_menu_[ $role ];
$disabled_submenu_all[] = $disabled_submenu_[ $role ];
}
// remove dashboard
if ( $disabled_menu_all !== '' || $disabled_submenu_all !== '' ) {
$redirect = FALSE;
foreach ( $user_roles as $role ) {
if ( _mw_adminimize_current_user_has_role( $role ) ) {
if ( _mw_adminimize_recursive_in_array( 'index.php', $disabled_menu_[ $role ] )
|| _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
) {
$redirect = TRUE;
}
}
}
// Redirect option, if Dashboard is inactive
if ( $redirect ) {
$_mw_adminimize_db_redirect = (int) _mw_adminimize_get_option_value(
'_mw_adminimize_db_redirect'
);
$_mw_adminimize_db_redirect_admin_url = get_option( 'siteurl' ) . '/wp-admin/';
switch ( $_mw_adminimize_db_redirect ) {
case 0:
$_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'profile.php';
break;
case 1:
$_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit.php';
break;
case 2:
$_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit.php?post_type=page';
break;
case 3:
$_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'post-new.php';
break;
case 4:
$_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'page-new.php';
break;
case 5:
$_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit-comments.php';
break;
case 6:
$_mw_adminimize_db_redirect = _mw_adminimize_get_option_value( '_mw_adminimize_db_redirect_txt' );
break;
}
$the_user = new WP_User( $user_ID );
reset( $menu );
$page = key( $menu );
$dashboard_core_string = esc_attr__( 'Dashboard' );
$dashboard = array( $menu[ $page ][ 0 ], $menu[ $page ][ 1 ] );
while (
! in_array( $dashboard_core_string, $dashboard, TRUE ) && next( $menu )
) {
$page = key( $menu );
}
if ( in_array( $dashboard_core_string, $dashboard, TRUE ) ) {
unset( $menu[ $page ] );
}
reset( $menu );
$page = key( $menu );
while ( ! $the_user->has_cap( $menu[ $page ][ 1 ] ) && next( $menu ) ) {
$page = key( $menu );
}
if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER[ 'REQUEST_URI' ] ) ) {
wp_safe_redirect( $_mw_adminimize_db_redirect );
}
}
}
}
/**
* Set menu for settings
*/
function _mw_adminimize_set_menu_option() {
// exclude super admin
if ( _mw_adminimize_exclude_super_admin() ) {
return;
}
// Leave the settings screen from Adminimize to see all areas on settings.
if ( _mw_adminimize_exclude_settings_page() ) {
return;
}
global $menu, $submenu;
$wp_menu = (array) _mw_adminimize_get_option_value( 'mw_adminimize_default_menu' );
$wp_submenu = (array) _mw_adminimize_get_option_value( 'mw_adminimize_default_submenu' );
// Object to array
if ( is_object( $wp_submenu ) ) {
$wp_submenu = get_object_vars( $wp_submenu );
}
if ( ! isset( $wp_menu ) || empty( $wp_menu ) ) {
$wp_menu = $menu;
}
if ( ! isset( $wp_submenu ) || empty( $wp_submenu ) ) {
$wp_submenu = $submenu;
}
if ( ! isset( $menu ) || empty( $menu ) ) {
return;
}
_mw_adminimize_debug( $wp_menu, 'Adminimize, WordPress Menu:' );
_mw_adminimize_debug( $wp_submenu, 'Adminimize, WordPress Sub-Menu:' );
$disabled_menu_ = array();
$disabled_submenu_ = array();
$user = wp_get_current_user();
$user_roles = $user->roles;
_mw_adminimize_debug( $user, 'Adminimize, Current User:' );
foreach ( $user_roles as $role ) {
$disabled_menu_[ $role ] = (array) _mw_adminimize_get_option_value(
'mw_adminimize_disabled_menu_' . $role . '_items'
);
$disabled_submenu_[ $role ] = (array) _mw_adminimize_get_option_value(
'mw_adminimize_disabled_submenu_' . $role . '_items'
);
}
$mw_adminimize_menu = array();
$mw_adminimize_submenu = array();
// Set admin-menu.
foreach ( $user_roles as $role ) {
if ( in_array( $role, $user->roles, TRUE )
&& _mw_adminimize_current_user_has_role( $role )
) {
// Create array about all items with all affected roles.
foreach ( (array) $disabled_menu_[ $role ] as $menu_item ) {
$mw_adminimize_menu[] = $menu_item;
}
foreach ( (array) $disabled_submenu_[ $role ] as $submenu_item ) {
$mw_adminimize_submenu[] = $submenu_item;
}
}
}
// Support Multiple Roles for users.
// Leave only the items, there are active on each roles of the users.
if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
$mw_adminimize_menu = _mw_adminimize_get_intersection( $disabled_menu_ );
$mw_adminimize_submenu = _mw_adminimize_get_intersection( $disabled_submenu_ );
} else {
// Alternative filter the array to remove duplicates, much faster.
$mw_adminimize_menu = array_unique( $mw_adminimize_menu );
$mw_adminimize_submenu = array_unique( $mw_adminimize_submenu );
}
_mw_adminimize_debug( $mw_adminimize_menu, 'Adminimize, Menu Slugs to hide after Filter.' );
_mw_adminimize_debug( $mw_adminimize_submenu, 'Adminimize, Sub-Menu Slugs to hide after Filter.' );
foreach ( $wp_menu as $key => $item ) {
_mw_adminimize_debug( $item, 'Adminimize, Each Menu Item Array to check for hiding.' );
// Menu
if ( isset( $item[ 2 ] ) ) {
$menu_slug = $item[ 2 ];
// Check, if the Menu item in the current user role settings?
if ( in_array( $menu_slug, $mw_adminimize_menu, false )
) {
remove_menu_page( $menu_slug );
// Prevent access to the page with the slug, there was inactive.
_mw_adminimize_check_page_access( $menu_slug );
}
// Sub Menu Settings.
if ( isset( $wp_submenu ) && ! empty( $wp_submenu[ $menu_slug ] ) ) {
foreach ( (array) $wp_submenu[ $menu_slug ] as $subindex => $subitem ) {
// @see https://github.com/bueltge/adminimize/issues/149
if ( is_object( $subitem ) ) {
$subitem = json_decode( json_encode( $subitem ), true );
}
// Check, if is Sub Menu item in the user role settings?
if (
isset( $mw_adminimize_submenu )
&& _mw_adminimize_in_arrays(
array( $subitem[ 2 ], $menu_slug . '__' . $subindex ),
$mw_adminimize_submenu
)
) {
remove_submenu_page( $menu_slug, $subitem[ 2 ] );
// Prevent access to the page with the slug, there was inactive.
_mw_adminimize_check_page_access( $subitem[ 2 ] );
}
}
}
}
}
}
/**
* Set global options in backend in all areas.
*/
function _mw_adminimize_set_global_option() {
// exclude super admin
if ( _mw_adminimize_exclude_super_admin() ) {
return NULL;
}
// Leave the settings screen from Adminimize to see all areas on settings.
if ( _mw_adminimize_exclude_settings_page() ) {
return;
}
$user_roles = _mw_adminimize_get_all_user_roles();
$_mw_adminimize_admin_head = '';
$disabled_global_option = array();
$disabled_global_option_ = array();
$user = wp_get_current_user();
// Get settings for each role.
foreach ( $user_roles as $role ) {
$disabled_global_option_[ $role ] = (array) _mw_adminimize_get_option_value(
'mw_adminimize_disabled_global_option_' . $role . '_items'
);
}
// Write global options in an var.
foreach ( $user_roles as $role ) {
if ( in_array( $role, $user->roles, TRUE ) && _mw_adminimize_current_user_has_role( $role ) ) {
// Create array about all items with all affected roles, important for multiple roles.
foreach ( (array) $disabled_global_option_[ $role ] as $global_item ) {
$disabled_global_option[] = $global_item;
}
}
}
// Support Multiple Roles for users.
if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
$disabled_global_option = _mw_adminimize_get_duplicate( $disabled_global_option );
}
$global_options = implode( ', ', $disabled_global_option );
if ( 0 === strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
global $_wp_admin_css_colors;
$_wp_admin_css_colors = 0;
}
$_mw_adminimize_admin_head .= '<!-- Set Adminimize global options -->' . "\n";
$_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display:none !important;}</style>' . "\n";
// List options if the debug option is active.
_mw_adminimize_debug($global_options, 'Adminimize: List active global options:');
if ( '' !== $global_options ) {
echo $_mw_adminimize_admin_head;
}
}
/**
* Set metabox options from database an area post.
*/
function _mw_adminimize_set_metabox_post_option() {
// exclude super admin
if ( _mw_adminimize_exclude_super_admin() ) {
return;
}
// Leave the settings screen from Adminimize to see all areas on settings.
if ( _mw_adminimize_exclude_settings_page() ) {
return;
}
$user_roles = _mw_adminimize_get_all_user_roles();
$_mw_adminimize_admin_head = '';
// It's better to declare $metaboxes as an array for better manipulation later.
$metaboxes = array();
foreach ( $user_roles as $role ) {
$disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
);
if ( ! isset( $disabled_metaboxes_post_[ $role ]['0'] ) ) {
$disabled_metaboxes_post_[ $role ]['0'] = '';
/**
* @todo Think why keep going if $role does not even have boxes to hide? We may as well jump to the next $role.
*/
continue;
}
/**
* @todo Think why call a function as we can use a global variable already declared by WordPress.
* @var WP_User $user Instance of WP_User.
* @since 1.7.8
* @version 1.11.4
*/
$user = $GLOBALS['current_user'];
if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
if ( _mw_adminimize_current_user_has_role( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
&& is_array(
$disabled_metaboxes_post_[ $role ]
)
) {
// The previous way $metaboxes was being filled it could be at some point non empty and empty afterwards.
// For instance, if a $role has items to be hidden and the user has this $role, $metaboxes will be filled.
// 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.
$metaboxes[] = implode( ',', $disabled_metaboxes_post_[ $role ] );
}
}
}
$_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox post options -->' . "\n";
// And below we implode $metaboxes because it's an array now.
$_mw_adminimize_admin_head .= '<style type="text/css">' .
implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
if ( ! empty( $metaboxes ) ) {
echo $_mw_adminimize_admin_head;
}
}
/**
* Set metabox options from database an area page.
*/
function _mw_adminimize_set_metabox_page_option() {
// exclude super admin
if ( _mw_adminimize_exclude_super_admin() ) {
return NULL;
}
// Leave the settings screen from Adminimize to see all areas on settings.
if ( _mw_adminimize_exclude_settings_page() ) {
return;
}
$user_roles = _mw_adminimize_get_all_user_roles();
$_mw_adminimize_admin_head = '';
$metaboxes = '';
foreach ( $user_roles as $role ) {
$disabled_metaboxes_page_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_metaboxes_page_' . $role . '_items'
);
if ( ! isset( $disabled_metaboxes_page_[ $role ][ '0' ] ) ) {
$disabled_metaboxes_page_[ $role ][ '0' ] = '';
}
// New since version 1.7.8.
$user = wp_get_current_user();
if ( is_array( $user->roles ) && in_array( $role, $user->roles, TRUE ) ) {
if ( _mw_adminimize_current_user_has_role( $role )
&& isset( $disabled_metaboxes_page_[ $role ] )
&& is_array( $disabled_metaboxes_page_[ $role ] )
) {
$metaboxes = implode( ',', $disabled_metaboxes_page_[ $role ] );
}
}
}
$_mw_adminimize_admin_head .= '<!-- Set Adminimize metabox page options -->' . "\n";
$_mw_adminimize_admin_head .= '<style type="text/css">' .
$metaboxes . ' {display:none !important;}</style>' . "\n";
if ( ! empty( $metaboxes ) ) {
echo $_mw_adminimize_admin_head;
}
}
/**
* Set metabox options from database an area post.
*/
function _mw_adminimize_set_metabox_cp_option() {
// exclude super admin
if ( _mw_adminimize_exclude_super_admin() ) {
return NULL;
}
// Leave the settings screen from Adminimize to see all areas on settings.
if ( _mw_adminimize_exclude_settings_page() ) {
return;
}
$post_id = 0;
if ( isset( $_GET[ 'post' ] ) ) {
$post_id = (int) $_GET[ 'post' ];
} elseif ( isset( $_POST[ 'post_ID' ] ) ) {
$post_id = (int) $_POST[ 'post_ID' ];
}
if ( ! isset( $GLOBALS[ 'post_type' ] ) || empty( $GLOBALS[ 'post_type' ] ) ) {
$current_post_type = get_post_type();
} else {
$current_post_type = $GLOBALS[ 'post_type' ];
}
if ( ! isset( $current_post_type ) ) {
$current_post_type = get_post_type( $post_id );
}
if ( ! isset( $current_post_type ) || ! $current_post_type ) {
$current_post_type = str_replace( 'post_type=', '', esc_attr( $_SERVER[ 'QUERY_STRING' ] ) );
}
// set hard to post
if ( ! $current_post_type ) {
$current_post_type = 'post';
}
$user_roles = _mw_adminimize_get_all_user_roles();
$_mw_adminimize_admin_head = '';
$metaboxes = array();
foreach ( $user_roles as $role ) {
$disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
);
if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] ) ) {
$disabled_metaboxes_[ $current_post_type . '_' . $role ]['0'] = '';
continue;
}
$user = $GLOBALS['current_user'];
if ( is_array( $user->roles ) && in_array( $role, $user->roles, true ) ) {
if ( _mw_adminimize_current_user_has_role( $role )
&& isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
&& is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
) {
$metaboxes[] = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
}
}
}
$_mw_adminimize_admin_head .= '<!-- Set Adminimize post options -->' . "\n";
$_mw_adminimize_admin_head .= '<style type="text/css">' .
implode( ',', $metaboxes ) . ' {display:none !important;}</style>' . "\n";
if ( ! empty( $metaboxes ) ) {
echo $_mw_adminimize_admin_head;
}
}
/**
* Set link options in area links of back end.
*/
function _mw_adminimize_set_link_option() {
// exclude super admin
if ( _mw_adminimize_exclude_super_admin() ) {
return NULL;
}
// Leave the settings screen from Adminimize to see all areas on settings.
if ( _mw_adminimize_exclude_settings_page() ) {
return;
}
$user_roles = _mw_adminimize_get_all_user_roles();
$_mw_adminimize_admin_head = '';
foreach ( $user_roles as $role ) {
$disabled_link_option_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_link_option_' . $role . '_items'
);
}
foreach ( $user_roles as $role ) {
if ( ! isset( $disabled_link_option_[ $role ][ '0' ] ) ) {
$disabled_link_option_[ $role ][ '0' ] = '';
}
}