forked from wp-plugins/toggle-meta-boxes-sitewide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds_wp3_toggle_meta_boxes.php
439 lines (377 loc) · 17.4 KB
/
ds_wp3_toggle_meta_boxes.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
<?php
/*
Plugin Name: Toggle Meta Boxes Sitewide
Plugin URI: http://wordpress.org/extend/plugins/toggle-meta-boxes-sitewide/
Version: 4.6
Description: WP Multisite network plugin. Go to Network-->Settings to "Enable Administration Meta Boxes". Meta boxes(post, page, link, and dashboard) are unchecked and disabled by default. Extra options to toggle the Quick Edit buttons, Media buttons, Screen Options and Help links. Toggle to Restrict Comment Editing to Editor+ roles. SuperAdmin comments can only be edited by a SuperAdmin.
Author: D Sader
Author URI: http://dsader.snowotherway.org
Network: true
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
class DS_Meta {
var $l10n_prefix;
function __construct() {
$this->l10n_prefix = 'toggle-meta-boxes-sitewide';
//------------------------------------------------------------------------//
//---Hooks----------------------------------------------------------------//
//------------------------------------------------------------------------//
add_action( 'admin_init', array($this, 'ds_localization_init' ));
add_action( 'wpmu_options', array($this, 'ds_meta_box_option' )); // "Menu Settings->Enable Administration Menus->Plugins"
add_action( 'admin_head', array($this, 'ds_toggle_meta_boxes' )); // toggle metaboxes
add_action( 'admin_head', array($this, 'ds_extras_remove' )); // toggle some extras
add_action( 'wp_dashboard_setup', array($this, 'ds_remove_dashboard_widgets' ));
add_action( 'wp_network_dashboard_setup', array($this, 'ds_remove_network_dashboard_widgets' ));
add_filter( 'comment_row_actions', array($this, 'ds_remove_comment_edit'), 1, 2); //Comment Editing Restricition
add_filter( 'map_meta_cap', array($this, 'ds_network_admin_restrict_comment_editing'), 10, 4 ); //Comment Editing Restricitons
add_action( 'admin_head-nav-menus.php', array($this, 'ds_nav_menus' ));
//add_filter( 'manage_nav-menus_columns', array($this, 'ds_nav_menu_manage_columns'),99 ); //not working yet: TODO
}
function ds_localization_init() {
load_plugin_textdomain(
$this->l10n_prefix, // Plugin text domain reference
false, // Abspath - deprecated parameter - leave as false
dirname( plugin_basename( __FILE__ ) ) . '/languages/' // Path to translation files
);
}
function ds_nav_menu_manage_columns($array) {
$menu_perms = get_site_option( "menu_items" );
if( isset($menu_perms[ 'nav_menu_links_adv' ]) ) {
$array = array(
'_title' => __('Show advanced menu properties'),
'cb' => '<input type="checkbox" />',
'link-target' => __('Link Target'),
'css-classes' => __('CSS Classes'),
'xfn' => __('Link Relationship (XFN)'),
'description' => __('Description'),
);
return $array;
}
}
function ds_nav_menus() {
// Menus nav-menus.php
if( current_user_can( 'edit_theme_options' )) {
$menu_perms = get_site_option( "menu_items" );
$screen = get_current_screen();
if( !isset($menu_perms[ 'nav_menu_links' ]) )
remove_meta_box( 'add-custom-links', 'nav-menus','side' );
function ds_nav_menu_post_type_meta_boxes() {
$post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
if ( ! $post_types )
return;
foreach ( $post_types as $post_type ) {
if ( $post_type ) {
$id = $post_type->name;
remove_meta_box("add-{$id}", 'nav-menus','side' );
}
}
}
function ds_nav_menu_taxonomy_meta_boxes() {
$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' );
if ( !$taxonomies )
return;
foreach ( $taxonomies as $tax ) {
if ( $tax ) {
$id = $tax->name;
remove_meta_box("add-{$id}", 'nav-menus','side' );
}
}
}
if( !isset($menu_perms[ 'nav_menu_pages' ]) ) ds_nav_menu_post_type_meta_boxes();
if( !isset($menu_perms[ 'nav_menu_cats' ]) ) ds_nav_menu_taxonomy_meta_boxes();
}
}
function ds_remove_dashboard_widgets() {
// DASHBOARD /wp-admin/
$menu_perms = get_site_option( "menu_items" );
if(current_user_can('read')) {
if( !isset($menu_perms[ 'dash_prim_mb' ]) ) {
remove_meta_box('dashboard_primary', 'dashboard', 'side');
}
if( !isset($menu_perms[ 'dash_sec_mb' ]) ) {
remove_meta_box('dashboard_secondary', 'dashboard', 'side');
}
if( !isset($menu_perms[ 'dash_links_mb' ]) )
remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal');
if( !isset($menu_perms[ 'dash_comments_mb' ]) )
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
if( !isset($menu_perms[ 'dash_right_now_mb' ]) )
remove_meta_box('dashboard_right_now', 'dashboard', 'normal');
}
if ( current_user_can('edit_posts') ) {
if( !isset($menu_perms[ 'dash_drafts_mb' ]) )
remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
if( !isset($menu_perms[ 'dash_quick_mb' ]) )
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
}
}
function ds_remove_network_dashboard_widgets() {
// Network Dashboard wp-admin/network/
$menu_perms = get_site_option( "menu_items" );
if( !isset($menu_perms[ 'dash_net_prim_mb' ]) ) {
remove_meta_box('dashboard_primary', 'dashboard-network', 'side');
}
if( !isset($menu_perms[ 'dash_net_sec_mb' ]) ) {
remove_meta_box('dashboard_secondary', 'dashboard-network', 'side');
}
if( !isset($menu_perms[ 'dash_net_plugins' ]) ) {
remove_meta_box( 'dashboard_plugins', 'dashboard-network', 'normal' );
}
if( !isset($menu_perms[ 'dash_net_right_now_mb' ]) ) {
remove_meta_box( 'network_dashboard_right_now', 'dashboard-network', 'normal' );
}
}
//------------------------------------------------------------------------//
//---Functions to Enable/Disable admin menus------------------------------//
//------------------------------------------------------------------------//
function ds_toggle_meta_boxes() {
global $tax_name, $post_type;
$menu_perms = get_site_option( "menu_items" );
if( !isset($menu_perms[ 'super_admin_mb' ] ) && is_super_admin())
return;
// POSTS edit-form-advanced.php
if( !isset($menu_perms[ 'format_mb' ]) )
remove_meta_box('formatdiv', $post_type, 'side');
if( !isset($menu_perms[ 'publish_mb' ]) )
remove_meta_box('submitdiv', $post_type, 'side');
if( !isset($menu_perms[ 'tags_mb' ]) )
remove_meta_box('tagsdiv-' . $tax_name, $post_type, 'side');
if( !isset($menu_perms[ 'tax_cats_mb' ]) )
remove_meta_box($tax_name . 'div', $post_type, 'side');
if( !isset($menu_perms[ 'cats_mb' ]) )
remove_meta_box('categorydiv', $post_type, 'side');
if( !isset($menu_perms[ 'att_mb' ]) )
remove_meta_box('pageparentdiv', $post_type, 'side');
if( !isset($menu_perms[ 'feat_img_mb' ]) )
remove_meta_box('postimagediv', $post_type, 'side');
if( !isset($menu_perms[ 'excerpt_mb' ]) )
remove_meta_box('postexcerpt', $post_type, 'normal');
if( !isset($menu_perms[ 'track_mb' ]) )
remove_meta_box('trackbacksdiv', $post_type, 'normal');
if( !isset($menu_perms[ 'custom_field_mb' ]) )
remove_meta_box('postcustom', $post_type, 'normal');
if( !isset($menu_perms[ 'disc_mb' ]) )
remove_meta_box('commentstatusdiv', $post_type, 'normal');
if( !isset($menu_perms[ 'slug_mb' ]) ) {
remove_meta_box('slugdiv', $post_type, 'normal');
}
if( !isset($menu_perms[ 'author_mb' ]) )
remove_meta_box('authordiv', $post_type, 'normal');
if( !isset($menu_perms[ 'revs_mb' ]) )
remove_meta_box('revisionsdiv', $post_type, 'normal'); // still saves aplenty unless redefined, though
if( !isset($menu_perms[ 'comments_mb' ]) )
remove_meta_box('commentsdiv', $post_type, 'normal');
// LINKS edit-link-form.php
if(current_user_can('manage_links')) {
if( !isset($menu_perms[ 'link_save_mb' ]) )
remove_meta_box('linksubmitdiv', 'link', 'side');
if( !isset($menu_perms[ 'link_cat_mb' ]) )
remove_meta_box('linkcategorydiv', 'link', 'normal');
if( !isset($menu_perms[ 'link_target_mb' ]) )
remove_meta_box('linktargetdiv', 'link', 'normal');
if( !isset($menu_perms[ 'link_xfn_mb' ]) )
remove_meta_box('linkxfndiv', 'link', 'normal');
if( !isset($menu_perms[ 'link_adv_mb' ]) )
remove_meta_box('linkadvanceddiv', 'link', 'normal');
}
}
//------------------------------------------------------------------------//
//--- Function to toggle extra administration cruft----------------------//
//----"Quick Edit" inline editing: http://core.trac.wordpress.org/ticket/12940---//
//----Comment Editing Restritions----------------------------------------//
//------------------------------------------------------------------------//
function ds_extras_remove() {
$menu_perms = get_site_option( "menu_items" );
if( is_array( $menu_perms ) == false )
$menu_perms = array();
if( !isset($menu_perms[ 'super_admin_mb' ] ) && is_super_admin())
return;
// css trickery for Slug/Permalink/Short URL
if( !isset($menu_perms[ 'edit_slug_box' ]) )
echo '<style>#edit-slug-box { display:none;}</style>';
// css trickery for Screen Options and Help
if( !isset($menu_perms[ 'screen_options_link' ]) )
echo '<style>#screen-options-link-wrap { display: none;}</style>';
if( !isset($menu_perms[ 'contextual_help_link' ]) )
echo '<style>#contextual-help-link-wrap { display: none;}</style>';
// Quick Edit
//disable quickedit in post rows
if( !isset($menu_perms[ 'quick_edit_posts' ]) ) {
add_filter('post_row_actions',
function ($actions, $post) {
unset($actions["inline hide-if-no-js"]);
return $actions;
}, 10, 2);
}
//disable quickedit in page rows
if( !isset($menu_perms[ 'quick_edit_pages' ]) ) {
add_filter('page_row_actions',
function ($actions, $post) {
unset($actions["inline hide-if-no-js"]);
return $actions;
}, 10, 2);
}
//disable quickedit in any tag rows
if( !isset($menu_perms[ 'quick_edit_tag' ]) ) {
add_filter('tag_row_actions',
function ($actions, $post) {
unset($actions["inline hide-if-no-js"]);
return $actions;
}, 10, 2);
}
//disable quickedit in taxonomy=post_tag rows
if( !isset($menu_perms[ 'quick_edit_post_tag' ]) ) {
add_filter('post_tag_row_actions',
function ($actions, $post) {
unset($actions["inline hide-if-no-js"]);
return $actions;
}, 10, 2);
}
//disable quickedit in taxonomy=category rows
if( !isset($menu_perms[ 'quick_edit_category' ]) ) {
add_filter('category_row_actions',
function ($actions, $post) {
unset($actions["inline hide-if-no-js"]);
return $actions;
}, 10, 2);
}
//disable quickedit in taxonomy=link_category rows
if( !isset($menu_perms[ 'quick_edit_link_category' ]) ) {
add_filter('link_category_row_actions',
function ($actions, $post) {
unset($actions["inline hide-if-no-js"]);
return $actions;
}, 10, 2);
}
//disable quickedit in comment rows
if( !isset($menu_perms[ 'quick_edit_comments' ]) ) {
add_filter('comment_row_actions',
function ($actions, $post) {
unset($actions["quickedit"]);
return $actions;
}, 10, 2);
}
// Media Buttons
if( !isset($menu_perms[ 'media_buttons' ]) )
remove_action( 'media_buttons', 'media_buttons' );
//Welcome Panel
if( !isset($menu_perms[ 'welcome_panel' ]) )
remove_action( 'welcome_panel', 'wp_welcome_panel' );
}
//Comment Editing Restrictions
// http://scribu.net/wordpress/prevent-blog-authors-from-editing-comments.html
function ds_network_admin_restrict_comment_editing( $caps, $cap, $user_id, $args ) {
$menu_perms = get_site_option( "menu_items" );
if( !isset($menu_perms[ 'super_admin_mb' ] ) && is_super_admin())
return $caps;
if( isset($menu_perms[ 'comment_edit' ]) ) {
if ( 'edit_comment' == $cap ) {
$comment = get_comment( $args[0] );
if ( is_super_admin( $comment->user_id ) )
$caps[] = 'manage_network'; //NetworkAdmin is only role that can edit this comment - no user can approve or trash it either!
if ( ! is_super_admin( $comment->user_id ) && $comment->user_id != $user_id )
$caps[] = 'moderate_comments'; //NetworkAdmin, Admins, Editors roles can edit others comments
}
}
return $caps;
}
function ds_remove_comment_edit($actions, $comment) {
$menu_perms = get_site_option( "menu_items" );
if( !isset($menu_perms[ 'super_admin_mb' ] ) && is_super_admin())
return $actions;
if( isset($menu_perms[ 'comment_edit' ]) ) {
$user_id = get_current_user_id();
if ($comment->user_id != $user_id) {
unset($actions['edit']); // edit link appears only on own comments
unset($actions['quickedit']); //quickedit may already be toggled for all roles
}
}
return $actions;
}
//------------------------------------------------------------------------//
//---Function SiteAdmin->Options------------------------------------------//
//---Options are saved as site_options on wpmu-options.php page-----------//
//------------------------------------------------------------------------//
function ds_meta_box_option() {
$meta_perms = get_site_option( "menu_items" );
if( is_array( $meta_perms ) == false )
$meta_perms = array();
$meta_items = array(
'super_admin_mb' => __( 'Super Admin gets the following limited meta boxes, too?', $this->l10n_prefix ),
//Extras
'screen_options_link' => __( 'Screen Options Link', $this->l10n_prefix ),
'contextual_help_link' => __( 'Contextual Help Link', $this->l10n_prefix ),
'edit_slug_box' => __( 'Edit Slug Box', $this->l10n_prefix ),
'media_buttons' => __( 'Add Media Button', $this->l10n_prefix ),
//Meta Boxes
'format_mb' => __( 'Format', $this->l10n_prefix ),
'publish_mb' => __( 'Publish', $this->l10n_prefix ),
'tags_mb' => __( 'Tags', $this->l10n_prefix ),
'tax_cats_mb' => __( 'Taxonomy Categories', $this->l10n_prefix ),
'cats_mb' => __( 'Categories', $this->l10n_prefix ),
'att_mb' => __( 'Attributes', $this->l10n_prefix ),
'feat_img_mb' => __( 'Featured Image', $this->l10n_prefix ),
'excerpt_mb' => __( 'Excerpt', $this->l10n_prefix ),
'track_mb' => __( 'Send Trackbacks', $this->l10n_prefix ),
'custom_field_mb' => __( 'Custom Fields', $this->l10n_prefix ),
'disc_mb' => __( 'Discussion', $this->l10n_prefix ),
'slug_mb' => __( 'Slug', $this->l10n_prefix ),
'author_mb' => __( 'Author', $this->l10n_prefix ),
'revs_mb' => __( 'Revisions', $this->l10n_prefix ),
'comments_mb' => __( 'Comments', $this->l10n_prefix ),
'link_save_mb' => __( 'Link Save', $this->l10n_prefix ),
'link_cat_mb' => __( 'Link Categories', $this->l10n_prefix ),
'link_target_mb' => __( 'Link Target', $this->l10n_prefix ),
'link_xfn_mb' => __( 'Link Relationship (XFN)', $this->l10n_prefix ),
'link_adv_mb' => __( 'Link Advanced', $this->l10n_prefix ),
'nav_menu_links' => __( 'Appearance Menu Links', $this->l10n_prefix ),
'nav_menu_links_adv' => __( 'Appearance Menu Link Show Advanced Properties', $this->l10n_prefix ),
'nav_menu_pages' => __( 'Appearance Menu Pages', $this->l10n_prefix ),
'nav_menu_cats' => __( 'Appearance Menu Categories', $this->l10n_prefix ),
'welcome_panel' => __( 'Welcome Panel', $this->l10n_prefix ),
'dash_prim_mb' => __( 'Dashboard Primary', $this->l10n_prefix ),
'dash_sec_mb' => __( 'Dashboard Secondary', $this->l10n_prefix ),
'dash_links_mb' => __( 'Dashboard Incoming Links', $this->l10n_prefix ),
'dash_comments_mb' => __( 'Dashboard Recent Comments', $this->l10n_prefix ),
'dash_right_now_mb' => __( 'Dashboard Right Now', $this->l10n_prefix ),
'dash_drafts_mb' => __( 'Dashboard Recent Drafts', $this->l10n_prefix ),
'dash_quick_mb' => __( 'Dashboard QuickPress', $this->l10n_prefix ),
'dash_net_right_now_mb' => __( 'Network Dashboard Right Now', $this->l10n_prefix ),
'dash_net_prim_mb' => __( 'Network Dashboard Primary', $this->l10n_prefix ),
'dash_net_sec_mb' => __( 'Network Dashboard Secondary', $this->l10n_prefix ),
'dash_net_plugins' => __( 'Network Dashboard Plugins', $this->l10n_prefix ),
'quick_edit_posts' => __( 'Quick Edit Posts', $this->l10n_prefix ),
'quick_edit_pages' => __( 'Quick Edit Pages', $this->l10n_prefix ),
'quick_edit_tag' => __( 'Quick Edit Any Tag', $this->l10n_prefix ),
'quick_edit_post_tag' => __( 'Quick Edit Post Tag', $this->l10n_prefix ),
'quick_edit_category' => __( 'Quick Edit Post Category', $this->l10n_prefix ),
'quick_edit_link_category' => __( 'Quick Edit Link Category', $this->l10n_prefix ),
'quick_edit_comments' => __( 'Quick Edit Comments', $this->l10n_prefix ),
'comment_edit' => __( 'Restrict Comment Editing', $this->l10n_prefix ),
);
?>
<h3><?php _e( 'Meta Boxes', $this->l10n_prefix ); ?></h3>
<table id="menu" class="form-table">
<tr valign="top">
<th scope="row"><?php _e( 'Enable Administration Meta Boxes', $this->l10n_prefix ); ?></th>
<td>
<?php
foreach ( (array) $meta_items as $key => $val ) {
echo "<label><input type='checkbox' name='menu_items[" . $key . "]' value='1'" . ( isset( $meta_perms[$key] ) ? checked( $meta_perms[$key], '1', false ) : '' ) . " /> " . esc_html( $val ) . "</label><br/>";
}
?>
</td>
</tr>
</table>
<?php
}
}
new DS_Meta();
?>