]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-plugins-list-table.php
WordPress 4.7.2
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-plugins-list-table.php
1 <?php
2 /**
3  * List Table API: WP_Plugins_List_Table class
4  *
5  * @package WordPress
6  * @subpackage Administration
7  * @since 3.1.0
8  */
9
10 /**
11  * Core class used to implement displaying installed plugins in a list table.
12  *
13  * @since 3.1.0
14  * @access private
15  *
16  * @see WP_List_Table
17  */
18 class WP_Plugins_List_Table extends WP_List_Table {
19
20         /**
21          * Constructor.
22          *
23          * @since 3.1.0
24          * @access public
25          *
26          * @see WP_List_Table::__construct() for more information on default arguments.
27          *
28          * @global string $status
29          * @global int    $page
30          *
31          * @param array $args An associative array of arguments.
32          */
33         public function __construct( $args = array() ) {
34                 global $status, $page;
35
36                 parent::__construct( array(
37                         'plural' => 'plugins',
38                         'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
39                 ) );
40
41                 $status = 'all';
42                 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) )
43                         $status = $_REQUEST['plugin_status'];
44
45                 if ( isset($_REQUEST['s']) )
46                         $_SERVER['REQUEST_URI'] = add_query_arg('s', wp_unslash($_REQUEST['s']) );
47
48                 $page = $this->get_pagenum();
49         }
50
51         /**
52          * @return array
53          */
54         protected function get_table_classes() {
55                 return array( 'widefat', $this->_args['plural'] );
56         }
57
58         /**
59          * @return bool
60          */
61         public function ajax_user_can() {
62                 return current_user_can('activate_plugins');
63         }
64
65         /**
66          *
67          * @global string $status
68          * @global array  $plugins
69          * @global array  $totals
70          * @global int    $page
71          * @global string $orderby
72          * @global string $order
73          * @global string $s
74          */
75         public function prepare_items() {
76                 global $status, $plugins, $totals, $page, $orderby, $order, $s;
77
78                 wp_reset_vars( array( 'orderby', 'order' ) );
79
80                 /**
81                  * Filters the full array of plugins to list in the Plugins list table.
82                  *
83                  * @since 3.0.0
84                  *
85                  * @see get_plugins()
86                  *
87                  * @param array $all_plugins An array of plugins to display in the list table.
88                  */
89                 $all_plugins = apply_filters( 'all_plugins', get_plugins() );
90
91                 $plugins = array(
92                         'all'                => $all_plugins,
93                         'search'             => array(),
94                         'active'             => array(),
95                         'inactive'           => array(),
96                         'recently_activated' => array(),
97                         'upgrade'            => array(),
98                         'mustuse'            => array(),
99                         'dropins'            => array(),
100                 );
101
102                 $screen = $this->screen;
103
104                 if ( ! is_multisite() || ( $screen->in_admin( 'network' ) && current_user_can( 'manage_network_plugins' ) ) ) {
105
106                         /**
107                          * Filters whether to display the advanced plugins list table.
108                          *
109                          * There are two types of advanced plugins - must-use and drop-ins -
110                          * which can be used in a single site or Multisite network.
111                          *
112                          * The $type parameter allows you to differentiate between the type of advanced
113                          * plugins to filter the display of. Contexts include 'mustuse' and 'dropins'.
114                          *
115                          * @since 3.0.0
116                          *
117                          * @param bool   $show Whether to show the advanced plugins for the specified
118                          *                     plugin type. Default true.
119                          * @param string $type The plugin type. Accepts 'mustuse', 'dropins'.
120                          */
121                         if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ) {
122                                 $plugins['mustuse'] = get_mu_plugins();
123                         }
124
125                         /** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */
126                         if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
127                                 $plugins['dropins'] = get_dropins();
128
129                         if ( current_user_can( 'update_plugins' ) ) {
130                                 $current = get_site_transient( 'update_plugins' );
131                                 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
132                                         if ( isset( $current->response[ $plugin_file ] ) ) {
133                                                 $plugins['all'][ $plugin_file ]['update'] = true;
134                                                 $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
135                                         }
136                                 }
137                         }
138                 }
139
140                 if ( ! $screen->in_admin( 'network' ) ) {
141                         $show = current_user_can( 'manage_network_plugins' );
142                         /**
143                          * Filters whether to display network-active plugins alongside plugins active for the current site.
144                          *
145                          * This also controls the display of inactive network-only plugins (plugins with
146                          * "Network: true" in the plugin header).
147                          *
148                          * Plugins cannot be network-activated or network-deactivated from this screen.
149                          *
150                          * @since 4.4.0
151                          *
152                          * @param bool $show Whether to show network-active plugins. Default is whether the current
153                          *                   user can manage network plugins (ie. a Super Admin).
154                          */
155                         $show_network_active = apply_filters( 'show_network_active_plugins', $show );
156                 }
157
158                 set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS );
159
160                 if ( $screen->in_admin( 'network' ) ) {
161                         $recently_activated = get_site_option( 'recently_activated', array() );
162                 } else {
163                         $recently_activated = get_option( 'recently_activated', array() );
164                 }
165
166                 foreach ( $recently_activated as $key => $time ) {
167                         if ( $time + WEEK_IN_SECONDS < time() ) {
168                                 unset( $recently_activated[$key] );
169                         }
170                 }
171
172                 if ( $screen->in_admin( 'network' ) ) {
173                         update_site_option( 'recently_activated', $recently_activated );
174                 } else {
175                         update_option( 'recently_activated', $recently_activated );
176                 }
177
178                 $plugin_info = get_site_transient( 'update_plugins' );
179
180                 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
181                         // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide.
182                         if ( isset( $plugin_info->response[ $plugin_file ] ) ) {
183                                 $plugins['all'][ $plugin_file ] = $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], $plugin_data );
184                                 // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade
185                                 if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) {
186                                         $plugins['upgrade'][ $plugin_file ] = $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], $plugin_data );
187                                 }
188
189                         } elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) {
190                                 $plugins['all'][ $plugin_file ] = $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], $plugin_data );
191                                 // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade
192                                 if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) {
193                                         $plugins['upgrade'][ $plugin_file ] = $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], $plugin_data );
194                                 }
195                         }
196
197                         // Filter into individual sections
198                         if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) && ! is_plugin_active( $plugin_file ) ) {
199                                 if ( $show_network_active ) {
200                                         // On the non-network screen, show inactive network-only plugins if allowed
201                                         $plugins['inactive'][ $plugin_file ] = $plugin_data;
202                                 } else {
203                                         // On the non-network screen, filter out network-only plugins as long as they're not individually active
204                                         unset( $plugins['all'][ $plugin_file ] );
205                                 }
206                         } elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) {
207                                 if ( $show_network_active ) {
208                                         // On the non-network screen, show network-active plugins if allowed
209                                         $plugins['active'][ $plugin_file ] = $plugin_data;
210                                 } else {
211                                         // On the non-network screen, filter out network-active plugins
212                                         unset( $plugins['all'][ $plugin_file ] );
213                                 }
214                         } elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) )
215                                 || ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) {
216                                 // On the non-network screen, populate the active list with plugins that are individually activated
217                                 // On the network-admin screen, populate the active list with plugins that are network activated
218                                 $plugins['active'][ $plugin_file ] = $plugin_data;
219                         } else {
220                                 if ( isset( $recently_activated[ $plugin_file ] ) ) {
221                                         // Populate the recently activated list with plugins that have been recently activated
222                                         $plugins['recently_activated'][ $plugin_file ] = $plugin_data;
223                                 }
224                                 // Populate the inactive list with plugins that aren't activated
225                                 $plugins['inactive'][ $plugin_file ] = $plugin_data;
226                         }
227                 }
228
229                 if ( strlen( $s ) ) {
230                         $status = 'search';
231                         $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) );
232                 }
233
234                 $totals = array();
235                 foreach ( $plugins as $type => $list )
236                         $totals[ $type ] = count( $list );
237
238                 if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
239                         $status = 'all';
240
241                 $this->items = array();
242                 foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) {
243                         // Translate, Don't Apply Markup, Sanitize HTML
244                         $this->items[$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
245                 }
246
247                 $total_this_page = $totals[ $status ];
248
249                 $js_plugins = array();
250                 foreach ( $plugins as $key => $list ) {
251                         $js_plugins[ $key ] = array_keys( (array) $list );
252                 }
253
254                 wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
255                         'plugins' => $js_plugins,
256                         'totals'  => wp_get_update_data(),
257                 ) );
258
259                 if ( ! $orderby ) {
260                         $orderby = 'Name';
261                 } else {
262                         $orderby = ucfirst( $orderby );
263                 }
264
265                 $order = strtoupper( $order );
266
267                 uasort( $this->items, array( $this, '_order_callback' ) );
268
269                 $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 );
270
271                 $start = ( $page - 1 ) * $plugins_per_page;
272
273                 if ( $total_this_page > $plugins_per_page )
274                         $this->items = array_slice( $this->items, $start, $plugins_per_page );
275
276                 $this->set_pagination_args( array(
277                         'total_items' => $total_this_page,
278                         'per_page' => $plugins_per_page,
279                 ) );
280         }
281
282         /**
283          * @global string $s URL encoded search term.
284          *
285          * @param array $plugin
286          * @return bool
287          */
288         public function _search_callback( $plugin ) {
289                 global $s;
290
291                 foreach ( $plugin as $value ) {
292                         if ( is_string( $value ) && false !== stripos( strip_tags( $value ), urldecode( $s ) ) ) {
293                                 return true;
294                         }
295                 }
296
297                 return false;
298         }
299
300         /**
301          * @global string $orderby
302          * @global string $order
303          * @param array $plugin_a
304          * @param array $plugin_b
305          * @return int
306          */
307         public function _order_callback( $plugin_a, $plugin_b ) {
308                 global $orderby, $order;
309
310                 $a = $plugin_a[$orderby];
311                 $b = $plugin_b[$orderby];
312
313                 if ( $a == $b )
314                         return 0;
315
316                 if ( 'DESC' === $order ) {
317                         return strcasecmp( $b, $a );
318                 } else {
319                         return strcasecmp( $a, $b );
320                 }
321         }
322
323         /**
324          *
325          * @global array $plugins
326          */
327         public function no_items() {
328                 global $plugins;
329
330                 if ( ! empty( $_REQUEST['s'] ) ) {
331                         $s = esc_html( wp_unslash( $_REQUEST['s'] ) );
332
333                         printf( __( 'No plugins found for &#8220;%s&#8221;.' ), $s );
334
335                         // We assume that somebody who can install plugins in multisite is experienced enough to not need this helper link.
336                         if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) {
337                                 echo ' <a href="' . esc_url( admin_url( 'plugin-install.php?tab=search&s=' . urlencode( $s ) ) ) . '">' . __( 'Search for plugins in the WordPress Plugin Directory.' ) . '</a>';
338                         }
339                 } elseif ( ! empty( $plugins['all'] ) )
340                         _e( 'No plugins found.' );
341                 else
342                         _e( 'You do not appear to have any plugins available at this time.' );
343         }
344
345         /**
346          * Displays the search box.
347          *
348          * @since 4.6.0
349          * @access public
350          *
351          * @param string $text     The 'submit' button label.
352          * @param string $input_id ID attribute value for the search input field.
353          */
354         public function search_box( $text, $input_id ) {
355                 if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
356                         return;
357                 }
358
359                 $input_id = $input_id . '-search-input';
360
361                 if ( ! empty( $_REQUEST['orderby'] ) ) {
362                         echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
363                 }
364                 if ( ! empty( $_REQUEST['order'] ) ) {
365                         echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
366                 }
367                 ?>
368                 <p class="search-box">
369                         <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label>
370                         <input type="search" id="<?php echo esc_attr( $input_id ); ?>" class="wp-filter-search" name="s" value="<?php _admin_search_query(); ?>" placeholder="<?php esc_attr_e( 'Search installed plugins...' ); ?>"/>
371                         <?php submit_button( $text, 'hide-if-js', '', false, array( 'id' => 'search-submit' ) ); ?>
372                 </p>
373                 <?php
374         }
375
376         /**
377          *
378          * @global string $status
379          * @return array
380          */
381         public function get_columns() {
382                 global $status;
383
384                 return array(
385                         'cb'          => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
386                         'name'        => __( 'Plugin' ),
387                         'description' => __( 'Description' ),
388                 );
389         }
390
391         /**
392          * @return array
393          */
394         protected function get_sortable_columns() {
395                 return array();
396         }
397
398         /**
399          *
400          * @global array $totals
401          * @global string $status
402          * @return array
403          */
404         protected function get_views() {
405                 global $totals, $status;
406
407                 $status_links = array();
408                 foreach ( $totals as $type => $count ) {
409                         if ( !$count )
410                                 continue;
411
412                         switch ( $type ) {
413                                 case 'all':
414                                         $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' );
415                                         break;
416                                 case 'active':
417                                         $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count );
418                                         break;
419                                 case 'recently_activated':
420                                         $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count );
421                                         break;
422                                 case 'inactive':
423                                         $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
424                                         break;
425                                 case 'mustuse':
426                                         $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
427                                         break;
428                                 case 'dropins':
429                                         $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count );
430                                         break;
431                                 case 'upgrade':
432                                         $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
433                                         break;
434                         }
435
436                         if ( 'search' !== $type ) {
437                                 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
438                                         add_query_arg('plugin_status', $type, 'plugins.php'),
439                                         ( $type === $status ) ? ' class="current"' : '',
440                                         sprintf( $text, number_format_i18n( $count ) )
441                                         );
442                         }
443                 }
444
445                 return $status_links;
446         }
447
448         /**
449          *
450          * @global string $status
451          * @return array
452          */
453         protected function get_bulk_actions() {
454                 global $status;
455
456                 $actions = array();
457
458                 if ( 'active' != $status )
459                         $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' );
460
461                 if ( 'inactive' != $status && 'recent' != $status )
462                         $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' );
463
464                 if ( !is_multisite() || $this->screen->in_admin( 'network' ) ) {
465                         if ( current_user_can( 'update_plugins' ) )
466                                 $actions['update-selected'] = __( 'Update' );
467                         if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
468                                 $actions['delete-selected'] = __( 'Delete' );
469                 }
470
471                 return $actions;
472         }
473
474         /**
475          * @global string $status
476          * @param string $which
477          */
478         public function bulk_actions( $which = '' ) {
479                 global $status;
480
481                 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) )
482                         return;
483
484                 parent::bulk_actions( $which );
485         }
486
487         /**
488          * @global string $status
489          * @param string $which
490          */
491         protected function extra_tablenav( $which ) {
492                 global $status;
493
494                 if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) )
495                         return;
496
497                 echo '<div class="alignleft actions">';
498
499                 if ( 'recently_activated' == $status ) {
500                         submit_button( __( 'Clear List' ), '', 'clear-recent-list', false );
501                 } elseif ( 'top' === $which && 'mustuse' === $status ) {
502                         /* translators: %s: mu-plugins directory name */
503                         echo '<p>' . sprintf( __( 'Files in the %s directory are executed automatically.' ),
504                                 '<code>' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . '</code>'
505                         ) . '</p>';
506                 } elseif ( 'top' === $which && 'dropins' === $status ) {
507                         /* translators: %s: wp-content directory name */
508                         echo '<p>' . sprintf( __( 'Drop-ins are advanced plugins in the %s directory that replace WordPress functionality when present.' ),
509                                 '<code>' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '</code>'
510                         ) . '</p>';
511                 }
512                 echo '</div>';
513         }
514
515         /**
516          * @return string
517          */
518         public function current_action() {
519                 if ( isset($_POST['clear-recent-list']) )
520                         return 'clear-recent-list';
521
522                 return parent::current_action();
523         }
524
525         /**
526          *
527          * @global string $status
528          */
529         public function display_rows() {
530                 global $status;
531
532                 if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) )
533                         return;
534
535                 foreach ( $this->items as $plugin_file => $plugin_data )
536                         $this->single_row( array( $plugin_file, $plugin_data ) );
537         }
538
539         /**
540          * @global string $status
541          * @global int $page
542          * @global string $s
543          * @global array $totals
544          *
545          * @param array $item
546          */
547         public function single_row( $item ) {
548                 global $status, $page, $s, $totals;
549
550                 list( $plugin_file, $plugin_data ) = $item;
551                 $context = $status;
552                 $screen = $this->screen;
553
554                 // Pre-order.
555                 $actions = array(
556                         'deactivate' => '',
557                         'activate' => '',
558                         'details' => '',
559                         'edit' => '',
560                         'delete' => '',
561                 );
562
563                 // Do not restrict by default
564                 $restrict_network_active = false;
565                 $restrict_network_only = false;
566
567                 if ( 'mustuse' === $context ) {
568                         $is_active = true;
569                 } elseif ( 'dropins' === $context ) {
570                         $dropins = _get_dropins();
571                         $plugin_name = $plugin_file;
572                         if ( $plugin_file != $plugin_data['Name'] )
573                                 $plugin_name .= '<br/>' . $plugin_data['Name'];
574                         if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
575                                 $is_active = true;
576                                 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
577                         } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
578                                 $is_active = true;
579                                 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
580                         } else {
581                                 $is_active = false;
582                                 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="error-message">' . __( 'Inactive:' ) . '</span></strong> ' .
583                                         /* translators: 1: drop-in constant name, 2: wp-config.php */
584                                         sprintf( __( 'Requires %1$s in %2$s file.' ),
585                                                 "<code>define('" . $dropins[ $plugin_file ][1] . "', true);</code>",
586                                                 '<code>wp-config.php</code>'
587                                         ) . '</p>';
588                         }
589                         if ( $plugin_data['Description'] )
590                                 $description .= '<p>' . $plugin_data['Description'] . '</p>';
591                 } else {
592                         if ( $screen->in_admin( 'network' ) ) {
593                                 $is_active = is_plugin_active_for_network( $plugin_file );
594                         } else {
595                                 $is_active = is_plugin_active( $plugin_file );
596                                 $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) );
597                                 $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active );
598                         }
599
600                         if ( $screen->in_admin( 'network' ) ) {
601                                 if ( $is_active ) {
602                                         if ( current_user_can( 'manage_network_plugins' ) ) {
603                                                 /* translators: %s: plugin name */
604                                                 $actions['deactivate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Deactivate' ) . '</a>';
605                                                 }
606                                 } else {
607                                         if ( current_user_can( 'manage_network_plugins' ) ) {
608                                                 /* translators: %s: plugin name */
609                                                 $actions['activate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file ) . '" class="edit" aria-label="' . esc_attr( sprintf( _x( 'Network Activate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Activate' ) . '</a>';
610                                         }
611                                         if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) {
612                                                 /* translators: %s: plugin name */
613                                                 $actions['delete'] = '<a href="' . wp_nonce_url( 'plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins' ) . '" class="delete" aria-label="' . esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>';
614                                         }
615                                 }
616                         } else {
617                                 if ( $restrict_network_active ) {
618                                         $actions = array(
619                                                 'network_active' => __( 'Network Active' ),
620                                         );
621                                 } elseif ( $restrict_network_only ) {
622                                         $actions = array(
623                                                 'network_only' => __( 'Network Only' ),
624                                         );
625                                 } elseif ( $is_active ) {
626                                         /* translators: %s: plugin name */
627                                         $actions['deactivate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( _x( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Deactivate' ) . '</a>';
628                                 } else {
629                                         /* translators: %s: plugin name */
630                                         $actions['activate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file ) . '" class="edit" aria-label="' . esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Activate' ) . '</a>';
631
632                                         if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) {
633                                                 /* translators: %s: plugin name */
634                                                 $actions['delete'] = '<a href="' . wp_nonce_url( 'plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins' ) . '" class="delete" aria-label="' . esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>';
635                                         }
636                                 } // end if $is_active
637
638                          } // end if $screen->in_admin( 'network' )
639
640                         if ( ( ! is_multisite() || $screen->in_admin( 'network' ) ) && current_user_can( 'edit_plugins' ) && is_writable( WP_PLUGIN_DIR . '/' . $plugin_file ) ) {
641                                 /* translators: %s: plugin name */
642                                 $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" class="edit" aria-label="' . esc_attr( sprintf( __( 'Edit %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Edit' ) . '</a>';
643                         }
644                 } // end if $context
645
646                 $actions = array_filter( $actions );
647
648                 if ( $screen->in_admin( 'network' ) ) {
649
650                         /**
651                          * Filters the action links displayed for each plugin in the Network Admin Plugins list table.
652                          *
653                          * The default action links for the Network plugins list table include
654                          * 'Network Activate', 'Network Deactivate', 'Edit', and 'Delete'.
655                          *
656                          * @since 3.1.0
657                          *
658                          * @param array  $actions     An array of plugin action links.
659                          * @param string $plugin_file Path to the plugin file relative to the plugins directory.
660                          * @param array  $plugin_data An array of plugin data.
661                          * @param string $context     The plugin context. Defaults are 'All', 'Active',
662                          *                            'Inactive', 'Recently Activated', 'Upgrade',
663                          *                            'Must-Use', 'Drop-ins', 'Search'.
664                          */
665                         $actions = apply_filters( 'network_admin_plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
666
667                         /**
668                          * Filters the list of action links displayed for a specific plugin in the Network Admin Plugins list table.
669                          *
670                          * The dynamic portion of the hook name, $plugin_file, refers to the path
671                          * to the plugin file, relative to the plugins directory.
672                          *
673                          * @since 3.1.0
674                          *
675                          * @param array  $actions     An array of plugin action links.
676                          * @param string $plugin_file Path to the plugin file relative to the plugins directory.
677                          * @param array  $plugin_data An array of plugin data.
678                          * @param string $context     The plugin context. Defaults are 'All', 'Active',
679                          *                            'Inactive', 'Recently Activated', 'Upgrade',
680                          *                            'Must-Use', 'Drop-ins', 'Search'.
681                          */
682                         $actions = apply_filters( "network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );
683
684                 } else {
685
686                         /**
687                          * Filters the action links displayed for each plugin in the Plugins list table.
688                          *
689                          * The default action links for the site plugins list table include
690                          * 'Activate', 'Deactivate', and 'Edit', for a network site, and
691                          * 'Activate', 'Deactivate', 'Edit', and 'Delete' for a single site.
692                          *
693                          * @since 2.5.0
694                          * @since 2.6.0 The `$context` parameter was added.
695                          *
696                          * @param array  $actions     An array of plugin action links.
697                          * @param string $plugin_file Path to the plugin file relative to the plugins directory.
698                          * @param array  $plugin_data An array of plugin data.
699                          * @param string $context     The plugin context. Defaults are 'All', 'Active',
700                          *                            'Inactive', 'Recently Activated', 'Upgrade',
701                          *                            'Must-Use', 'Drop-ins', 'Search'.
702                          */
703                         $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
704
705                         /**
706                          * Filters the list of action links displayed for a specific plugin in the Plugins list table.
707                          *
708                          * The dynamic portion of the hook name, $plugin_file, refers to the path
709                          * to the plugin file, relative to the plugins directory.
710                          *
711                          * @since 2.7.0
712                          *
713                          * @param array  $actions     An array of plugin action links.
714                          * @param string $plugin_file Path to the plugin file relative to the plugins directory.
715                          * @param array  $plugin_data An array of plugin data.
716                          * @param string $context     The plugin context. Defaults are 'All', 'Active',
717                          *                            'Inactive', 'Recently Activated', 'Upgrade',
718                          *                            'Must-Use', 'Drop-ins', 'Search'.
719                          */
720                         $actions = apply_filters( "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );
721
722                 }
723
724                 $class = $is_active ? 'active' : 'inactive';
725                 $checkbox_id =  "checkbox_" . md5($plugin_data['Name']);
726                 if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
727                         $checkbox = '';
728                 } else {
729                         $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . "</label>"
730                                 . "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' />";
731                 }
732                 if ( 'dropins' != $context ) {
733                         $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : '&nbsp;' ) . '</p>';
734                         $plugin_name = $plugin_data['Name'];
735                 }
736
737                 if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) )
738                         $class .= ' update';
739
740                 $plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_name );
741                 printf( '<tr class="%s" data-slug="%s" data-plugin="%s">',
742                         esc_attr( $class ),
743                         esc_attr( $plugin_slug ),
744                         esc_attr( $plugin_file )
745                 );
746
747                 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
748
749                 foreach ( $columns as $column_name => $column_display_name ) {
750                         $extra_classes = '';
751                         if ( in_array( $column_name, $hidden ) ) {
752                                 $extra_classes = ' hidden';
753                         }
754
755                         switch ( $column_name ) {
756                                 case 'cb':
757                                         echo "<th scope='row' class='check-column'>$checkbox</th>";
758                                         break;
759                                 case 'name':
760                                         echo "<td class='plugin-title column-primary'><strong>$plugin_name</strong>";
761                                         echo $this->row_actions( $actions, true );
762                                         echo "</td>";
763                                         break;
764                                 case 'description':
765                                         $classes = 'column-description desc';
766
767                                         echo "<td class='$classes{$extra_classes}'>
768                                                 <div class='plugin-description'>$description</div>
769                                                 <div class='$class second plugin-version-author-uri'>";
770
771                                         $plugin_meta = array();
772                                         if ( !empty( $plugin_data['Version'] ) )
773                                                 $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
774                                         if ( !empty( $plugin_data['Author'] ) ) {
775                                                 $author = $plugin_data['Author'];
776                                                 if ( !empty( $plugin_data['AuthorURI'] ) )
777                                                         $author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>';
778                                                 $plugin_meta[] = sprintf( __( 'By %s' ), $author );
779                                         }
780
781                                         // Details link using API info, if available
782                                         if ( isset( $plugin_data['slug'] ) && current_user_can( 'install_plugins' ) ) {
783                                                 $plugin_meta[] = sprintf( '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
784                                                         esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] .
785                                                                 '&TB_iframe=true&width=600&height=550' ) ),
786                                                         esc_attr( sprintf( __( 'More information about %s' ), $plugin_name ) ),
787                                                         esc_attr( $plugin_name ),
788                                                         __( 'View details' )
789                                                 );
790                                         } elseif ( ! empty( $plugin_data['PluginURI'] ) ) {
791                                                 $plugin_meta[] = sprintf( '<a href="%s">%s</a>',
792                                                         esc_url( $plugin_data['PluginURI'] ),
793                                                         __( 'Visit plugin site' )
794                                                 );
795                                         }
796
797                                         /**
798                                          * Filters the array of row meta for each plugin in the Plugins list table.
799                                          *
800                                          * @since 2.8.0
801                                          *
802                                          * @param array  $plugin_meta An array of the plugin's metadata,
803                                          *                            including the version, author,
804                                          *                            author URI, and plugin URI.
805                                          * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
806                                          * @param array  $plugin_data An array of plugin data.
807                                          * @param string $status      Status of the plugin. Defaults are 'All', 'Active',
808                                          *                            'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
809                                          *                            'Drop-ins', 'Search'.
810                                          */
811                                         $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
812                                         echo implode( ' | ', $plugin_meta );
813
814                                         echo "</div></td>";
815                                         break;
816                                 default:
817                                         $classes = "$column_name column-$column_name $class";
818
819                                         echo "<td class='$classes{$extra_classes}'>";
820
821                                         /**
822                                          * Fires inside each custom column of the Plugins list table.
823                                          *
824                                          * @since 3.1.0
825                                          *
826                                          * @param string $column_name Name of the column.
827                                          * @param string $plugin_file Path to the plugin file.
828                                          * @param array  $plugin_data An array of plugin data.
829                                          */
830                                         do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
831
832                                         echo "</td>";
833                         }
834                 }
835
836                 echo "</tr>";
837
838                 /**
839                  * Fires after each row in the Plugins list table.
840                  *
841                  * @since 2.3.0
842                  *
843                  * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
844                  * @param array  $plugin_data An array of plugin data.
845                  * @param string $status      Status of the plugin. Defaults are 'All', 'Active',
846                  *                            'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
847                  *                            'Drop-ins', 'Search'.
848                  */
849                 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
850
851                 /**
852                  * Fires after each specific row in the Plugins list table.
853                  *
854                  * The dynamic portion of the hook name, `$plugin_file`, refers to the path
855                  * to the plugin file, relative to the plugins directory.
856                  *
857                  * @since 2.7.0
858                  *
859                  * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
860                  * @param array  $plugin_data An array of plugin data.
861                  * @param string $status      Status of the plugin. Defaults are 'All', 'Active',
862                  *                            'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
863                  *                            'Drop-ins', 'Search'.
864                  */
865                 do_action( "after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $status );
866         }
867
868         /**
869          * Gets the name of the primary column for this specific list table.
870          *
871          * @since 4.3.0
872          * @access protected
873          *
874          * @return string Unalterable name for the primary column, in this case, 'name'.
875          */
876         protected function get_primary_column_name() {
877                 return 'name';
878         }
879 }