]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-plugins-list-table.php
Wordpress 4.6-scripts
[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                 ) );
257
258                 if ( ! $orderby ) {
259                         $orderby = 'Name';
260                 } else {
261                         $orderby = ucfirst( $orderby );
262                 }
263
264                 $order = strtoupper( $order );
265
266                 uasort( $this->items, array( $this, '_order_callback' ) );
267
268                 $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 );
269
270                 $start = ( $page - 1 ) * $plugins_per_page;
271
272                 if ( $total_this_page > $plugins_per_page )
273                         $this->items = array_slice( $this->items, $start, $plugins_per_page );
274
275                 $this->set_pagination_args( array(
276                         'total_items' => $total_this_page,
277                         'per_page' => $plugins_per_page,
278                 ) );
279         }
280
281         /**
282          * @global string $s URL encoded search term.
283          *
284          * @param array $plugin
285          * @return bool
286          */
287         public function _search_callback( $plugin ) {
288                 global $s;
289
290                 foreach ( $plugin as $value ) {
291                         if ( is_string( $value ) && false !== stripos( strip_tags( $value ), urldecode( $s ) ) ) {
292                                 return true;
293                         }
294                 }
295
296                 return false;
297         }
298
299         /**
300          * @global string $orderby
301          * @global string $order
302          * @param array $plugin_a
303          * @param array $plugin_b
304          * @return int
305          */
306         public function _order_callback( $plugin_a, $plugin_b ) {
307                 global $orderby, $order;
308
309                 $a = $plugin_a[$orderby];
310                 $b = $plugin_b[$orderby];
311
312                 if ( $a == $b )
313                         return 0;
314
315                 if ( 'DESC' === $order ) {
316                         return strcasecmp( $b, $a );
317                 } else {
318                         return strcasecmp( $a, $b );
319                 }
320         }
321
322         /**
323          *
324          * @global array $plugins
325          */
326         public function no_items() {
327                 global $plugins;
328
329                 if ( ! empty( $_REQUEST['s'] ) ) {
330                         $s = esc_html( wp_unslash( $_REQUEST['s'] ) );
331
332                         printf( __( 'No plugins found for &#8220;%s&#8221;.' ), $s );
333
334                         // We assume that somebody who can install plugins in multisite is experienced enough to not need this helper link.
335                         if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) {
336                                 echo ' <a href="' . esc_url( admin_url( 'plugin-install.php?tab=search&s=' . urlencode( $s ) ) ) . '">' . __( 'Search for plugins in the WordPress Plugin Directory.' ) . '</a>';
337                         }
338                 } elseif ( ! empty( $plugins['all'] ) )
339                         _e( 'No plugins found.' );
340                 else
341                         _e( 'You do not appear to have any plugins available at this time.' );
342         }
343
344         /**
345          * Displays the search box.
346          *
347          * @since 4.6.0
348          * @access public
349          *
350          * @param string $text     The 'submit' button label.
351          * @param string $input_id ID attribute value for the search input field.
352          */
353         public function search_box( $text, $input_id ) {
354                 if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
355                         return;
356                 }
357
358                 $input_id = $input_id . '-search-input';
359
360                 if ( ! empty( $_REQUEST['orderby'] ) ) {
361                         echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
362                 }
363                 if ( ! empty( $_REQUEST['order'] ) ) {
364                         echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
365                 }
366                 ?>
367                 <p class="search-box">
368                         <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label>
369                         <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...' ); ?>"/>
370                         <?php submit_button( $text, 'button hide-if-js', '', false, array( 'id' => 'search-submit' ) ); ?>
371                 </p>
372                 <?php
373         }
374
375         /**
376          *
377          * @global string $status
378          * @return array
379          */
380         public function get_columns() {
381                 global $status;
382
383                 return array(
384                         'cb'          => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
385                         'name'        => __( 'Plugin' ),
386                         'description' => __( 'Description' ),
387                 );
388         }
389
390         /**
391          * @return array
392          */
393         protected function get_sortable_columns() {
394                 return array();
395         }
396
397         /**
398          *
399          * @global array $totals
400          * @global string $status
401          * @return array
402          */
403         protected function get_views() {
404                 global $totals, $status;
405
406                 $status_links = array();
407                 foreach ( $totals as $type => $count ) {
408                         if ( !$count )
409                                 continue;
410
411                         switch ( $type ) {
412                                 case 'all':
413                                         $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' );
414                                         break;
415                                 case 'active':
416                                         $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count );
417                                         break;
418                                 case 'recently_activated':
419                                         $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count );
420                                         break;
421                                 case 'inactive':
422                                         $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
423                                         break;
424                                 case 'mustuse':
425                                         $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
426                                         break;
427                                 case 'dropins':
428                                         $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count );
429                                         break;
430                                 case 'upgrade':
431                                         $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
432                                         break;
433                         }
434
435                         if ( 'search' !== $type ) {
436                                 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
437                                         add_query_arg('plugin_status', $type, 'plugins.php'),
438                                         ( $type === $status ) ? ' class="current"' : '',
439                                         sprintf( $text, number_format_i18n( $count ) )
440                                         );
441                         }
442                 }
443
444                 return $status_links;
445         }
446
447         /**
448          *
449          * @global string $status
450          * @return array
451          */
452         protected function get_bulk_actions() {
453                 global $status;
454
455                 $actions = array();
456
457                 if ( 'active' != $status )
458                         $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' );
459
460                 if ( 'inactive' != $status && 'recent' != $status )
461                         $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' );
462
463                 if ( !is_multisite() || $this->screen->in_admin( 'network' ) ) {
464                         if ( current_user_can( 'update_plugins' ) )
465                                 $actions['update-selected'] = __( 'Update' );
466                         if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
467                                 $actions['delete-selected'] = __( 'Delete' );
468                 }
469
470                 return $actions;
471         }
472
473         /**
474          * @global string $status
475          * @param string $which
476          */
477         public function bulk_actions( $which = '' ) {
478                 global $status;
479
480                 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) )
481                         return;
482
483                 parent::bulk_actions( $which );
484         }
485
486         /**
487          * @global string $status
488          * @param string $which
489          */
490         protected function extra_tablenav( $which ) {
491                 global $status;
492
493                 if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) )
494                         return;
495
496                 echo '<div class="alignleft actions">';
497
498                 if ( 'recently_activated' == $status ) {
499                         submit_button( __( 'Clear List' ), 'button', 'clear-recent-list', false );
500                 } elseif ( 'top' === $which && 'mustuse' === $status ) {
501                         /* translators: %s: mu-plugins directory name */
502                         echo '<p>' . sprintf( __( 'Files in the %s directory are executed automatically.' ),
503                                 '<code>' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . '</code>'
504                         ) . '</p>';
505                 } elseif ( 'top' === $which && 'dropins' === $status ) {
506                         /* translators: %s: wp-content directory name */
507                         echo '<p>' . sprintf( __( 'Drop-ins are advanced plugins in the %s directory that replace WordPress functionality when present.' ),
508                                 '<code>' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '</code>'
509                         ) . '</p>';
510                 }
511                 echo '</div>';
512         }
513
514         /**
515          * @return string
516          */
517         public function current_action() {
518                 if ( isset($_POST['clear-recent-list']) )
519                         return 'clear-recent-list';
520
521                 return parent::current_action();
522         }
523
524         /**
525          *
526          * @global string $status
527          */
528         public function display_rows() {
529                 global $status;
530
531                 if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) )
532                         return;
533
534                 foreach ( $this->items as $plugin_file => $plugin_data )
535                         $this->single_row( array( $plugin_file, $plugin_data ) );
536         }
537
538         /**
539          * @global string $status
540          * @global int $page
541          * @global string $s
542          * @global array $totals
543          *
544          * @param array $item
545          */
546         public function single_row( $item ) {
547                 global $status, $page, $s, $totals;
548
549                 list( $plugin_file, $plugin_data ) = $item;
550                 $context = $status;
551                 $screen = $this->screen;
552
553                 // Pre-order.
554                 $actions = array(
555                         'deactivate' => '',
556                         'activate' => '',
557                         'details' => '',
558                         'edit' => '',
559                         'delete' => '',
560                 );
561
562                 // Do not restrict by default
563                 $restrict_network_active = false;
564                 $restrict_network_only = false;
565
566                 if ( 'mustuse' === $context ) {
567                         $is_active = true;
568                 } elseif ( 'dropins' === $context ) {
569                         $dropins = _get_dropins();
570                         $plugin_name = $plugin_file;
571                         if ( $plugin_file != $plugin_data['Name'] )
572                                 $plugin_name .= '<br/>' . $plugin_data['Name'];
573                         if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
574                                 $is_active = true;
575                                 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
576                         } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
577                                 $is_active = true;
578                                 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
579                         } else {
580                                 $is_active = false;
581                                 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="error-message">' . __( 'Inactive:' ) . '</span></strong> ' .
582                                         /* translators: 1: drop-in constant name, 2: wp-config.php */
583                                         sprintf( __( 'Requires %1$s in %2$s file.' ),
584                                                 "<code>define('" . $dropins[ $plugin_file ][1] . "', true);</code>",
585                                                 '<code>wp-config.php</code>'
586                                         ) . '</p>';
587                         }
588                         if ( $plugin_data['Description'] )
589                                 $description .= '<p>' . $plugin_data['Description'] . '</p>';
590                 } else {
591                         if ( $screen->in_admin( 'network' ) ) {
592                                 $is_active = is_plugin_active_for_network( $plugin_file );
593                         } else {
594                                 $is_active = is_plugin_active( $plugin_file );
595                                 $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) );
596                                 $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active );
597                         }
598
599                         if ( $screen->in_admin( 'network' ) ) {
600                                 if ( $is_active ) {
601                                         if ( current_user_can( 'manage_network_plugins' ) ) {
602                                                 /* translators: %s: plugin name */
603                                                 $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>';
604                                                 }
605                                 } else {
606                                         if ( current_user_can( 'manage_network_plugins' ) ) {
607                                                 /* translators: %s: plugin name */
608                                                 $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>';
609                                         }
610                                         if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) {
611                                                 /* translators: %s: plugin name */
612                                                 $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>';
613                                         }
614                                 }
615                         } else {
616                                 if ( $restrict_network_active ) {
617                                         $actions = array(
618                                                 'network_active' => __( 'Network Active' ),
619                                         );
620                                 } elseif ( $restrict_network_only ) {
621                                         $actions = array(
622                                                 'network_only' => __( 'Network Only' ),
623                                         );
624                                 } elseif ( $is_active ) {
625                                         /* translators: %s: plugin name */
626                                         $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>';
627                                 } else {
628                                         /* translators: %s: plugin name */
629                                         $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>';
630
631                                         if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) {
632                                                 /* translators: %s: plugin name */
633                                                 $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>';
634                                         }
635                                 } // end if $is_active
636
637                          } // end if $screen->in_admin( 'network' )
638
639                         if ( ( ! is_multisite() || $screen->in_admin( 'network' ) ) && current_user_can( 'edit_plugins' ) && is_writable( WP_PLUGIN_DIR . '/' . $plugin_file ) ) {
640                                 /* translators: %s: plugin name */
641                                 $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" class="edit" aria-label="' . esc_attr( sprintf( __( 'Edit %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Edit' ) . '</a>';
642                         }
643                 } // end if $context
644
645                 $actions = array_filter( $actions );
646
647                 if ( $screen->in_admin( 'network' ) ) {
648
649                         /**
650                          * Filters the action links displayed for each plugin in the Network Admin Plugins list table.
651                          *
652                          * The default action links for the Network plugins list table include
653                          * 'Network Activate', 'Network Deactivate', 'Edit', and 'Delete'.
654                          *
655                          * @since 3.1.0 As `{$prefix}_plugin_action_links`
656                          * @since 4.4.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 As `{$prefix}_plugin_action_links_{$plugin_file}`
674                          * @since 4.4.0
675                          *
676                          * @param array  $actions     An array of plugin action links.
677                          * @param string $plugin_file Path to the plugin file relative to the plugins directory.
678                          * @param array  $plugin_data An array of plugin data.
679                          * @param string $context     The plugin context. Defaults are 'All', 'Active',
680                          *                            'Inactive', 'Recently Activated', 'Upgrade',
681                          *                            'Must-Use', 'Drop-ins', 'Search'.
682                          */
683                         $actions = apply_filters( "network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );
684
685                 } else {
686
687                         /**
688                          * Filters the action links displayed for each plugin in the Plugins list table.
689                          *
690                          * The default action links for the site plugins list table include
691                          * 'Activate', 'Deactivate', and 'Edit', for a network site, and
692                          * 'Activate', 'Deactivate', 'Edit', and 'Delete' for a single site.
693                          *
694                          * @since 2.5.0 As `{$prefix}_plugin_action_links`
695                          * @since 4.4.0
696                          *
697                          * @param array  $actions     An array of plugin action links.
698                          * @param string $plugin_file Path to the plugin file relative to the plugins directory.
699                          * @param array  $plugin_data An array of plugin data.
700                          * @param string $context     The plugin context. Defaults are 'All', 'Active',
701                          *                            'Inactive', 'Recently Activated', 'Upgrade',
702                          *                            'Must-Use', 'Drop-ins', 'Search'.
703                          */
704                         $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
705
706                         /**
707                          * Filters the list of action links displayed for a specific plugin in the Plugins list table.
708                          *
709                          * The dynamic portion of the hook name, $plugin_file, refers to the path
710                          * to the plugin file, relative to the plugins directory.
711                          *
712                          * @since 2.7.0 As `{$prefix}_plugin_action_links_{$plugin_file}`
713                          * @since 4.4.0
714                          *
715                          * @param array  $actions     An array of plugin action links.
716                          * @param string $plugin_file Path to the plugin file relative to the plugins directory.
717                          * @param array  $plugin_data An array of plugin data.
718                          * @param string $context     The plugin context. Defaults are 'All', 'Active',
719                          *                            'Inactive', 'Recently Activated', 'Upgrade',
720                          *                            'Must-Use', 'Drop-ins', 'Search'.
721                          */
722                         $actions = apply_filters( "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );
723
724                 }
725
726                 $class = $is_active ? 'active' : 'inactive';
727                 $checkbox_id =  "checkbox_" . md5($plugin_data['Name']);
728                 if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
729                         $checkbox = '';
730                 } else {
731                         $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . "</label>"
732                                 . "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' />";
733                 }
734                 if ( 'dropins' != $context ) {
735                         $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : '&nbsp;' ) . '</p>';
736                         $plugin_name = $plugin_data['Name'];
737                 }
738
739                 if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) )
740                         $class .= ' update';
741
742                 $plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_name );
743                 printf( '<tr class="%s" data-slug="%s" data-plugin="%s">',
744                         esc_attr( $class ),
745                         esc_attr( $plugin_slug ),
746                         esc_attr( $plugin_file )
747                 );
748
749                 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
750
751                 foreach ( $columns as $column_name => $column_display_name ) {
752                         $extra_classes = '';
753                         if ( in_array( $column_name, $hidden ) ) {
754                                 $extra_classes = ' hidden';
755                         }
756
757                         switch ( $column_name ) {
758                                 case 'cb':
759                                         echo "<th scope='row' class='check-column'>$checkbox</th>";
760                                         break;
761                                 case 'name':
762                                         echo "<td class='plugin-title column-primary'><strong>$plugin_name</strong>";
763                                         echo $this->row_actions( $actions, true );
764                                         echo "</td>";
765                                         break;
766                                 case 'description':
767                                         $classes = 'column-description desc';
768
769                                         echo "<td class='$classes{$extra_classes}'>
770                                                 <div class='plugin-description'>$description</div>
771                                                 <div class='$class second plugin-version-author-uri'>";
772
773                                         $plugin_meta = array();
774                                         if ( !empty( $plugin_data['Version'] ) )
775                                                 $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
776                                         if ( !empty( $plugin_data['Author'] ) ) {
777                                                 $author = $plugin_data['Author'];
778                                                 if ( !empty( $plugin_data['AuthorURI'] ) )
779                                                         $author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>';
780                                                 $plugin_meta[] = sprintf( __( 'By %s' ), $author );
781                                         }
782
783                                         // Details link using API info, if available
784                                         if ( isset( $plugin_data['slug'] ) && current_user_can( 'install_plugins' ) ) {
785                                                 $plugin_meta[] = sprintf( '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
786                                                         esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] .
787                                                                 '&TB_iframe=true&width=600&height=550' ) ),
788                                                         esc_attr( sprintf( __( 'More information about %s' ), $plugin_name ) ),
789                                                         esc_attr( $plugin_name ),
790                                                         __( 'View details' )
791                                                 );
792                                         } elseif ( ! empty( $plugin_data['PluginURI'] ) ) {
793                                                 $plugin_meta[] = sprintf( '<a href="%s">%s</a>',
794                                                         esc_url( $plugin_data['PluginURI'] ),
795                                                         __( 'Visit plugin site' )
796                                                 );
797                                         }
798
799                                         /**
800                                          * Filters the array of row meta for each plugin in the Plugins list table.
801                                          *
802                                          * @since 2.8.0
803                                          *
804                                          * @param array  $plugin_meta An array of the plugin's metadata,
805                                          *                            including the version, author,
806                                          *                            author URI, and plugin URI.
807                                          * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
808                                          * @param array  $plugin_data An array of plugin data.
809                                          * @param string $status      Status of the plugin. Defaults are 'All', 'Active',
810                                          *                            'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
811                                          *                            'Drop-ins', 'Search'.
812                                          */
813                                         $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
814                                         echo implode( ' | ', $plugin_meta );
815
816                                         echo "</div></td>";
817                                         break;
818                                 default:
819                                         $classes = "$column_name column-$column_name $class";
820
821                                         echo "<td class='$classes{$extra_classes}'>";
822
823                                         /**
824                                          * Fires inside each custom column of the Plugins list table.
825                                          *
826                                          * @since 3.1.0
827                                          *
828                                          * @param string $column_name Name of the column.
829                                          * @param string $plugin_file Path to the plugin file.
830                                          * @param array  $plugin_data An array of plugin data.
831                                          */
832                                         do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
833
834                                         echo "</td>";
835                         }
836                 }
837
838                 echo "</tr>";
839
840                 /**
841                  * Fires after each row in the Plugins list table.
842                  *
843                  * @since 2.3.0
844                  *
845                  * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
846                  * @param array  $plugin_data An array of plugin data.
847                  * @param string $status      Status of the plugin. Defaults are 'All', 'Active',
848                  *                            'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
849                  *                            'Drop-ins', 'Search'.
850                  */
851                 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
852
853                 /**
854                  * Fires after each specific row in the Plugins list table.
855                  *
856                  * The dynamic portion of the hook name, `$plugin_file`, refers to the path
857                  * to the plugin file, relative to the plugins directory.
858                  *
859                  * @since 2.7.0
860                  *
861                  * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
862                  * @param array  $plugin_data An array of plugin data.
863                  * @param string $status      Status of the plugin. Defaults are 'All', 'Active',
864                  *                            'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
865                  *                            'Drop-ins', 'Search'.
866                  */
867                 do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status );
868         }
869
870         /**
871          * Gets the name of the primary column for this specific list table.
872          *
873          * @since 4.3.0
874          * @access protected
875          *
876          * @return string Unalterable name for the primary column, in this case, 'name'.
877          */
878         protected function get_primary_column_name() {
879                 return 'name';
880         }
881 }