forked from wp-media/adminimize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminimize.php
executable file
·1926 lines (1647 loc) · 62.3 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: Frank Bültge
* Author URI: http://bueltge.de/
* Version: 1.8.6-Dev
* License: GPLv2+
*
* Php Version 5.3
*
* @package WordPress
* @author Frank Bültge <[email protected]>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version 2015-03-27
*/
/**
* 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.
*/
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( dirname( __FILE__ ) ) );
define( 'FB_ADMINIMIZE_TEXTDOMAIN', _mw_adminimize_get_plugin_data( 'TextDomain' ) );
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__ );
$plugin_value = $plugin_data[ $value ];
return $plugin_value;
}
function _mw_adminimize_textdomain() {
load_plugin_textdomain(
_mw_adminimize_get_plugin_data( 'TextDomain' ),
FALSE,
dirname( FB_ADMINIMIZE_BASENAME ) . _mw_adminimize_get_plugin_data( 'DomainPath' )
);
}
function _mw_adminimize_recursive_in_array( $needle, $haystack ) {
if ( '' != $haystack ) {
foreach ( $haystack as $stalk ) {
if ( $needle == $stalk
|| ( is_array( $stalk ) && _mw_adminimize_recursive_in_array( $needle, $stalk )
)
) {
return TRUE;
}
}
return FALSE;
}
return FALSE;
}
/**
* some basics for message
*/
class _mw_adminimize_message_class {
/**
* constructor
*/
function _mw_adminimize_message_class() {
$this->localizion_name = FB_ADMINIMIZE_TEXTDOMAIN;
$this->errors = new WP_Error();
$this->initialize_errors();
}
/**
* get_error - Returns an error message based on the passed code
* Parameters - $code (the error code as a string)
*
* @param string $code
*
* @return string $errorMessage
*/
function get_error( $code = '' ) {
$errorMessage = $this->errors->get_error_message( $code );
if ( NULL == $errorMessage ) {
return __( 'Unknown error.', $this->localizion_name );
}
return $errorMessage;
}
/**
* Initializes all the error messages
*/
function initialize_errors() {
$this->errors->add( '_mw_adminimize_update', __( 'The updates were saved.', $this->localizion_name ) );
$this->errors->add(
'_mw_adminimize_access_denied',
__( 'You have not enough rights to edit entries in the database.', $this->localizion_name )
);
$this->errors->add(
'_mw_adminimize_import', __( 'All entries in the database were imported.', $this->localizion_name )
);
$this->errors->add(
'_mw_adminimize_deinstall', __( 'All entries in the database were deleted.', $this->localizion_name )
);
$this->errors->add(
'_mw_adminimize_deinstall_yes', __( 'Set the checkbox on deinstall-button.', $this->localizion_name )
);
$this->errors->add(
'_mw_adminimize_get_option', __( 'Can\'t load menu and submenu.', $this->localizion_name )
);
$this->errors->add( '_mw_adminimize_set_theme', __( 'Backend-Theme was activated!', $this->localizion_name ) );
$this->errors->add(
'_mw_adminimize_load_theme', __( 'Load user data to themes was successful.', $this->localizion_name )
);
}
} // end class
function _mw_adminimize_exclude_super_admin() {
// exclude super admin
if ( function_exists( 'is_super_admin' )
&& is_super_admin()
&& 1 == _mw_adminimize_get_option_value( '_mw_adminimize_exclude_super_admin' )
) {
return TRUE;
}
return FALSE;
}
/**
* _mw_adminimize_get_all_user_roles() - Returns an array with all user roles(names) in it.
* Inclusive self defined roles (for example with the 'Role Manager' plugin).
* code by Vincent Weber, www.webRtistik.nl
*
* @uses $wp_roles
* @return array $user_roles
*/
function _mw_adminimize_get_all_user_roles() {
global $wp_roles;
$user_roles = array();
if ( isset( $wp_roles->roles ) && is_array( $wp_roles->roles ) ) {
foreach ( $wp_roles->roles as $role => $data ) {
array_push( $user_roles, $role );
//$data contains caps, maybe for later use..
}
}
// exclude the new bbPress roles
$user_roles = array_diff(
$user_roles,
array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
);
return $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() {
global $wp_roles;
$user_roles_names = array();
foreach ( $wp_roles->role_names as $role_name => $data ) {
if ( function_exists( 'translate_user_role' ) ) {
$data = translate_user_role( $data );
} else {
$data = _x( $data, 'Translate each user role.' );
}
array_push( $user_roles_names, $data );
}
// exclude the new bbPress roles
$user_roles_names = array_diff(
$user_roles_names,
array(
__( 'Keymaster', 'bbpress' ),
__( 'Moderator', 'bbpress' ),
__( 'Participant', 'bbpress' ),
__( 'Spectator', 'bbpress' ),
__( 'Blocked', 'bbpress' )
)
);
return $user_roles_names;
}
/**
* Control Flash Uploader
*
* @return boolean
*/
function _mw_adminimize_control_flashloader() {
$_mw_adminimize_control_flashloader = _mw_adminimize_get_option_value( '_mw_adminimize_control_flashloader' );
if ( $_mw_adminimize_control_flashloader == '1' ) {
return FALSE;
} else {
return TRUE;
}
}
/**
* return post type
*/
function _mw_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
else if ( $typenow ) {
return $typenow;
} // check the global $current_screen object - set in sceen.php
else if ( $current_screen && $current_screen->post_type ) {
return $current_screen->post_type;
} // lastly check the post_type querystring
else 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
*
* @uses $pagenow
*/
function _mw_adminimize_admin_init() {
global $pagenow, $post_type, $menu, $submenu;
if ( isset( $_GET[ 'post' ] ) ) {
$post_id = (int) esc_attr( $_GET[ 'post' ] );
} elseif ( isset( $_POST[ 'post_ID' ] ) ) {
$post_id = (int) esc_attr( $_POST[ 'post_ID' ] );
} else {
$post_id = 0;
}
$current_post_type = $post_type;
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_get_current_post_type();
}
if ( ! $current_post_type ) // set hard to post
{
$current_post_type = 'post';
}
$user_roles = _mw_adminimize_get_all_user_roles();
// check for use on multisite
if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
$adminimizeoptions = get_site_option( 'mw_adminimize' );
} else {
$adminimizeoptions = get_option( 'mw_adminimize' );
}
// 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_global_option_[ $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'
);
array_push( $disabled_metaboxes_post_all, $disabled_metaboxes_post_[ $role ] );
array_push( $disabled_metaboxes_page_all, $disabled_metaboxes_page_[ $role ] );
}
// global options
// exclude super admin
if ( ! _mw_adminimize_exclude_super_admin() ) {
$_mw_adminimize_footer = _mw_adminimize_get_option_value( '_mw_adminimize_footer' );
switch ( $_mw_adminimize_footer ) {
case 1:
wp_enqueue_script(
'_mw_adminimize_remove_footer',
WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_footer.js',
array( 'jquery' )
);
break;
}
$_mw_adminimize_header = _mw_adminimize_get_option_value( '_mw_adminimize_header' );
switch ( $_mw_adminimize_header ) {
case 1:
wp_enqueue_script(
'_mw_adminimize_remove_header',
WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_header.js',
array( 'jquery' )
);
break;
}
//post-page options
if ( in_array( $pagenow, $def_post_pages ) ) {
$_mw_adminimize_tb_window = _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.js',
array( 'thickbox' )
);
break;
}
$_mw_adminimize_timestamp = _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.js',
array( 'jquery' )
);
break;
}
//category options
$_mw_adminimize_cat_full = _mw_adminimize_get_option_value( '_mw_adminimize_cat_full' );
switch ( $_mw_adminimize_cat_full ) {
case 1:
wp_enqueue_style(
'adminimize-ful-category',
WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/css/mw_cat_full.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', create_function( '', 'return "tinymce";' ) );
}
// remove media bottons
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' );
}
}
$_mw_adminimize_control_flashloader = _mw_adminimize_get_option_value( '_mw_adminimize_control_flashloader' );
switch ( $_mw_adminimize_control_flashloader ) {
case 1:
add_filter( 'flash_uploader', '_mw_adminimize_control_flashloader', 1 );
break;
}
}
// set menu option
add_action( 'admin_head', '_mw_adminimize_set_menu_option', 1 );
// global_options
add_action( 'admin_head', '_mw_adminimize_set_global_option', 1 );
// set metabox post option
if ( in_array( $pagenow, $def_post_pages ) && in_array( $current_post_type, $def_post_types ) ) {
add_action( 'admin_head', '_mw_adminimize_set_metabox_post_option', 1 );
}
// set metabox page option
if ( in_array( $pagenow, $def_page_pages ) && in_array( $current_post_type, $def_page_types ) ) {
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 )
&& in_array(
$current_post_type, $def_custom_types
)
) {
add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
}
// set link option
if ( in_array( $pagenow, $link_pages ) ) {
add_action( 'admin_head', '_mw_adminimize_set_link_option', 1 );
}
// set wp nav menu options
if ( in_array( $pagenow, $nav_menu_pages ) ) {
add_action( 'admin_head', '_mw_adminimize_set_nav_menu_option', 1 );
}
// set widget options
if ( in_array( $pagenow, $widget_pages ) ) {
add_action( 'admin_head', '_mw_adminimize_set_widget_option', 1 );
}
$adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
$adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
}
/**
* Init always with WP
*/
function _mw_adminimize_init() {
// change Admin Bar and user Info
if ( version_compare( $GLOBALS[ 'wp_version' ], '3.3alpha', '>=' ) ) {
_mw_adminimize_set_menu_option_33();
} else {
add_action( 'admin_head', '_mw_adminimize_set_user_info' );
add_action( 'wp_head', '_mw_adminimize_set_user_info' );
}
}
// on admin init
define( 'MW_ADMIN_FILE', plugin_basename( __FILE__ ) );
if ( is_admin() ) {
add_action( 'admin_init', '_mw_adminimize_textdomain' );
add_action( 'admin_init', '_mw_adminimize_admin_init', 2 );
/* maybe later
if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) )
add_action( 'network_admin_menu', '_mw_adminimize_add_settings_page' );
*/
add_action( 'admin_menu', '_mw_adminimize_add_settings_page' );
add_action( 'admin_menu', '_mw_adminimize_remove_dashboard' );
}
add_action( 'init', '_mw_adminimize_init', 2 );
register_activation_hook( __FILE__, '_mw_adminimize_install' );
register_uninstall_hook( __FILE__, '_mw_adminimize_deinstall' );
//register_deactivation_hook(__FILE__, '_mw_adminimize_deinstall' );
/**
* list category-box in sidebar
*
* @uses $post_ID
*/
function _mw_adminimize_sidecat_list_category_box() {
global $post_ID;
?>
<div class="inside" id="categorydivsb">
<p><strong><?php _e( "Categories" ); ?></strong></p>
<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
<?php wp_category_checklist( $post_ID ); ?>
</ul>
<?php if ( ! defined( 'WP_PLUGIN_DIR' ) ) { // for wp <2.6 ?>
<div id="category-adder" class="wp-hidden-children">
<h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e(
'+ Add New Category'
); ?></a></h4>
<p id="category-add" class="wp-hidden-child">
<input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e(
'New category name'
); ?>" tabindex="3" />
<?php wp_dropdown_categories(
array(
'hide_empty' => 0,
'name' => 'newcat_parent',
'orderby' => 'name',
'hierarchical' => 1,
'show_option_none' => __( 'Parent category' ),
'tab_index' => 3
)
); ?>
<input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e(
'Add'
); ?>" tabindex="3" />
<?php wp_nonce_field( 'add-category', '_ajax_nonce', FALSE ); ?>
<span id="category-ajax-response"></span>
</p>
</div>
<?php } else { ?>
<div id="category-adder" class="wp-hidden-children">
<h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e(
'+ Add New Category'
); ?></a></h4>
<p id="category-add" class="wp-hidden-child">
<label class="hidden" for="newcat"><?php _e(
'Add New Category'
); ?></label><input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e(
'New category name'
); ?>" tabindex="3" aria-required="TRUE" />
<br />
<label class="hidden" for="newcat_parent"><?php _e(
'Parent category'
); ?>:</label><?php wp_dropdown_categories(
array(
'hide_empty' => 0,
'name' => 'newcat_parent',
'orderby' => 'name',
'hierarchical' => 1,
'show_option_none' => __( 'Parent category' ),
'tab_index' => 3
)
); ?>
<input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e(
'Add'
); ?>" tabindex="3" />
<?php wp_nonce_field( 'add-category', '_ajax_nonce', FALSE ); ?>
<span id="category-ajax-response"></span>
</p>
</div>
<?php } ?>
</div>
<?php
}
/**
* Remove the dashboard
*
* @author Basic Austin Matzko
* @see http://www.ilfilosofo.com/blog/2006/05/24/plugin-remove-the-wordpress-dashboard/
*/
function _mw_adminimize_remove_dashboard() {
global $menu, $user_ID, $wp_version;
$disabled_menu_ = '';
$disabled_submenu_ = '';
$user_roles = _mw_adminimize_get_all_user_roles();
foreach ( $user_roles as $role ) {
$disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_menu_' . $role . '_items'
);
$disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_submenu_' . $role . '_items'
);
}
$disabled_menu_all = array();
$disabled_submenu_all = array();
foreach ( $user_roles as $role ) {
array_push( $disabled_menu_all, $disabled_menu_[ $role ] );
array_push( $disabled_submenu_all, $disabled_submenu_[ $role ] );
}
// remove dashboard
if ( $disabled_menu_all != '' || $disabled_submenu_all != '' ) {
foreach ( $user_roles as $role ) {
if ( current_user_can( $role ) ) {
if ( _mw_adminimize_recursive_in_array(
'index.php', $disabled_menu_[ $role ]
)
|| _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
) {
$redirect = TRUE;
} else {
$redirect = FALSE;
}
}
}
// redirect option, if Dashboard is inactive
if ( isset( $redirect ) && $redirect ) {
$_mw_adminimize_db_redirect = _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;
}
// fallback for WP smaller 3.0
if ( version_compare(
$wp_version, "3.0alpha", "<"
)
&& 'edit.php?post_type=page' == $_mw_adminimize_db_redirect
) {
$_mw_adminimize_db_redirect = 'edit-pages.php';
}
$the_user = new WP_User( $user_ID );
reset( $menu );
$page = key( $menu );
while ( ( __( 'Dashboard' ) != $menu[ $page ][ 0 ] ) && next( $menu )
|| ( __(
'Dashboard'
) != $menu[ $page ][ 1 ] )
&& next( $menu ) ) {
$page = key( $menu );
}
if ( __( 'Dashboard' ) == $menu[ $page ][ 0 ] || __( 'Dashboard' ) == $menu[ $page ][ 1 ] ) {
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_redirect( $_mw_adminimize_db_redirect );
}
}
}
}
/**
* set menu options from database
*/
function _mw_adminimize_set_user_info() {
global $user_identity, $wp_version;
// exclude super admin
if ( _mw_adminimize_exclude_super_admin() ) {
return NULL;
}
$user_roles = _mw_adminimize_get_all_user_roles();
foreach ( $user_roles as $role ) {
$disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_menu_' . $role . '_items'
);
$disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_submenu_' . $role . '_items'
);
}
$_mw_adminimize_admin_head = "\n";
$_mw_adminimize_user_info = _mw_adminimize_get_option_value( '_mw_adminimize_user_info' );
$_mw_adminimize_ui_redirect = _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' );
// change user-info
switch ( $_mw_adminimize_user_info ) {
case 1:
$_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
$_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove(); });' . "\n";
$_mw_adminimize_admin_head .= '</script>' . "\n";
break;
case 2:
if ( version_compare( $wp_version, "3.2alpha", ">=" ) ) {
if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
$_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
dirname( __FILE__ )
) . '/css/mw_small_user_info31.css" type="text/css" />' . "\n";
}
$_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
dirname( __FILE__ )
) . '/css/mw_small_user_info32.css" type="text/css" />' . "\n";
} elseif ( version_compare( $wp_version, "3.0alpha", ">=" ) ) {
if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
$_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
dirname( __FILE__ )
) . '/css/mw_small_user_info31.css" type="text/css" />' . "\n";
}
$_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
dirname( __FILE__ )
) . '/css/mw_small_user_info30.css" type="text/css" />' . "\n";
} elseif ( version_compare( substr( $wp_version, 0, 3 ), '2.7', '>=' ) ) {
$_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
dirname( __FILE__ )
) . '/css/mw_small_user_info27.css" type="text/css" />' . "\n";
} else {
$_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
dirname( __FILE__ )
) . '/css/mw_small_user_info.css" type="text/css" />' . "\n";
}
$_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
$_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove();';
if ( $_mw_adminimize_ui_redirect == '1' ) {
$_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
'siteurl'
) . wp_nonce_url(
( '/wp-login.php?action=logout&redirect_to=' ) . get_option( 'siteurl' ), 'log-out'
) . '" title="' . __( 'Log Out' ) . '">' . __( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
} else {
$_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
'siteurl'
) . wp_nonce_url( ( '/wp-login.php?action=logout' ), 'log-out' ) . '" title="' . __(
'Log Out'
) . '">' . __( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
}
$_mw_adminimize_admin_head .= '</script>' . "\n";
break;
case 3:
if ( version_compare( $wp_version, "3.2alpha", ">=" ) ) {
if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
$_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
dirname( __FILE__ )
) . '/css/mw_small_user_info31.css" type="text/css" />' . "\n";
}
$_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
dirname( __FILE__ )
) . '/css/mw_small_user_info32.css" type="text/css" />' . "\n";
} elseif ( version_compare( $wp_version, "3.0alpha", ">=" ) ) {
if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
$_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
dirname( __FILE__ )
) . '/css/mw_small_user_info31.css" type="text/css" />' . "\n";
}
$_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
dirname( __FILE__ )
) . '/css/mw_small_user_info30.css" type="text/css" />' . "\n";
} elseif ( version_compare( substr( $wp_version, 0, 3 ), '2.7', '>=' ) ) {
$_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
dirname( __FILE__ )
) . '/css/mw_small_user_info27.css" type="text/css" />' . "\n";
} else {
$_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
dirname( __FILE__ )
) . '/css/mw_small_user_info.css" type="text/css" />' . "\n";
}
$_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
$_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove();';
if ( $_mw_adminimize_ui_redirect == '1' ) {
$_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
'siteurl'
) . ( '/wp-admin/profile.php' ) . '">' . $user_identity . '</a> | <a href="' . get_option(
'siteurl'
) . wp_nonce_url(
( '/wp-login.php?action=logout&redirect_to=' ) . get_option( 'siteurl' ), 'log-out'
) . '" title="' . __( 'Log Out' ) . '">' . __( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
} else {
$_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
'siteurl'
) . ( '/wp-admin/profile.php' ) . '">' . $user_identity . '</a> | <a href="' . get_option(
'siteurl'
) . wp_nonce_url( ( '/wp-login.php?action=logout' ), 'log-out' ) . '" title="' . __(
'Log Out'
) . '">' . __( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
}
$_mw_adminimize_admin_head .= '</script>' . "\n";
break;
}
echo $_mw_adminimize_admin_head;
}
/**
* Set menu for settings
*/
function _mw_adminimize_set_menu_option() {
global $menu, $submenu, $current_screen;
// exclude super admin
if ( _mw_adminimize_exclude_super_admin() ) {
return NULL;
}
if ( 'settings_page_adminimize/adminimize' === $current_screen->id ) {
return NULL;
}
$user_roles = _mw_adminimize_get_all_user_roles();
$disabled_menu_ = '';
$disabled_submenu_ = '';
foreach ( $user_roles as $role ) {
$disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_menu_' . $role . '_items'
);
$disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_submenu_' . $role . '_items'
);
}
$mw_adminimize_menu = array();
$mw_adminimize_submenu = array();
// set menu
//if ( isset( $disabled_menu_[ 'editor' ] ) && '' != $disabled_menu_[ 'editor' ] ) {
// set admin-menu
foreach ( $user_roles as $role ) {
$user = wp_get_current_user();
if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
if ( current_user_can( $role ) ) {
$mw_adminimize_menu = $disabled_menu_[ $role ];
$mw_adminimize_submenu = $disabled_submenu_[ $role ];
}
}
}
// fallback on users.php on all userroles smaller admin
if ( is_array( $mw_adminimize_menu ) && in_array( 'users.php', $mw_adminimize_menu ) ) {
$mw_adminimize_menu[ ] = 'profile.php';
}
if ( isset( $menu ) && ! empty( $menu ) ) {
foreach ( $menu as $index => $item ) {
if ( 'index.php' === $item ) {
continue;
}
if ( isset( $item[ 2 ] ) ) {
if ( isset( $mw_adminimize_menu ) && in_array( $item[ 2 ], $mw_adminimize_menu ) ) {
unset( $menu[ $index ] );
}
if ( isset( $submenu ) && ! empty( $submenu[ $item[ 2 ] ] ) ) {
foreach ( $submenu[ $item[ 2 ] ] as $subindex => $subitem ) {
if ( isset( $mw_adminimize_submenu ) && in_array( $subitem[ 2 ], $mw_adminimize_submenu ) )
//if ( 'profile.php' === $subitem[2] )
// unset( $menu[70] );
{
unset( $submenu[ $item[ 2 ] ][ $subindex ] );
}
}
}
}
}
}
//}
}
/**
* set global options in backend in all areas
*/
function _mw_adminimize_set_global_option() {
global $_wp_admin_css_colors;
// exclude super admin
if ( _mw_adminimize_exclude_super_admin() ) {
return NULL;
}
$user_roles = _mw_adminimize_get_all_user_roles();
$_mw_adminimize_admin_head = '';
// remove_action( 'admin_head', 'index_js' );
foreach ( $user_roles as $role ) {
$disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
'mw_adminimize_disabled_global_option_' . $role . '_items'
);
}
foreach ( $user_roles as $role ) {
if ( ! isset( $disabled_global_option_[ $role ][ '0' ] ) ) {
$disabled_global_option_[ $role ][ '0' ] = '';
}
}
$global_options = '';
// new 1.7.8
foreach ( $user_roles as $role ) {
$user = wp_get_current_user();
if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
if ( current_user_can( $role )
&& isset( $disabled_global_option_[ $role ] )
&& is_array( $disabled_global_option_[ $role ] )
) {
$global_options = implode( ', ', $disabled_global_option_[ $role ] );
}
}
}
if ( isset( $global_options ) && 0 != strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
$_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";
if ( ! empty( $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 NULL;
}
$user_roles = _mw_adminimize_get_all_user_roles();
$_mw_adminimize_admin_head = '';
$metaboxes = '';
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' ] = '';
}