|
1 <?php |
|
2 /** |
|
3 * Plugins List Table class. |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage List_Table |
|
7 * @since 3.1.0 |
|
8 * @access private |
|
9 */ |
|
10 class WP_Plugins_List_Table extends WP_List_Table { |
|
11 |
|
12 function __construct() { |
|
13 global $status, $page; |
|
14 |
|
15 $status = 'all'; |
|
16 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) ) |
|
17 $status = $_REQUEST['plugin_status']; |
|
18 |
|
19 if ( isset($_REQUEST['s']) ) |
|
20 $_SERVER['REQUEST_URI'] = add_query_arg('s', stripslashes($_REQUEST['s']) ); |
|
21 |
|
22 $page = $this->get_pagenum(); |
|
23 |
|
24 parent::__construct( array( |
|
25 'plural' => 'plugins', |
|
26 ) ); |
|
27 } |
|
28 |
|
29 function get_table_classes() { |
|
30 return array( 'widefat', $this->_args['plural'] ); |
|
31 } |
|
32 |
|
33 function ajax_user_can() { |
|
34 if ( is_multisite() ) { |
|
35 $menu_perms = get_site_option( 'menu_items', array() ); |
|
36 |
|
37 if ( empty( $menu_perms['plugins'] ) && ! is_super_admin() ) |
|
38 return false; |
|
39 } |
|
40 |
|
41 return current_user_can('activate_plugins'); |
|
42 } |
|
43 |
|
44 function prepare_items() { |
|
45 global $status, $plugins, $totals, $page, $orderby, $order, $s; |
|
46 |
|
47 wp_reset_vars( array( 'orderby', 'order', 's' ) ); |
|
48 |
|
49 $plugins = array( |
|
50 'all' => apply_filters( 'all_plugins', get_plugins() ), |
|
51 'search' => array(), |
|
52 'active' => array(), |
|
53 'inactive' => array(), |
|
54 'recently_activated' => array(), |
|
55 'upgrade' => array(), |
|
56 'mustuse' => array(), |
|
57 'dropins' => array() |
|
58 ); |
|
59 |
|
60 $screen = get_current_screen(); |
|
61 |
|
62 if ( ! is_multisite() || ( $screen->is_network && current_user_can('manage_network_plugins') ) ) { |
|
63 if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ) |
|
64 $plugins['mustuse'] = get_mu_plugins(); |
|
65 if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) |
|
66 $plugins['dropins'] = get_dropins(); |
|
67 |
|
68 if ( current_user_can( 'update_plugins' ) ) { |
|
69 $current = get_site_transient( 'update_plugins' ); |
|
70 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { |
|
71 if ( isset( $current->response[ $plugin_file ] ) ) { |
|
72 $plugins['all'][ $plugin_file ]['update'] = true; |
|
73 $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ]; |
|
74 } |
|
75 } |
|
76 } |
|
77 } |
|
78 |
|
79 set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), 86400 ); |
|
80 |
|
81 if ( ! $screen->is_network ) { |
|
82 $recently_activated = get_option( 'recently_activated', array() ); |
|
83 |
|
84 $one_week = 7*24*60*60; |
|
85 foreach ( $recently_activated as $key => $time ) |
|
86 if ( $time + $one_week < time() ) |
|
87 unset( $recently_activated[$key] ); |
|
88 update_option( 'recently_activated', $recently_activated ); |
|
89 } |
|
90 |
|
91 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { |
|
92 // Filter into individual sections |
|
93 if ( is_multisite() && ! $screen->is_network && is_network_only_plugin( $plugin_file ) ) { |
|
94 unset( $plugins['all'][ $plugin_file ] ); |
|
95 } elseif ( ! $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) { |
|
96 unset( $plugins['all'][ $plugin_file ] ); |
|
97 } elseif ( ( ! $screen->is_network && is_plugin_active( $plugin_file ) ) |
|
98 || ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) { |
|
99 $plugins['active'][ $plugin_file ] = $plugin_data; |
|
100 } else { |
|
101 if ( !$screen->is_network && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated? |
|
102 $plugins['recently_activated'][ $plugin_file ] = $plugin_data; |
|
103 $plugins['inactive'][ $plugin_file ] = $plugin_data; |
|
104 } |
|
105 } |
|
106 |
|
107 if ( $s ) { |
|
108 $status = 'search'; |
|
109 $plugins['search'] = array_filter( $plugins['all'], array( &$this, '_search_callback' ) ); |
|
110 } |
|
111 |
|
112 $totals = array(); |
|
113 foreach ( $plugins as $type => $list ) |
|
114 $totals[ $type ] = count( $list ); |
|
115 |
|
116 if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) ) |
|
117 $status = 'all'; |
|
118 |
|
119 $this->items = array(); |
|
120 foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) { |
|
121 // Translate, Don't Apply Markup, Sanitize HTML |
|
122 $this->items[$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true ); |
|
123 } |
|
124 |
|
125 $total_this_page = $totals[ $status ]; |
|
126 |
|
127 if ( $orderby ) { |
|
128 $orderby = ucfirst( $orderby ); |
|
129 $order = strtoupper( $order ); |
|
130 |
|
131 uasort( $this->items, array( &$this, '_order_callback' ) ); |
|
132 } |
|
133 |
|
134 $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 ); |
|
135 |
|
136 $start = ( $page - 1 ) * $plugins_per_page; |
|
137 |
|
138 if ( $total_this_page > $plugins_per_page ) |
|
139 $this->items = array_slice( $this->items, $start, $plugins_per_page ); |
|
140 |
|
141 $this->set_pagination_args( array( |
|
142 'total_items' => $total_this_page, |
|
143 'per_page' => $plugins_per_page, |
|
144 ) ); |
|
145 } |
|
146 |
|
147 function _search_callback( $plugin ) { |
|
148 static $term; |
|
149 if ( is_null( $term ) ) |
|
150 $term = stripslashes( $_REQUEST['s'] ); |
|
151 |
|
152 foreach ( $plugin as $value ) |
|
153 if ( stripos( $value, $term ) !== false ) |
|
154 return true; |
|
155 |
|
156 return false; |
|
157 } |
|
158 |
|
159 function _order_callback( $plugin_a, $plugin_b ) { |
|
160 global $orderby, $order; |
|
161 |
|
162 $a = $plugin_a[$orderby]; |
|
163 $b = $plugin_b[$orderby]; |
|
164 |
|
165 if ( $a == $b ) |
|
166 return 0; |
|
167 |
|
168 if ( 'DESC' == $order ) |
|
169 return ( $a < $b ) ? 1 : -1; |
|
170 else |
|
171 return ( $a < $b ) ? -1 : 1; |
|
172 } |
|
173 |
|
174 function no_items() { |
|
175 global $plugins; |
|
176 |
|
177 if ( !empty( $plugins['all'] ) ) |
|
178 _e( 'No plugins found.' ); |
|
179 else |
|
180 _e( 'You do not appear to have any plugins available at this time.' ); |
|
181 } |
|
182 |
|
183 function get_columns() { |
|
184 global $status; |
|
185 |
|
186 return array( |
|
187 'cb' => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '', |
|
188 'name' => __( 'Plugin' ), |
|
189 'description' => __( 'Description' ), |
|
190 ); |
|
191 } |
|
192 |
|
193 function get_sortable_columns() { |
|
194 return array(); |
|
195 } |
|
196 |
|
197 function get_views() { |
|
198 global $totals, $status; |
|
199 |
|
200 $status_links = array(); |
|
201 foreach ( $totals as $type => $count ) { |
|
202 if ( !$count ) |
|
203 continue; |
|
204 |
|
205 switch ( $type ) { |
|
206 case 'all': |
|
207 $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' ); |
|
208 break; |
|
209 case 'active': |
|
210 $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count ); |
|
211 break; |
|
212 case 'recently_activated': |
|
213 $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count ); |
|
214 break; |
|
215 case 'inactive': |
|
216 $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count ); |
|
217 break; |
|
218 case 'mustuse': |
|
219 $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count ); |
|
220 break; |
|
221 case 'dropins': |
|
222 $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count ); |
|
223 break; |
|
224 case 'upgrade': |
|
225 $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count ); |
|
226 break; |
|
227 } |
|
228 |
|
229 if ( 'search' != $type ) { |
|
230 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>", |
|
231 add_query_arg('plugin_status', $type, 'plugins.php'), |
|
232 ( $type == $status ) ? ' class="current"' : '', |
|
233 sprintf( $text, number_format_i18n( $count ) ) |
|
234 ); |
|
235 } |
|
236 } |
|
237 |
|
238 return $status_links; |
|
239 } |
|
240 |
|
241 function get_bulk_actions() { |
|
242 global $status; |
|
243 |
|
244 $actions = array(); |
|
245 |
|
246 $screen = get_current_screen(); |
|
247 |
|
248 if ( 'active' != $status ) |
|
249 $actions['activate-selected'] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' ); |
|
250 |
|
251 if ( 'inactive' != $status && 'recent' != $status ) |
|
252 $actions['deactivate-selected'] = $screen->is_network ? __( 'Network Deactivate' ) : __( 'Deactivate' ); |
|
253 |
|
254 if ( !is_multisite() || $screen->is_network ) { |
|
255 if ( current_user_can( 'update_plugins' ) ) |
|
256 $actions['update-selected'] = __( 'Update' ); |
|
257 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) |
|
258 $actions['delete-selected'] = __( 'Delete' ); |
|
259 } |
|
260 |
|
261 return $actions; |
|
262 } |
|
263 |
|
264 function bulk_actions( $which ) { |
|
265 global $status; |
|
266 |
|
267 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) |
|
268 return; |
|
269 |
|
270 parent::bulk_actions( $which ); |
|
271 } |
|
272 |
|
273 function extra_tablenav( $which ) { |
|
274 global $status; |
|
275 |
|
276 if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) ) |
|
277 return; |
|
278 |
|
279 echo '<div class="alignleft actions">'; |
|
280 |
|
281 $screen = get_current_screen(); |
|
282 |
|
283 if ( ! $screen->is_network && 'recently_activated' == $status ) |
|
284 submit_button( __( 'Clear List' ), 'secondary', 'clear-recent-list', false ); |
|
285 elseif ( 'top' == $which && 'mustuse' == $status ) |
|
286 echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>'; |
|
287 elseif ( 'top' == $which && 'dropins' == $status ) |
|
288 echo '<p>' . sprintf( __( 'Drop-ins are advanced plugins in the <code>%s</code> directory that replace WordPress functionality when present.' ), str_replace( ABSPATH, '', WP_CONTENT_DIR ) ) . '</p>'; |
|
289 |
|
290 echo '</div>'; |
|
291 } |
|
292 |
|
293 function current_action() { |
|
294 if ( isset($_POST['clear-recent-list']) ) |
|
295 return 'clear-recent-list'; |
|
296 |
|
297 return parent::current_action(); |
|
298 } |
|
299 |
|
300 function display_rows() { |
|
301 global $status; |
|
302 |
|
303 $screen = get_current_screen(); |
|
304 |
|
305 if ( is_multisite() && !$screen->is_network && in_array( $status, array( 'mustuse', 'dropins' ) ) ) |
|
306 return; |
|
307 |
|
308 foreach ( $this->items as $plugin_file => $plugin_data ) |
|
309 $this->single_row( $plugin_file, $plugin_data ); |
|
310 } |
|
311 |
|
312 function single_row( $plugin_file, $plugin_data ) { |
|
313 global $status, $page, $s, $totals; |
|
314 |
|
315 $context = $status; |
|
316 |
|
317 $screen = get_current_screen(); |
|
318 |
|
319 // preorder |
|
320 $actions = array( |
|
321 'deactivate' => '', |
|
322 'activate' => '', |
|
323 'edit' => '', |
|
324 'delete' => '', |
|
325 ); |
|
326 |
|
327 if ( 'mustuse' == $context ) { |
|
328 $is_active = true; |
|
329 } elseif ( 'dropins' == $context ) { |
|
330 $dropins = _get_dropins(); |
|
331 $plugin_name = $plugin_file; |
|
332 if ( $plugin_file != $plugin_data['Name'] ) |
|
333 $plugin_name .= '<br/>' . $plugin_data['Name']; |
|
334 if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant |
|
335 $is_active = true; |
|
336 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; |
|
337 } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true |
|
338 $is_active = true; |
|
339 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; |
|
340 } else { |
|
341 $is_active = false; |
|
342 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="attention">' . __('Inactive:') . '</span></strong> ' . sprintf( __( 'Requires <code>%s</code> in <code>wp-config.php</code>.' ), "define('" . $dropins[ $plugin_file ][1] . "', true);" ) . '</p>'; |
|
343 } |
|
344 if ( $plugin_data['Description'] ) |
|
345 $description .= '<p>' . $plugin_data['Description'] . '</p>'; |
|
346 } else { |
|
347 if ( $screen->is_network ) |
|
348 $is_active = is_plugin_active_for_network( $plugin_file ); |
|
349 else |
|
350 $is_active = is_plugin_active( $plugin_file ); |
|
351 |
|
352 if ( $screen->is_network ) { |
|
353 if ( $is_active ) { |
|
354 if ( current_user_can( 'manage_network_plugins' ) ) |
|
355 $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>'; |
|
356 } else { |
|
357 if ( current_user_can( 'manage_network_plugins' ) ) |
|
358 $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>'; |
|
359 if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) |
|
360 $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; |
|
361 } |
|
362 } else { |
|
363 if ( $is_active ) { |
|
364 $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Deactivate') . '</a>'; |
|
365 } else { |
|
366 $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>'; |
|
367 |
|
368 if ( ! is_multisite() && current_user_can('delete_plugins') ) |
|
369 $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; |
|
370 } // end if $is_active |
|
371 } // end if $screen->is_network |
|
372 |
|
373 if ( ( ! is_multisite() || $screen->is_network ) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) ) |
|
374 $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . esc_attr__('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>'; |
|
375 } // end if $context |
|
376 |
|
377 $prefix = $screen->is_network ? 'network_admin_' : ''; |
|
378 $actions = apply_filters( $prefix . 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context ); |
|
379 $actions = apply_filters( $prefix . "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context ); |
|
380 |
|
381 $class = $is_active ? 'active' : 'inactive'; |
|
382 $checkbox_id = "checkbox_" . md5($plugin_data['Name']); |
|
383 $checkbox = in_array( $status, array( 'mustuse', 'dropins' ) ) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $plugin_data['Name'] . "</label>"; |
|
384 if ( 'dropins' != $context ) { |
|
385 $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : ' ' ) . '</p>'; |
|
386 $plugin_name = $plugin_data['Name']; |
|
387 } |
|
388 |
|
389 $id = sanitize_title( $plugin_name ); |
|
390 if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) ) |
|
391 $class .= ' update'; |
|
392 |
|
393 echo "<tr id='$id' class='$class'>"; |
|
394 |
|
395 list( $columns, $hidden ) = $this->get_column_info(); |
|
396 |
|
397 foreach ( $columns as $column_name => $column_display_name ) { |
|
398 $style = ''; |
|
399 if ( in_array( $column_name, $hidden ) ) |
|
400 $style = ' style="display:none;"'; |
|
401 |
|
402 switch ( $column_name ) { |
|
403 case 'cb': |
|
404 echo "<th scope='row' class='check-column'>$checkbox</th>"; |
|
405 break; |
|
406 case 'name': |
|
407 echo "<td class='plugin-title'$style><strong>$plugin_name</strong>"; |
|
408 echo $this->row_actions( $actions, true ); |
|
409 echo "</td>"; |
|
410 break; |
|
411 case 'description': |
|
412 echo "<td class='column-description desc'$style> |
|
413 <div class='plugin-description'>$description</div> |
|
414 <div class='$class second plugin-version-author-uri'>"; |
|
415 |
|
416 $plugin_meta = array(); |
|
417 if ( !empty( $plugin_data['Version'] ) ) |
|
418 $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); |
|
419 if ( !empty( $plugin_data['Author'] ) ) { |
|
420 $author = $plugin_data['Author']; |
|
421 if ( !empty( $plugin_data['AuthorURI'] ) ) |
|
422 $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>'; |
|
423 $plugin_meta[] = sprintf( __( 'By %s' ), $author ); |
|
424 } |
|
425 if ( ! empty( $plugin_data['PluginURI'] ) ) |
|
426 $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin site' ) . '">' . __( 'Visit plugin site' ) . '</a>'; |
|
427 |
|
428 $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status ); |
|
429 echo implode( ' | ', $plugin_meta ); |
|
430 |
|
431 echo "</div></td>"; |
|
432 break; |
|
433 default: |
|
434 echo "<td class='$column_name column-$column_name'$style>"; |
|
435 do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data ); |
|
436 echo "</td>"; |
|
437 } |
|
438 } |
|
439 |
|
440 echo "</tr>"; |
|
441 |
|
442 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status ); |
|
443 do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status ); |
|
444 } |
|
445 } |