3 * Plugins List Table class.
6 * @subpackage List_Table
10 class WP_Plugins_List_Table extends WP_List_Table {
12 function __construct( $args = array() ) {
13 global $status, $page;
15 parent::__construct( array(
16 'plural' => 'plugins',
17 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
21 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) )
22 $status = $_REQUEST['plugin_status'];
24 if ( isset($_REQUEST['s']) )
25 $_SERVER['REQUEST_URI'] = add_query_arg('s', wp_unslash($_REQUEST['s']) );
27 $page = $this->get_pagenum();
30 function get_table_classes() {
31 return array( 'widefat', $this->_args['plural'] );
34 function ajax_user_can() {
35 return current_user_can('activate_plugins');
38 function prepare_items() {
39 global $status, $plugins, $totals, $page, $orderby, $order, $s;
41 wp_reset_vars( array( 'orderby', 'order', 's' ) );
44 * Filter the full array of plugins to list in the Plugins list table.
50 * @param array $plugins An array of plugins to display in the list table.
53 'all' => apply_filters( 'all_plugins', get_plugins() ),
56 'inactive' => array(),
57 'recently_activated' => array(),
63 $screen = $this->screen;
65 if ( ! is_multisite() || ( $screen->in_admin( 'network' ) && current_user_can( 'manage_network_plugins' ) ) ) {
68 * Filter whether to display the advanced plugins list table.
70 * There are two types of advanced plugins - must-use and drop-ins -
71 * which can be used in a single site or Multisite network.
73 * The $type parameter allows you to differentiate between the type of advanced
74 * plugins to filter the display of. Contexts include 'mustuse' and 'dropins'.
78 * @param bool $show Whether to show the advanced plugins for the specified
79 * plugin type. Default true.
80 * @param string $type The plugin type. Accepts 'mustuse', 'dropins'.
82 if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ) {
83 $plugins['mustuse'] = get_mu_plugins();
86 /** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */
87 if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
88 $plugins['dropins'] = get_dropins();
90 if ( current_user_can( 'update_plugins' ) ) {
91 $current = get_site_transient( 'update_plugins' );
92 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
93 if ( isset( $current->response[ $plugin_file ] ) ) {
94 $plugins['all'][ $plugin_file ]['update'] = true;
95 $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
101 set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS );
103 if ( ! $screen->in_admin( 'network' ) ) {
104 $recently_activated = get_option( 'recently_activated', array() );
106 foreach ( $recently_activated as $key => $time )
107 if ( $time + WEEK_IN_SECONDS < time() )
108 unset( $recently_activated[$key] );
109 update_option( 'recently_activated', $recently_activated );
112 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
113 // Filter into individual sections
114 if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) && ! is_plugin_active( $plugin_file ) ) {
115 // On the non-network screen, filter out network-only plugins as long as they're not individually activated
116 unset( $plugins['all'][ $plugin_file ] );
117 } elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) {
118 // On the non-network screen, filter out network activated plugins
119 unset( $plugins['all'][ $plugin_file ] );
120 } elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) )
121 || ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) {
122 // On the non-network screen, populate the active list with plugins that are individually activated
123 // On the network-admin screen, populate the active list with plugins that are network activated
124 $plugins['active'][ $plugin_file ] = $plugin_data;
126 if ( ! $screen->in_admin( 'network' ) && isset( $recently_activated[ $plugin_file ] ) ) {
127 // On the non-network screen, populate the recently activated list with plugins that have been recently activated
128 $plugins['recently_activated'][ $plugin_file ] = $plugin_data;
130 // Populate the inactive list with plugins that aren't activated
131 $plugins['inactive'][ $plugin_file ] = $plugin_data;
137 $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) );
141 foreach ( $plugins as $type => $list )
142 $totals[ $type ] = count( $list );
144 if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
147 $this->items = array();
148 foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) {
149 // Translate, Don't Apply Markup, Sanitize HTML
150 $this->items[$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
153 $total_this_page = $totals[ $status ];
156 $orderby = ucfirst( $orderby );
157 $order = strtoupper( $order );
159 uasort( $this->items, array( $this, '_order_callback' ) );
162 $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 );
164 $start = ( $page - 1 ) * $plugins_per_page;
166 if ( $total_this_page > $plugins_per_page )
167 $this->items = array_slice( $this->items, $start, $plugins_per_page );
169 $this->set_pagination_args( array(
170 'total_items' => $total_this_page,
171 'per_page' => $plugins_per_page,
175 function _search_callback( $plugin ) {
177 if ( is_null( $term ) )
178 $term = wp_unslash( $_REQUEST['s'] );
180 foreach ( $plugin as $value ) {
181 if ( false !== stripos( strip_tags( $value ), $term ) ) {
189 function _order_callback( $plugin_a, $plugin_b ) {
190 global $orderby, $order;
192 $a = $plugin_a[$orderby];
193 $b = $plugin_b[$orderby];
198 if ( 'DESC' == $order )
199 return ( $a < $b ) ? 1 : -1;
201 return ( $a < $b ) ? -1 : 1;
204 function no_items() {
207 if ( !empty( $plugins['all'] ) )
208 _e( 'No plugins found.' );
210 _e( 'You do not appear to have any plugins available at this time.' );
213 function get_columns() {
217 'cb' => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
218 'name' => __( 'Plugin' ),
219 'description' => __( 'Description' ),
223 function get_sortable_columns() {
227 function get_views() {
228 global $totals, $status;
230 $status_links = array();
231 foreach ( $totals as $type => $count ) {
237 $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' );
240 $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count );
242 case 'recently_activated':
243 $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count );
246 $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
249 $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
252 $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count );
255 $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
259 if ( 'search' != $type ) {
260 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
261 add_query_arg('plugin_status', $type, 'plugins.php'),
262 ( $type == $status ) ? ' class="current"' : '',
263 sprintf( $text, number_format_i18n( $count ) )
268 return $status_links;
271 function get_bulk_actions() {
276 if ( 'active' != $status )
277 $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' );
279 if ( 'inactive' != $status && 'recent' != $status )
280 $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' );
282 if ( !is_multisite() || $this->screen->in_admin( 'network' ) ) {
283 if ( current_user_can( 'update_plugins' ) )
284 $actions['update-selected'] = __( 'Update' );
285 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
286 $actions['delete-selected'] = __( 'Delete' );
292 function bulk_actions() {
295 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) )
298 parent::bulk_actions();
301 function extra_tablenav( $which ) {
304 if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) )
307 echo '<div class="alignleft actions">';
309 if ( ! $this->screen->in_admin( 'network' ) && 'recently_activated' == $status )
310 submit_button( __( 'Clear List' ), 'button', 'clear-recent-list', false );
311 elseif ( 'top' == $which && 'mustuse' == $status )
312 echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>';
313 elseif ( 'top' == $which && 'dropins' == $status )
314 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>';
319 function current_action() {
320 if ( isset($_POST['clear-recent-list']) )
321 return 'clear-recent-list';
323 return parent::current_action();
326 function display_rows() {
329 if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) )
332 foreach ( $this->items as $plugin_file => $plugin_data )
333 $this->single_row( array( $plugin_file, $plugin_data ) );
336 function single_row( $item ) {
337 global $status, $page, $s, $totals;
339 list( $plugin_file, $plugin_data ) = $item;
341 $screen = $this->screen;
351 if ( 'mustuse' == $context ) {
353 } elseif ( 'dropins' == $context ) {
354 $dropins = _get_dropins();
355 $plugin_name = $plugin_file;
356 if ( $plugin_file != $plugin_data['Name'] )
357 $plugin_name .= '<br/>' . $plugin_data['Name'];
358 if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
360 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
361 } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
363 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
366 $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>';
368 if ( $plugin_data['Description'] )
369 $description .= '<p>' . $plugin_data['Description'] . '</p>';
371 if ( $screen->in_admin( 'network' ) )
372 $is_active = is_plugin_active_for_network( $plugin_file );
374 $is_active = is_plugin_active( $plugin_file );
376 if ( $screen->in_admin( 'network' ) ) {
378 if ( current_user_can( 'manage_network_plugins' ) )
379 $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>';
381 if ( current_user_can( 'manage_network_plugins' ) )
382 $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>';
383 if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) )
384 $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>';
388 $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>';
390 $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>';
392 if ( ! is_multisite() && current_user_can('delete_plugins') )
393 $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>';
394 } // end if $is_active
395 } // end if $screen->in_admin( 'network' )
397 if ( ( ! is_multisite() || $screen->in_admin( 'network' ) ) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
398 $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . esc_attr__('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
401 $prefix = $screen->in_admin( 'network' ) ? 'network_admin_' : '';
404 * Filter the action links displayed for each plugin in the Plugins list table.
406 * The dynamic portion of the hook name, $prefix, refers to the context the
407 * action links are displayed in. The 'network_admin_' prefix is used if the
408 * current screen is the Network plugins list table. The prefix is empty ('')
409 * if the current screen is the site plugins list table.
411 * The default action links for the Network plugins list table include
412 * 'Network Activate', 'Network Deactivate', 'Edit', and 'Delete'.
414 * The default action links for the site plugins list table include
415 * 'Activate', 'Deactivate', and 'Edit', for a network site, and
416 * 'Activate', 'Deactivate', 'Edit', and 'Delete' for a single site.
420 * @param array $actions An array of plugin action links.
421 * @param string $plugin_file Path to the plugin file.
422 * @param array $plugin_data An array of plugin data.
423 * @param string $context The plugin context. Defaults are 'All', 'Active',
424 * 'Inactive', 'Recently Activated', 'Upgrade',
425 * 'Must-Use', 'Drop-ins', 'Search'.
427 $actions = apply_filters( $prefix . 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
430 * Filter the list of action links displayed for a specific plugin.
432 * The first dynamic portion of the hook name, $prefix, refers to the context
433 * the action links are displayed in. The 'network_admin_' prefix is used if the
434 * current screen is the Network plugins list table. The prefix is empty ('')
435 * if the current screen is the site plugins list table.
437 * The second dynamic portion of the hook name, $plugin_file, refers to the path
438 * to the plugin file, relative to the plugins directory.
442 * @param array $actions An array of plugin action links.
443 * @param string $plugin_file Path to the plugin file.
444 * @param array $plugin_data An array of plugin data.
445 * @param string $context The plugin context. Defaults are 'All', 'Active',
446 * 'Inactive', 'Recently Activated', 'Upgrade',
447 * 'Must-Use', 'Drop-ins', 'Search'.
449 $actions = apply_filters( $prefix . "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
451 $class = $is_active ? 'active' : 'inactive';
452 $checkbox_id = "checkbox_" . md5($plugin_data['Name']);
453 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
456 $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . "</label>"
457 . "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' />";
459 if ( 'dropins' != $context ) {
460 $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : ' ' ) . '</p>';
461 $plugin_name = $plugin_data['Name'];
464 $id = sanitize_title( $plugin_name );
465 if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) )
468 echo "<tr id='$id' class='$class'>";
470 list( $columns, $hidden ) = $this->get_column_info();
472 foreach ( $columns as $column_name => $column_display_name ) {
474 if ( in_array( $column_name, $hidden ) )
475 $style = ' style="display:none;"';
477 switch ( $column_name ) {
479 echo "<th scope='row' class='check-column'>$checkbox</th>";
482 echo "<td class='plugin-title'$style><strong>$plugin_name</strong>";
483 echo $this->row_actions( $actions, true );
487 echo "<td class='column-description desc'$style>
488 <div class='plugin-description'>$description</div>
489 <div class='$class second plugin-version-author-uri'>";
491 $plugin_meta = array();
492 if ( !empty( $plugin_data['Version'] ) )
493 $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
494 if ( !empty( $plugin_data['Author'] ) ) {
495 $author = $plugin_data['Author'];
496 if ( !empty( $plugin_data['AuthorURI'] ) )
497 $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
498 $plugin_meta[] = sprintf( __( 'By %s' ), $author );
500 if ( ! empty( $plugin_data['PluginURI'] ) )
501 $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin site' ) . '">' . __( 'Visit plugin site' ) . '</a>';
504 * Filter the array of row meta for each plugin in the Plugins list table.
508 * @param array $plugin_meta An array of the plugin's metadata,
509 * including the version, author,
510 * author URI, and plugin URI.
511 * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
512 * @param array $plugin_data An array of plugin data.
513 * @param string $status Status of the plugin. Defaults are 'All', 'Active',
514 * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
515 * 'Drop-ins', 'Search'.
517 $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
518 echo implode( ' | ', $plugin_meta );
523 echo "<td class='$column_name column-$column_name'$style>";
526 * Fires inside each custom column of the Plugins list table.
530 * @param string $column_name Name of the column.
531 * @param string $plugin_file Path to the plugin file.
532 * @param array $plugin_data An array of plugin data.
534 do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
542 * Fires after each row in the Plugins list table.
546 * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
547 * @param array $plugin_data An array of plugin data.
548 * @param string $status Status of the plugin. Defaults are 'All', 'Active',
549 * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
550 * 'Drop-ins', 'Search'.
552 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
555 * Fires after each specific row in the Plugins list table.
557 * The dynamic portion of the hook name, $plugin_file, refers to the path
558 * to the plugin file, relative to the plugins directory.
562 * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
563 * @param array $plugin_data An array of plugin data.
564 * @param string $status Status of the plugin. Defaults are 'All', 'Active',
565 * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
566 * 'Drop-ins', 'Search'.
568 do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status );