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 'all' => apply_filters( 'all_plugins', get_plugins() ),
47 'inactive' => array(),
48 'recently_activated' => array(),
54 $screen = $this->screen;
56 if ( ! is_multisite() || ( $screen->in_admin( 'network' ) && current_user_can( 'manage_network_plugins' ) ) ) {
57 if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) )
58 $plugins['mustuse'] = get_mu_plugins();
59 if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
60 $plugins['dropins'] = get_dropins();
62 if ( current_user_can( 'update_plugins' ) ) {
63 $current = get_site_transient( 'update_plugins' );
64 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
65 if ( isset( $current->response[ $plugin_file ] ) ) {
66 $plugins['all'][ $plugin_file ]['update'] = true;
67 $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
73 set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS );
75 if ( ! $screen->in_admin( 'network' ) ) {
76 $recently_activated = get_option( 'recently_activated', array() );
78 foreach ( $recently_activated as $key => $time )
79 if ( $time + WEEK_IN_SECONDS < time() )
80 unset( $recently_activated[$key] );
81 update_option( 'recently_activated', $recently_activated );
84 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
85 // Filter into individual sections
86 if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) ) {
87 unset( $plugins['all'][ $plugin_file ] );
88 } elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) {
89 unset( $plugins['all'][ $plugin_file ] );
90 } elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) )
91 || ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) {
92 $plugins['active'][ $plugin_file ] = $plugin_data;
94 if ( ! $screen->in_admin( 'network' ) && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
95 $plugins['recently_activated'][ $plugin_file ] = $plugin_data;
96 $plugins['inactive'][ $plugin_file ] = $plugin_data;
102 $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) );
106 foreach ( $plugins as $type => $list )
107 $totals[ $type ] = count( $list );
109 if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
112 $this->items = array();
113 foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) {
114 // Translate, Don't Apply Markup, Sanitize HTML
115 $this->items[$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
118 $total_this_page = $totals[ $status ];
121 $orderby = ucfirst( $orderby );
122 $order = strtoupper( $order );
124 uasort( $this->items, array( $this, '_order_callback' ) );
127 $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 );
129 $start = ( $page - 1 ) * $plugins_per_page;
131 if ( $total_this_page > $plugins_per_page )
132 $this->items = array_slice( $this->items, $start, $plugins_per_page );
134 $this->set_pagination_args( array(
135 'total_items' => $total_this_page,
136 'per_page' => $plugins_per_page,
140 function _search_callback( $plugin ) {
142 if ( is_null( $term ) )
143 $term = wp_unslash( $_REQUEST['s'] );
145 foreach ( $plugin as $value )
146 if ( stripos( $value, $term ) !== false )
152 function _order_callback( $plugin_a, $plugin_b ) {
153 global $orderby, $order;
155 $a = $plugin_a[$orderby];
156 $b = $plugin_b[$orderby];
161 if ( 'DESC' == $order )
162 return ( $a < $b ) ? 1 : -1;
164 return ( $a < $b ) ? -1 : 1;
167 function no_items() {
170 if ( !empty( $plugins['all'] ) )
171 _e( 'No plugins found.' );
173 _e( 'You do not appear to have any plugins available at this time.' );
176 function get_columns() {
180 'cb' => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
181 'name' => __( 'Plugin' ),
182 'description' => __( 'Description' ),
186 function get_sortable_columns() {
190 function get_views() {
191 global $totals, $status;
193 $status_links = array();
194 foreach ( $totals as $type => $count ) {
200 $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' );
203 $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count );
205 case 'recently_activated':
206 $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count );
209 $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
212 $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
215 $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count );
218 $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
222 if ( 'search' != $type ) {
223 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
224 add_query_arg('plugin_status', $type, 'plugins.php'),
225 ( $type == $status ) ? ' class="current"' : '',
226 sprintf( $text, number_format_i18n( $count ) )
231 return $status_links;
234 function get_bulk_actions() {
239 if ( 'active' != $status )
240 $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' );
242 if ( 'inactive' != $status && 'recent' != $status )
243 $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' );
245 if ( !is_multisite() || $this->screen->in_admin( 'network' ) ) {
246 if ( current_user_can( 'update_plugins' ) )
247 $actions['update-selected'] = __( 'Update' );
248 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
249 $actions['delete-selected'] = __( 'Delete' );
255 function bulk_actions() {
258 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) )
261 parent::bulk_actions();
264 function extra_tablenav( $which ) {
267 if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) )
270 echo '<div class="alignleft actions">';
272 if ( ! $this->screen->in_admin( 'network' ) && 'recently_activated' == $status )
273 submit_button( __( 'Clear List' ), 'button', 'clear-recent-list', false );
274 elseif ( 'top' == $which && 'mustuse' == $status )
275 echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>';
276 elseif ( 'top' == $which && 'dropins' == $status )
277 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>';
282 function current_action() {
283 if ( isset($_POST['clear-recent-list']) )
284 return 'clear-recent-list';
286 return parent::current_action();
289 function display_rows() {
292 if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) )
295 foreach ( $this->items as $plugin_file => $plugin_data )
296 $this->single_row( array( $plugin_file, $plugin_data ) );
299 function single_row( $item ) {
300 global $status, $page, $s, $totals;
302 list( $plugin_file, $plugin_data ) = $item;
304 $screen = $this->screen;
314 if ( 'mustuse' == $context ) {
316 } elseif ( 'dropins' == $context ) {
317 $dropins = _get_dropins();
318 $plugin_name = $plugin_file;
319 if ( $plugin_file != $plugin_data['Name'] )
320 $plugin_name .= '<br/>' . $plugin_data['Name'];
321 if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
323 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
324 } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
326 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
329 $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>';
331 if ( $plugin_data['Description'] )
332 $description .= '<p>' . $plugin_data['Description'] . '</p>';
334 if ( $screen->in_admin( 'network' ) )
335 $is_active = is_plugin_active_for_network( $plugin_file );
337 $is_active = is_plugin_active( $plugin_file );
339 if ( $screen->in_admin( 'network' ) ) {
341 if ( current_user_can( 'manage_network_plugins' ) )
342 $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>';
344 if ( current_user_can( 'manage_network_plugins' ) )
345 $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>';
346 if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) )
347 $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>';
351 $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>';
353 $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>';
355 if ( ! is_multisite() && current_user_can('delete_plugins') )
356 $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>';
357 } // end if $is_active
358 } // end if $screen->in_admin( 'network' )
360 if ( ( ! is_multisite() || $screen->in_admin( 'network' ) ) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
361 $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . esc_attr__('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
364 $prefix = $screen->in_admin( 'network' ) ? 'network_admin_' : '';
365 $actions = apply_filters( $prefix . 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
366 $actions = apply_filters( $prefix . "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
368 $class = $is_active ? 'active' : 'inactive';
369 $checkbox_id = "checkbox_" . md5($plugin_data['Name']);
370 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
373 $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . "</label>"
374 . "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' />";
376 if ( 'dropins' != $context ) {
377 $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : ' ' ) . '</p>';
378 $plugin_name = $plugin_data['Name'];
381 $id = sanitize_title( $plugin_name );
382 if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) )
385 echo "<tr id='$id' class='$class'>";
387 list( $columns, $hidden ) = $this->get_column_info();
389 foreach ( $columns as $column_name => $column_display_name ) {
391 if ( in_array( $column_name, $hidden ) )
392 $style = ' style="display:none;"';
394 switch ( $column_name ) {
396 echo "<th scope='row' class='check-column'>$checkbox</th>";
399 echo "<td class='plugin-title'$style><strong>$plugin_name</strong>";
400 echo $this->row_actions( $actions, true );
404 echo "<td class='column-description desc'$style>
405 <div class='plugin-description'>$description</div>
406 <div class='$class second plugin-version-author-uri'>";
408 $plugin_meta = array();
409 if ( !empty( $plugin_data['Version'] ) )
410 $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
411 if ( !empty( $plugin_data['Author'] ) ) {
412 $author = $plugin_data['Author'];
413 if ( !empty( $plugin_data['AuthorURI'] ) )
414 $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
415 $plugin_meta[] = sprintf( __( 'By %s' ), $author );
417 if ( ! empty( $plugin_data['PluginURI'] ) )
418 $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin site' ) . '">' . __( 'Visit plugin site' ) . '</a>';
420 $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
421 echo implode( ' | ', $plugin_meta );
426 echo "<td class='$column_name column-$column_name'$style>";
427 do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
434 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
435 do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status );