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