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