-
Notifications
You must be signed in to change notification settings - Fork 0
/
blue-network-plugins.php
323 lines (252 loc) · 9.22 KB
/
blue-network-plugins.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
<?php
/*
Plugin Name: Blue Network Plugins!
Description: Separates active network plugins from inactive ones on the Wordpress network plugins page. Requires Wordpress Multisite.
Author: r-a-y
Version: 1.1
Network: true
Author URI: http://buddypress.org/community/members/r-a-y
License: CC-GNU-GPL http://creativecommons.org/licenses/GPL/2.0/
Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6U36PVEZB4BAE
*/
/**
* Blue Network Plugins
*
* @package BNP
* @subpackage Core
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
global $wp_version;
// let's stop this plugin from running if multisite isn't enabled and WP < 3.0
if( !is_multisite() && version_compare( $wp_version, '3.0', '<' ) )
return false;
/**
* Class: Blue Network Plugins
*
* @package BNP
* @subpackage Classes
* @since 1.1
*/
class Blue_Network_Plugins {
/**
* Initializes the class when called upon.
* Yeah, I know it's named funny. Why? See line 177 ;)
*/
function blue() {
/* filters **************************************************************/
// filter network plugins from entire plugins list
add_filter( 'all_plugins', array( &$this, 'exclude_network_plugins' ) );
// add extra action links for our plugin
add_filter( 'network_admin_plugin_action_links',array( &$this, 'add_plugin_action_links' ), 10, 2 );
// do not display network plugins alongside site plugins in sub-site admin
add_filter( 'show_network_active_plugins', '__return_false' );
/* actions **************************************************************/
// localization
add_action( 'admin_init', array( &$this, 'translate' ) );
// that funky pale blue color you love from WPMU
// let's only add the CSS on the plugins page
add_action( 'admin_head-plugins.php', array( &$this, 'css' ), 99 );
// add custom network plugins table before the regular plugins table
add_action( 'pre_current_active_plugins', array( &$this, 'display' ) );
}
/**
* Filter network plugins from entire plugins list
*/
function exclude_network_plugins() {
$all_plugins = get_plugins();
$network_plugins = ray_get_network_plugins_only();
return array_diff_key( $all_plugins, $network_plugins );
}
/**
* CSS on the plugins page
*/
function css() {
?>
<style type="text/css">
#network-plugins tr.active th, #network-plugins tr.active td {background-color:#EEF2FF !important;}
#network-plugins .check-column input, h2 .subtitle {display:none;}
p.search-box {margin-top:5px;}
</style>
<?php
}
/**
* Display our modified plugins table above the regular plugin table.
* Accomodates both WP 3.0 and 3.1+.
*
* @uses Network_Plugins_List_Table
*/
function display() {
global $wp_version, $s;
if ( current_user_can( 'manage_network_plugins' ) ) :
echo '<h3>' . __( 'Currently Active Network Plugins', 'bnp' ) . '</h3>';
echo '<div id="network-plugins">';
// WP 3.1+
if ( version_compare( $wp_version, '3.1', '>=' ) ) :
$screen = get_current_screen();
// display this on the network admin plugins page
if ( $screen->is_network ) :
echo '<p>' . __( 'Plugins that appear in the list below are activated on all sites across this installation.', 'bnp' ) .'</p>';
// WP 3.1 introduces a new class to output plugins
// Network_Plugins_List_Table extends WP_Plugins_List_Table
$wp_list_table = new Network_Plugins_List_Table;
$wp_list_table->prepare_items();
$wp_list_table->display();
// display this on the site admin plugins page
else :
echo '<p>' . sprintf( __( 'You can <a href="%s">manage your network plugins here</a>.', 'bnp' ), network_admin_url( 'plugins.php' ) ) . '</p>';
echo '<h3>' . sprintf( __( 'Plugins on %s', 'bnp' ), get_bloginfo( 'name' ) ) . '</h3>';
endif;
// WP 3.0 branch
// print_plugins_table() doesn't exist in WP 3.1+
else :
echo '<p>' . __( 'Plugins that appear in the list below are activated on all sites across this installation.', 'bnp' ) .'</p>';
print_plugins_table( ray_get_network_plugins_only() );
echo '<p>' . __( 'Plugins that are enabled on the entire network can only be disabled by a super administrator.', 'bnp' ) .'</p>';
endif;
echo '</div>';
// if a search is being made, let's reposition the search heading here
if ( $s )
printf( '<h4>' . __( 'Search results for “%s”', 'bnp' ) . '</h3>', esc_html( $s ) );
endif;
}
/**
* This method works even if we shove the plugin in /mu-plugins/.
*/
function translate() {
$locale = get_locale();
$mofile = dirname(__FILE__) . "/lang/bnp-$locale.mo";
if ( file_exists( $mofile ) )
load_textdomain( 'bnp', $mofile );
}
/**
* Add extra links for BNP on the WP Admin plugins page
*
* @param array $links Plugin action links
* @param string $file A plugin's loader base filename
*/
function add_plugin_action_links( $links, $file ) {
// Do not do anything for other plugins
if ( strrpos( 'blue-network-plugins.php', $file ) === false )
return $links;
// Donate link
$donate = '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6U36PVEZB4BAE" target="_blank" title="So you\'re using this plugin, help support this plugin by donating any amount you wish. Thanks for reading! :)" style="font-weight:bold; color:#D54E21">Donate!</a>';
array_unshift( $links, $donate );
return $links;
}
}
// I'm blue, dah bah dee, dah bah dah!
$eiffel_65 = new Blue_Network_Plugins;
$eiffel_65->blue();
/* FUNCTIONS *************************************************************/
/**
* Helper function to get network plugins only
*
* @since 1.1
*/
function ray_get_network_plugins_only() {
$all_plugins = get_plugins();
$network_plugins = array();
foreach ( (array) $all_plugins as $plugin_file => $plugin_data) {
if ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) {
unset( $all_plugins[ $plugin_file ] );
continue;
} elseif ( is_plugin_active_for_network($plugin_file) ) {
$network_plugins[ $plugin_file ] = $plugin_data;
}
}
return apply_filters( 'network_plugins_only', $network_plugins );
}
/* CLASSES **************************************************************/
// WP 3.1+ support
if ( version_compare( $wp_version, '3.1', '>=' ) ) :
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
require_once( ABSPATH . 'wp-admin/includes/class-wp-plugins-list-table.php' );
/**
* Class: Network_Plugins_List_Table
*
* Extends and manipulates {@link WP_Plugins_List_Table class} to
* display only network plugins.
*
* @package BNP
* @subpackage Classes
* @see Blue_Network_Plugins::display()
* @since 1.1
*/
class Network_Plugins_List_Table extends WP_Plugins_List_Table {
/**
* Overrides {@link WP_Plugins_List_Table::prepare_items()}
*/
function prepare_items() {
global $status, $page, $orderby, $order, $s;
wp_reset_vars( array( 'orderby', 'order' ) );
$plugins = array(
'all' => ray_get_network_plugins_only(),
'search' => array(),
'active' => array(),
'inactive' => array(),
'recently_activated' => array(),
'upgrade' => array(),
'mustuse' => array(),
'dropins' => array()
);
$screen = $this->screen;
if ( ! is_multisite() || ( $screen->in_admin( 'network' ) && current_user_can( 'manage_network_plugins' ) ) ) {
if ( current_user_can( 'update_plugins' ) ) {
$current = get_site_transient( 'update_plugins' );
foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
if ( isset( $current->response[ $plugin_file ] ) ) {
$plugins['all'][ $plugin_file ]['update'] = true;
$plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
}
}
}
}
set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS );
$recently_activated = get_site_option( 'recently_activated', array() );
foreach ( $recently_activated as $key => $time ) {
if ( $time + WEEK_IN_SECONDS < time() ) {
unset( $recently_activated[$key] );
}
}
update_site_option( 'recently_activated', $recently_activated );
if ( strlen( $s ) ) {
$status = 'search';
$plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) );
}
$totals = array();
foreach ( $plugins as $type => $list )
$totals[ $type ] = count( $list );
if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
$status = 'all';
$this->items = array();
foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) {
// Translate, Don't Apply Markup, Sanitize HTML
$this->items[$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
}
$total_this_page = $totals[ $status ];
if ( ! $orderby ) {
$orderby = 'Name';
} else {
$orderby = ucfirst( $orderby );
}
$order = strtoupper( $order );
uasort( $this->items, array( $this, '_order_callback' ) );
}
/**
* Overrides {@link WP_Plugins_List_Table::bulk_actions()}
* to return nothing since this isn't applicable for our needs
*/
function bulk_actions( $which = '' ) {
return;
}
/**
* Overrides {@link WP_Plugins_List_Table::display_tablenav()}
* to return nothing since this isn't applicable for our needs
*/
function display_tablenav( $which ) {
return;
}
}
endif;
?>