3 * Plugins List Table class.
6 * @subpackage List_Table
10 class WP_Plugins_List_Table extends WP_List_Table {
12 function __construct() {
13 global $status, $page;
16 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'network', 'mustuse', 'dropins', 'search' ) ) )
17 $status = $_REQUEST['plugin_status'];
19 if ( isset($_REQUEST['s']) )
20 $_SERVER['REQUEST_URI'] = add_query_arg('s', stripslashes($_REQUEST['s']) );
22 $page = $this->get_pagenum();
24 parent::__construct( array(
25 'plural' => 'plugins',
29 function get_table_classes() {
30 return array( 'widefat', $this->_args['plural'] );
33 function ajax_user_can() {
34 if ( is_multisite() ) {
35 $menu_perms = get_site_option( 'menu_items', array() );
37 if ( empty( $menu_perms['plugins'] ) && ! is_super_admin() )
41 return current_user_can('activate_plugins');
44 function prepare_items() {
45 global $status, $plugins, $totals, $page, $orderby, $order, $s;
47 wp_reset_vars( array( 'orderby', 'order', 's' ) );
50 'all' => apply_filters( 'all_plugins', get_plugins() ),
53 'inactive' => array(),
54 'recently_activated' => array(),
60 $screen = get_current_screen();
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();
68 $current = get_site_transient( 'update_plugins' );
69 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
70 if ( isset( $current->response[ $plugin_file ] ) )
71 $plugins['upgrade'][ $plugin_file ] = $plugin_data;
75 set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), 86400 );
77 $recently_activated = get_option( 'recently_activated', array() );
79 $one_week = 7*24*60*60;
80 foreach ( $recently_activated as $key => $time )
81 if ( $time + $one_week < time() )
82 unset( $recently_activated[$key] );
83 update_option( 'recently_activated', $recently_activated );
85 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
86 // Filter into individual sections
87 if ( is_multisite() && is_network_only_plugin( $plugin_file ) && !$screen->is_network ) {
88 unset( $plugins['all'][ $plugin_file] );
89 } elseif ( is_plugin_active_for_network($plugin_file) && !$screen->is_network ) {
90 unset( $plugins['all'][ $plugin_file ] );
91 } elseif ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) {
92 $plugins['network'][ $plugin_file ] = $plugin_data;
93 } elseif ( ( !$screen->is_network && is_plugin_active( $plugin_file ) )
94 || ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) {
95 $plugins['active'][ $plugin_file ] = $plugin_data;
97 if ( !$screen->is_network && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
98 $plugins['recently_activated'][ $plugin_file ] = $plugin_data;
99 $plugins['inactive'][ $plugin_file ] = $plugin_data;
103 if ( !current_user_can( 'update_plugins' ) )
104 $plugins['upgrade'] = array();
108 $plugins['search'] = array_filter( $plugins['all'], array( &$this, '_search_callback' ) );
112 foreach ( $plugins as $type => $list )
113 $totals[ $type ] = count( $list );
115 if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
118 $this->items = array();
119 foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) {
120 // Translate, Don't Apply Markup, Sanitize HTML
121 $this->items[$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
124 $total_this_page = $totals[ $status ];
127 $orderby = ucfirst( $orderby );
128 $order = strtoupper( $order );
130 uasort( $this->items, array( &$this, '_order_callback' ) );
133 $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 );
135 $start = ( $page - 1 ) * $plugins_per_page;
137 if ( $total_this_page > $plugins_per_page )
138 $this->items = array_slice( $this->items, $start, $plugins_per_page );
140 $this->set_pagination_args( array(
141 'total_items' => $total_this_page,
142 'per_page' => $plugins_per_page,
146 function _search_callback( $plugin ) {
148 if ( is_null( $term ) )
149 $term = stripslashes( $_REQUEST['s'] );
151 foreach ( $plugin as $value )
152 if ( stripos( $value, $term ) !== false )
158 function _order_callback( $plugin_a, $plugin_b ) {
159 global $orderby, $order;
161 $a = $plugin_a[$orderby];
162 $b = $plugin_b[$orderby];
167 if ( 'DESC' == $order )
168 return ( $a < $b ) ? 1 : -1;
170 return ( $a < $b ) ? -1 : 1;
173 function no_items() {
176 if ( !empty( $plugins['all'] ) )
177 _e( 'No plugins found.' );
179 _e( 'You do not appear to have any plugins available at this time.' );
182 function get_columns() {
186 'cb' => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
187 'name' => __( 'Plugin' ),
188 'description' => __( 'Description' ),
192 function get_sortable_columns() {
196 function get_views() {
197 global $totals, $status;
199 $status_links = array();
200 foreach ( $totals as $type => $count ) {
206 $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' );
209 $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count );
211 case 'recently_activated':
212 $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count );
215 $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
218 $text = _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $count );
221 $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
224 $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count );
227 $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
231 if ( 'search' != $type ) {
232 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
233 add_query_arg('plugin_status', $type, 'plugins.php'),
234 ( $type == $status ) ? ' class="current"' : '',
235 sprintf( $text, number_format_i18n( $count ) )
240 return $status_links;
243 function get_bulk_actions() {
248 $screen = get_current_screen();
250 if ( 'active' != $status ) {
251 $action = $screen->is_network ? 'network-activate-selected' : 'activate-selected';
252 $actions[ $action ] = __( 'Activate' );
255 if ( 'inactive' != $status && 'recent' != $status )
256 $actions['deactivate-selected'] = __( 'Deactivate' );
258 if ( !is_multisite() || $screen->is_network ) {
259 if ( current_user_can( 'update_plugins' ) )
260 $actions['update-selected'] = __( 'Update' );
261 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
262 $actions['delete-selected'] = __( 'Delete' );
268 function bulk_actions( $which ) {
271 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) )
274 parent::bulk_actions( $which );
277 function extra_tablenav( $which ) {
280 if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) )
283 echo '<div class="alignleft actions">';
285 if ( 'recently_activated' == $status )
286 submit_button( __( 'Clear List' ), 'secondary', 'clear-recent-list', false );
287 elseif ( 'top' == $which && 'mustuse' == $status )
288 echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>';
289 elseif ( 'top' == $which && 'dropins' == $status )
290 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>';
295 function current_action() {
296 if ( isset($_POST['clear-recent-list']) )
297 return 'clear-recent-list';
299 return parent::current_action();
302 function display_rows() {
305 $screen = get_current_screen();
307 if ( is_multisite() && !$screen->is_network && in_array( $status, array( 'mustuse', 'dropins' ) ) )
310 foreach ( $this->items as $plugin_file => $plugin_data )
311 $this->single_row( $plugin_file, $plugin_data );
314 function single_row( $plugin_file, $plugin_data ) {
315 global $status, $page, $s;
319 $screen = get_current_screen();
323 'network_deactivate' => '', 'deactivate' => '',
324 'network_only' => '', 'activate' => '',
325 'network_activate' => '',
330 if ( 'mustuse' == $context ) {
332 } elseif ( 'dropins' == $context ) {
333 $dropins = _get_dropins();
334 $plugin_name = $plugin_file;
335 if ( $plugin_file != $plugin_data['Name'] )
336 $plugin_name .= '<br/>' . $plugin_data['Name'];
337 if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
339 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
340 } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
342 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
345 $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>';
347 if ( $plugin_data['Description'] )
348 $description .= '<p>' . $plugin_data['Description'] . '</p>';
350 $is_active_for_network = is_plugin_active_for_network($plugin_file);
351 if ( $screen->is_network )
352 $is_active = $is_active_for_network;
354 $is_active = is_plugin_active( $plugin_file );
356 if ( $is_active_for_network && !is_super_admin() && !$screen->is_network )
359 if ( $screen->is_network ) {
360 if ( $is_active_for_network ) {
361 if ( current_user_can( 'manage_network_plugins' ) )
362 $actions['network_deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
364 if ( current_user_can( 'manage_network_plugins' ) )
365 $actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&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>';
366 if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) )
367 $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>';
371 $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>';
373 $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>';
375 if ( ! is_multisite() && current_user_can('delete_plugins') )
376 $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>';
377 } // end if $is_active
378 } // end if $screen->is_network
380 if ( ( ! is_multisite() || $screen->is_network ) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
381 $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . esc_attr__('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
384 $prefix = $screen->is_network ? 'network_admin_' : '';
385 $actions = apply_filters( $prefix . 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
386 $actions = apply_filters( $prefix . "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
388 $class = $is_active ? 'active' : 'inactive';
389 $checkbox_id = "checkbox_" . md5($plugin_data['Name']);
390 $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>";
391 if ( 'dropins' != $context ) {
392 $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : ' ' ) . '</p>';
393 $plugin_name = $plugin_data['Name'];
396 $id = sanitize_title( $plugin_name );
398 echo "<tr id='$id' class='$class'>";
400 list( $columns, $hidden ) = $this->get_column_info();
402 foreach ( $columns as $column_name => $column_display_name ) {
404 if ( in_array( $column_name, $hidden ) )
405 $style = ' style="display:none;"';
407 switch ( $column_name ) {
409 echo "<th scope='row' class='check-column'>$checkbox</th>";
412 echo "<td class='plugin-title'$style><strong>$plugin_name</strong>";
413 echo $this->row_actions( $actions, true );
417 echo "<td class='column-description desc'$style>
418 <div class='plugin-description'>$description</div>
419 <div class='$class second plugin-version-author-uri'>";
421 $plugin_meta = array();
422 if ( !empty( $plugin_data['Version'] ) )
423 $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
424 if ( !empty( $plugin_data['Author'] ) ) {
425 $author = $plugin_data['Author'];
426 if ( !empty( $plugin_data['AuthorURI'] ) )
427 $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
428 $plugin_meta[] = sprintf( __( 'By %s' ), $author );
430 if ( ! empty( $plugin_data['PluginURI'] ) )
431 $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin site' ) . '">' . __( 'Visit plugin site' ) . '</a>';
433 $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
434 echo implode( ' | ', $plugin_meta );
439 echo "<td class='$column_name column-$column_name'$style>";
440 do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
447 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
448 do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status );