[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/includes/ -> class-wp-plugins-list-table.php (source)

   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   *
  15   * @see WP_List_Table
  16   */
  17  class WP_Plugins_List_Table extends WP_List_Table {
  18      /**
  19       * Whether to show the auto-updates UI.
  20       *
  21       * @since 5.5.0
  22       *
  23       * @var bool True if auto-updates UI is to be shown, false otherwise.
  24       */
  25      protected $show_autoupdates = true;
  26  
  27      /**
  28       * Constructor.
  29       *
  30       * @since 3.1.0
  31       *
  32       * @see WP_List_Table::__construct() for more information on default arguments.
  33       *
  34       * @global string $status
  35       * @global int    $page
  36       *
  37       * @param array $args An associative array of arguments.
  38       */
  39  	public function __construct( $args = array() ) {
  40          global $status, $page;
  41  
  42          parent::__construct(
  43              array(
  44                  'plural' => 'plugins',
  45                  'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
  46              )
  47          );
  48  
  49          $allowed_statuses = array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused', 'auto-update-enabled', 'auto-update-disabled' );
  50  
  51          $status = 'all';
  52          if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], $allowed_statuses, true ) ) {
  53              $status = $_REQUEST['plugin_status'];
  54          }
  55  
  56          if ( isset( $_REQUEST['s'] ) ) {
  57              $_SERVER['REQUEST_URI'] = add_query_arg( 's', wp_unslash( $_REQUEST['s'] ) );
  58          }
  59  
  60          $page = $this->get_pagenum();
  61  
  62          $this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'plugin' )
  63              && current_user_can( 'update_plugins' )
  64              && ( ! is_multisite() || $this->screen->in_admin( 'network' ) );
  65      }
  66  
  67      /**
  68       * @return array
  69       */
  70  	protected function get_table_classes() {
  71          return array( 'widefat', $this->_args['plural'] );
  72      }
  73  
  74      /**
  75       * @return bool
  76       */
  77  	public function ajax_user_can() {
  78          return current_user_can( 'activate_plugins' );
  79      }
  80  
  81      /**
  82       * @global string $status
  83       * @global array  $plugins
  84       * @global array  $totals
  85       * @global int    $page
  86       * @global string $orderby
  87       * @global string $order
  88       * @global string $s
  89       */
  90  	public function prepare_items() {
  91          global $status, $plugins, $totals, $page, $orderby, $order, $s;
  92  
  93          wp_reset_vars( array( 'orderby', 'order' ) );
  94  
  95          /**
  96           * Filters the full array of plugins to list in the Plugins list table.
  97           *
  98           * @since 3.0.0
  99           *
 100           * @see get_plugins()
 101           *
 102           * @param array $all_plugins An array of plugins to display in the list table.
 103           */
 104          $all_plugins = apply_filters( 'all_plugins', get_plugins() );
 105  
 106          $plugins = array(
 107              'all'                => $all_plugins,
 108              'search'             => array(),
 109              'active'             => array(),
 110              'inactive'           => array(),
 111              'recently_activated' => array(),
 112              'upgrade'            => array(),
 113              'mustuse'            => array(),
 114              'dropins'            => array(),
 115              'paused'             => array(),
 116          );
 117          if ( $this->show_autoupdates ) {
 118              $auto_updates = (array) get_site_option( 'auto_update_plugins', array() );
 119  
 120              $plugins['auto-update-enabled']  = array();
 121              $plugins['auto-update-disabled'] = array();
 122          }
 123  
 124          $screen = $this->screen;
 125  
 126          if ( ! is_multisite() || ( $screen->in_admin( 'network' ) && current_user_can( 'manage_network_plugins' ) ) ) {
 127  
 128              /**
 129               * Filters whether to display the advanced plugins list table.
 130               *
 131               * There are two types of advanced plugins - must-use and drop-ins -
 132               * which can be used in a single site or Multisite network.
 133               *
 134               * The $type parameter allows you to differentiate between the type of advanced
 135               * plugins to filter the display of. Contexts include 'mustuse' and 'dropins'.
 136               *
 137               * @since 3.0.0
 138               *
 139               * @param bool   $show Whether to show the advanced plugins for the specified
 140               *                     plugin type. Default true.
 141               * @param string $type The plugin type. Accepts 'mustuse', 'dropins'.
 142               */
 143              if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ) {
 144                  $plugins['mustuse'] = get_mu_plugins();
 145              }
 146  
 147              /** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */
 148              if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) {
 149                  $plugins['dropins'] = get_dropins();
 150              }
 151  
 152              if ( current_user_can( 'update_plugins' ) ) {
 153                  $current = get_site_transient( 'update_plugins' );
 154                  foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
 155                      if ( isset( $current->response[ $plugin_file ] ) ) {
 156                          $plugins['all'][ $plugin_file ]['update'] = true;
 157                          $plugins['upgrade'][ $plugin_file ]       = $plugins['all'][ $plugin_file ];
 158                      }
 159                  }
 160              }
 161          }
 162  
 163          if ( ! $screen->in_admin( 'network' ) ) {
 164              $show = current_user_can( 'manage_network_plugins' );
 165              /**
 166               * Filters whether to display network-active plugins alongside plugins active for the current site.
 167               *
 168               * This also controls the display of inactive network-only plugins (plugins with
 169               * "Network: true" in the plugin header).
 170               *
 171               * Plugins cannot be network-activated or network-deactivated from this screen.
 172               *
 173               * @since 4.4.0
 174               *
 175               * @param bool $show Whether to show network-active plugins. Default is whether the current
 176               *                   user can manage network plugins (ie. a Super Admin).
 177               */
 178              $show_network_active = apply_filters( 'show_network_active_plugins', $show );
 179          }
 180  
 181          if ( $screen->in_admin( 'network' ) ) {
 182              $recently_activated = get_site_option( 'recently_activated', array() );
 183          } else {
 184              $recently_activated = get_option( 'recently_activated', array() );
 185          }
 186  
 187          foreach ( $recently_activated as $key => $time ) {
 188              if ( $time + WEEK_IN_SECONDS < time() ) {
 189                  unset( $recently_activated[ $key ] );
 190              }
 191          }
 192  
 193          if ( $screen->in_admin( 'network' ) ) {
 194              update_site_option( 'recently_activated', $recently_activated );
 195          } else {
 196              update_option( 'recently_activated', $recently_activated );
 197          }
 198  
 199          $plugin_info = get_site_transient( 'update_plugins' );
 200  
 201          foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
 202              // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide.
 203              if ( isset( $plugin_info->response[ $plugin_file ] ) ) {
 204                  $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], array( 'update-supported' => true ), $plugin_data );
 205              } elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) {
 206                  $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], array( 'update-supported' => true ), $plugin_data );
 207              } elseif ( empty( $plugin_data['update-supported'] ) ) {
 208                  $plugin_data['update-supported'] = false;
 209              }
 210  
 211              /*
 212               * Create the payload that's used for the auto_update_plugin filter.
 213               * This is the same data contained within $plugin_info->(response|no_update) however
 214               * not all plugins will be contained in those keys, this avoids unexpected warnings.
 215               */
 216              $filter_payload = array(
 217                  'id'            => $plugin_file,
 218                  'slug'          => '',
 219                  'plugin'        => $plugin_file,
 220                  'new_version'   => '',
 221                  'url'           => '',
 222                  'package'       => '',
 223                  'icons'         => array(),
 224                  'banners'       => array(),
 225                  'banners_rtl'   => array(),
 226                  'tested'        => '',
 227                  'requires_php'  => '',
 228                  'compatibility' => new stdClass(),
 229              );
 230  
 231              $filter_payload = (object) wp_parse_args( $plugin_data, $filter_payload );
 232  
 233              $auto_update_forced = wp_is_auto_update_forced_for_item( 'plugin', null, $filter_payload );
 234  
 235              if ( ! is_null( $auto_update_forced ) ) {
 236                  $plugin_data['auto-update-forced'] = $auto_update_forced;
 237              }
 238  
 239              $plugins['all'][ $plugin_file ] = $plugin_data;
 240              // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade.
 241              if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) {
 242                  $plugins['upgrade'][ $plugin_file ] = $plugin_data;
 243              }
 244  
 245              // Filter into individual sections.
 246              if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) && ! is_plugin_active( $plugin_file ) ) {
 247                  if ( $show_network_active ) {
 248                      // On the non-network screen, show inactive network-only plugins if allowed.
 249                      $plugins['inactive'][ $plugin_file ] = $plugin_data;
 250                  } else {
 251                      // On the non-network screen, filter out network-only plugins as long as they're not individually active.
 252                      unset( $plugins['all'][ $plugin_file ] );
 253                  }
 254              } elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) {
 255                  if ( $show_network_active ) {
 256                      // On the non-network screen, show network-active plugins if allowed.
 257                      $plugins['active'][ $plugin_file ] = $plugin_data;
 258                  } else {
 259                      // On the non-network screen, filter out network-active plugins.
 260                      unset( $plugins['all'][ $plugin_file ] );
 261                  }
 262              } elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) )
 263                  || ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) {
 264                  /*
 265                   * On the non-network screen, populate the active list with plugins that are individually activated.
 266                   * On the network admin screen, populate the active list with plugins that are network-activated.
 267                   */
 268                  $plugins['active'][ $plugin_file ] = $plugin_data;
 269  
 270                  if ( ! $screen->in_admin( 'network' ) && is_plugin_paused( $plugin_file ) ) {
 271                      $plugins['paused'][ $plugin_file ] = $plugin_data;
 272                  }
 273              } else {
 274                  if ( isset( $recently_activated[ $plugin_file ] ) ) {
 275                      // Populate the recently activated list with plugins that have been recently activated.
 276                      $plugins['recently_activated'][ $plugin_file ] = $plugin_data;
 277                  }
 278                  // Populate the inactive list with plugins that aren't activated.
 279                  $plugins['inactive'][ $plugin_file ] = $plugin_data;
 280              }
 281  
 282              if ( $this->show_autoupdates ) {
 283                  $enabled = in_array( $plugin_file, $auto_updates, true ) && $plugin_data['update-supported'];
 284                  if ( isset( $plugin_data['auto-update-forced'] ) ) {
 285                      $enabled = (bool) $plugin_data['auto-update-forced'];
 286                  }
 287  
 288                  if ( $enabled ) {
 289                      $plugins['auto-update-enabled'][ $plugin_file ] = $plugin_data;
 290                  } else {
 291                      $plugins['auto-update-disabled'][ $plugin_file ] = $plugin_data;
 292                  }
 293              }
 294          }
 295  
 296          if ( strlen( $s ) ) {
 297              $status            = 'search';
 298              $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) );
 299          }
 300  
 301          /**
 302           * Filters the array of plugins for the list table.
 303           *
 304           * @since 6.3.0
 305           *
 306           * @param array[] $plugins An array of arrays of plugin data, keyed by context.
 307           */
 308          $plugins = apply_filters( 'plugins_list', $plugins );
 309  
 310          $totals = array();
 311          foreach ( $plugins as $type => $list ) {
 312              $totals[ $type ] = count( $list );
 313          }
 314  
 315          if ( empty( $plugins[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) {
 316              $status = 'all';
 317          }
 318  
 319          $this->items = array();
 320          foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) {
 321              // Translate, don't apply markup, sanitize HTML.
 322              $this->items[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
 323          }
 324  
 325          $total_this_page = $totals[ $status ];
 326  
 327          $js_plugins = array();
 328          foreach ( $plugins as $key => $list ) {
 329              $js_plugins[ $key ] = array_keys( $list );
 330          }
 331  
 332          wp_localize_script(
 333              'updates',
 334              '_wpUpdatesItemCounts',
 335              array(
 336                  'plugins' => $js_plugins,
 337                  'totals'  => wp_get_update_data(),
 338              )
 339          );
 340  
 341          if ( ! $orderby ) {
 342              $orderby = 'Name';
 343          } else {
 344              $orderby = ucfirst( $orderby );
 345          }
 346  
 347          $order = strtoupper( $order );
 348  
 349          uasort( $this->items, array( $this, '_order_callback' ) );
 350  
 351          $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 );
 352  
 353          $start = ( $page - 1 ) * $plugins_per_page;
 354  
 355          if ( $total_this_page > $plugins_per_page ) {
 356              $this->items = array_slice( $this->items, $start, $plugins_per_page );
 357          }
 358  
 359          $this->set_pagination_args(
 360              array(
 361                  'total_items' => $total_this_page,
 362                  'per_page'    => $plugins_per_page,
 363              )
 364          );
 365      }
 366  
 367      /**
 368       * @global string $s URL encoded search term.
 369       *
 370       * @param array $plugin
 371       * @return bool
 372       */
 373  	public function _search_callback( $plugin ) {
 374          global $s;
 375  
 376          foreach ( $plugin as $value ) {
 377              if ( is_string( $value ) && false !== stripos( strip_tags( $value ), urldecode( $s ) ) ) {
 378                  return true;
 379              }
 380          }
 381  
 382          return false;
 383      }
 384  
 385      /**
 386       * @global string $orderby
 387       * @global string $order
 388       * @param array $plugin_a
 389       * @param array $plugin_b
 390       * @return int
 391       */
 392  	public function _order_callback( $plugin_a, $plugin_b ) {
 393          global $orderby, $order;
 394  
 395          $a = $plugin_a[ $orderby ];
 396          $b = $plugin_b[ $orderby ];
 397  
 398          if ( $a === $b ) {
 399              return 0;
 400          }
 401  
 402          if ( 'DESC' === $order ) {
 403              return strcasecmp( $b, $a );
 404          } else {
 405              return strcasecmp( $a, $b );
 406          }
 407      }
 408  
 409      /**
 410       * @global array $plugins
 411       */
 412  	public function no_items() {
 413          global $plugins;
 414  
 415          if ( ! empty( $_REQUEST['s'] ) ) {
 416              $s = esc_html( urldecode( wp_unslash( $_REQUEST['s'] ) ) );
 417  
 418              /* translators: %s: Plugin search term. */
 419              printf( __( 'No plugins found for: %s.' ), '<strong>' . $s . '</strong>' );
 420  
 421              // We assume that somebody who can install plugins in multisite is experienced enough to not need this helper link.
 422              if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) {
 423                  echo ' <a href="' . esc_url( admin_url( 'plugin-install.php?tab=search&s=' . urlencode( $s ) ) ) . '">' . __( 'Search for plugins in the WordPress Plugin Directory.' ) . '</a>';
 424              }
 425          } elseif ( ! empty( $plugins['all'] ) ) {
 426              _e( 'No plugins found.' );
 427          } else {
 428              _e( 'No plugins are currently available.' );
 429          }
 430      }
 431  
 432      /**
 433       * Displays the search box.
 434       *
 435       * @since 4.6.0
 436       *
 437       * @param string $text     The 'submit' button label.
 438       * @param string $input_id ID attribute value for the search input field.
 439       */
 440  	public function search_box( $text, $input_id ) {
 441          if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
 442              return;
 443          }
 444  
 445          $input_id = $input_id . '-search-input';
 446  
 447          if ( ! empty( $_REQUEST['orderby'] ) ) {
 448              echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
 449          }
 450          if ( ! empty( $_REQUEST['order'] ) ) {
 451              echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
 452          }
 453          ?>
 454          <p class="search-box">
 455              <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label>
 456              <input type="search" id="<?php echo esc_attr( $input_id ); ?>" class="wp-filter-search" name="s" value="<?php _admin_search_query(); ?>" placeholder="<?php esc_attr_e( 'Search installed plugins...' ); ?>" />
 457              <?php submit_button( $text, 'hide-if-js', '', false, array( 'id' => 'search-submit' ) ); ?>
 458          </p>
 459          <?php
 460      }
 461  
 462      /**
 463       * @global string $status
 464       *
 465       * @return string[] Array of column titles keyed by their column name.
 466       */
 467  	public function get_columns() {
 468          global $status;
 469  
 470          $columns = array(
 471              'cb'          => ! in_array( $status, array( 'mustuse', 'dropins' ), true ) ? '<input type="checkbox" />' : '',
 472              'name'        => __( 'Plugin' ),
 473              'description' => __( 'Description' ),
 474          );
 475  
 476          if ( $this->show_autoupdates && ! in_array( $status, array( 'mustuse', 'dropins' ), true ) ) {
 477              $columns['auto-updates'] = __( 'Automatic Updates' );
 478          }
 479  
 480          return $columns;
 481      }
 482  
 483      /**
 484       * @return array
 485       */
 486  	protected function get_sortable_columns() {
 487          return array();
 488      }
 489  
 490      /**
 491       * @global array $totals
 492       * @global string $status
 493       * @return array
 494       */
 495  	protected function get_views() {
 496          global $totals, $status;
 497  
 498          $status_links = array();
 499          foreach ( $totals as $type => $count ) {
 500              if ( ! $count ) {
 501                  continue;
 502              }
 503  
 504              switch ( $type ) {
 505                  case 'all':
 506                      /* translators: %s: Number of plugins. */
 507                      $text = _nx(
 508                          'All <span class="count">(%s)</span>',
 509                          'All <span class="count">(%s)</span>',
 510                          $count,
 511                          'plugins'
 512                      );
 513                      break;
 514                  case 'active':
 515                      /* translators: %s: Number of plugins. */
 516                      $text = _n(
 517                          'Active <span class="count">(%s)</span>',
 518                          'Active <span class="count">(%s)</span>',
 519                          $count
 520                      );
 521                      break;
 522                  case 'recently_activated':
 523                      /* translators: %s: Number of plugins. */
 524                      $text = _n(
 525                          'Recently Active <span class="count">(%s)</span>',
 526                          'Recently Active <span class="count">(%s)</span>',
 527                          $count
 528                      );
 529                      break;
 530                  case 'inactive':
 531                      /* translators: %s: Number of plugins. */
 532                      $text = _n(
 533                          'Inactive <span class="count">(%s)</span>',
 534                          'Inactive <span class="count">(%s)</span>',
 535                          $count
 536                      );
 537                      break;
 538                  case 'mustuse':
 539                      /* translators: %s: Number of plugins. */
 540                      $text = _n(
 541                          'Must-Use <span class="count">(%s)</span>',
 542                          'Must-Use <span class="count">(%s)</span>',
 543                          $count
 544                      );
 545                      break;
 546                  case 'dropins':
 547                      /* translators: %s: Number of plugins. */
 548                      $text = _n(
 549                          'Drop-in <span class="count">(%s)</span>',
 550                          'Drop-ins <span class="count">(%s)</span>',
 551                          $count
 552                      );
 553                      break;
 554                  case 'paused':
 555                      /* translators: %s: Number of plugins. */
 556                      $text = _n(
 557                          'Paused <span class="count">(%s)</span>',
 558                          'Paused <span class="count">(%s)</span>',
 559                          $count
 560                      );
 561                      break;
 562                  case 'upgrade':
 563                      /* translators: %s: Number of plugins. */
 564                      $text = _n(
 565                          'Update Available <span class="count">(%s)</span>',
 566                          'Update Available <span class="count">(%s)</span>',
 567                          $count
 568                      );
 569                      break;
 570                  case 'auto-update-enabled':
 571                      /* translators: %s: Number of plugins. */
 572                      $text = _n(
 573                          'Auto-updates Enabled <span class="count">(%s)</span>',
 574                          'Auto-updates Enabled <span class="count">(%s)</span>',
 575                          $count
 576                      );
 577                      break;
 578                  case 'auto-update-disabled':
 579                      /* translators: %s: Number of plugins. */
 580                      $text = _n(
 581                          'Auto-updates Disabled <span class="count">(%s)</span>',
 582                          'Auto-updates Disabled <span class="count">(%s)</span>',
 583                          $count
 584                      );
 585                      break;
 586              }
 587  
 588              if ( 'search' !== $type ) {
 589                  $status_links[ $type ] = array(
 590                      'url'     => add_query_arg( 'plugin_status', $type, 'plugins.php' ),
 591                      'label'   => sprintf( $text, number_format_i18n( $count ) ),
 592                      'current' => $type === $status,
 593                  );
 594              }
 595          }
 596  
 597          return $this->get_views_links( $status_links );
 598      }
 599  
 600      /**
 601       * @global string $status
 602       * @return array
 603       */
 604  	protected function get_bulk_actions() {
 605          global $status;
 606  
 607          $actions = array();
 608  
 609          if ( 'active' !== $status ) {
 610              $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? _x( 'Network Activate', 'plugin' ) : _x( 'Activate', 'plugin' );
 611          }
 612  
 613          if ( 'inactive' !== $status && 'recent' !== $status ) {
 614              $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? _x( 'Network Deactivate', 'plugin' ) : _x( 'Deactivate', 'plugin' );
 615          }
 616  
 617          if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) {
 618              if ( current_user_can( 'update_plugins' ) ) {
 619                  $actions['update-selected'] = __( 'Update' );
 620              }
 621  
 622              if ( current_user_can( 'delete_plugins' ) && ( 'active' !== $status ) ) {
 623                  $actions['delete-selected'] = __( 'Delete' );
 624              }
 625  
 626              if ( $this->show_autoupdates ) {
 627                  if ( 'auto-update-enabled' !== $status ) {
 628                      $actions['enable-auto-update-selected'] = __( 'Enable Auto-updates' );
 629                  }
 630                  if ( 'auto-update-disabled' !== $status ) {
 631                      $actions['disable-auto-update-selected'] = __( 'Disable Auto-updates' );
 632                  }
 633              }
 634          }
 635  
 636          return $actions;
 637      }
 638  
 639      /**
 640       * @global string $status
 641       * @param string $which
 642       */
 643  	public function bulk_actions( $which = '' ) {
 644          global $status;
 645  
 646          if ( in_array( $status, array( 'mustuse', 'dropins' ), true ) ) {
 647              return;
 648          }
 649  
 650          parent::bulk_actions( $which );
 651      }
 652  
 653      /**
 654       * @global string $status
 655       * @param string $which
 656       */
 657  	protected function extra_tablenav( $which ) {
 658          global $status;
 659  
 660          if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ), true ) ) {
 661              return;
 662          }
 663  
 664          echo '<div class="alignleft actions">';
 665  
 666          if ( 'recently_activated' === $status ) {
 667              submit_button( __( 'Clear List' ), '', 'clear-recent-list', false );
 668          } elseif ( 'top' === $which && 'mustuse' === $status ) {
 669              echo '<p>' . sprintf(
 670                  /* translators: %s: mu-plugins directory name. */
 671                  __( 'Files in the %s directory are executed automatically.' ),
 672                  '<code>' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . '</code>'
 673              ) . '</p>';
 674          } elseif ( 'top' === $which && 'dropins' === $status ) {
 675              echo '<p>' . sprintf(
 676                  /* translators: %s: wp-content directory name. */
 677                  __( 'Drop-ins are single files, found in the %s directory, that replace or enhance WordPress features in ways that are not possible for traditional plugins.' ),
 678                  '<code>' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '</code>'
 679              ) . '</p>';
 680          }
 681          echo '</div>';
 682      }
 683  
 684      /**
 685       * @return string
 686       */
 687  	public function current_action() {
 688          if ( isset( $_POST['clear-recent-list'] ) ) {
 689              return 'clear-recent-list';
 690          }
 691  
 692          return parent::current_action();
 693      }
 694  
 695      /**
 696       * @global string $status
 697       */
 698  	public function display_rows() {
 699          global $status;
 700  
 701          if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ), true ) ) {
 702              return;
 703          }
 704  
 705          foreach ( $this->items as $plugin_file => $plugin_data ) {
 706              $this->single_row( array( $plugin_file, $plugin_data ) );
 707          }
 708      }
 709  
 710      /**
 711       * @global string $status
 712       * @global int $page
 713       * @global string $s
 714       * @global array $totals
 715       *
 716       * @param array $item
 717       */
 718  	public function single_row( $item ) {
 719          global $status, $page, $s, $totals;
 720          static $plugin_id_attrs = array();
 721  
 722          list( $plugin_file, $plugin_data ) = $item;
 723  
 724          $plugin_slug    = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_data['Name'] );
 725          $plugin_id_attr = $plugin_slug;
 726  
 727          // Ensure the ID attribute is unique.
 728          $suffix = 2;
 729          while ( in_array( $plugin_id_attr, $plugin_id_attrs, true ) ) {
 730              $plugin_id_attr = "$plugin_slug-$suffix";
 731              ++$suffix;
 732          }
 733  
 734          $plugin_id_attrs[] = $plugin_id_attr;
 735  
 736          $context = $status;
 737          $screen  = $this->screen;
 738  
 739          // Pre-order.
 740          $actions = array(
 741              'deactivate' => '',
 742              'activate'   => '',
 743              'details'    => '',
 744              'delete'     => '',
 745          );
 746  
 747          // Do not restrict by default.
 748          $restrict_network_active = false;
 749          $restrict_network_only   = false;
 750  
 751          $requires_php = isset( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : null;
 752          $requires_wp  = isset( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : null;
 753  
 754          $compatible_php = is_php_version_compatible( $requires_php );
 755          $compatible_wp  = is_wp_version_compatible( $requires_wp );
 756  
 757          $has_dependents          = WP_Plugin_Dependencies::has_dependents( $plugin_file );
 758          $has_active_dependents   = WP_Plugin_Dependencies::has_active_dependents( $plugin_file );
 759          $has_unmet_dependencies  = WP_Plugin_Dependencies::has_unmet_dependencies( $plugin_file );
 760          $has_circular_dependency = WP_Plugin_Dependencies::has_circular_dependency( $plugin_file );
 761  
 762          if ( 'mustuse' === $context ) {
 763              $is_active = true;
 764          } elseif ( 'dropins' === $context ) {
 765              $dropins     = _get_dropins();
 766              $plugin_name = $plugin_file;
 767  
 768              if ( $plugin_file !== $plugin_data['Name'] ) {
 769                  $plugin_name .= '<br />' . $plugin_data['Name'];
 770              }
 771  
 772              if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant.
 773                  $is_active   = true;
 774                  $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
 775              } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true.
 776                  $is_active   = true;
 777                  $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
 778              } else {
 779                  $is_active   = false;
 780                  $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="error-message">' . __( 'Inactive:' ) . '</span></strong> ' .
 781                      sprintf(
 782                          /* translators: 1: Drop-in constant name, 2: wp-config.php */
 783                          __( 'Requires %1$s in %2$s file.' ),
 784                          "<code>define('" . $dropins[ $plugin_file ][1] . "', true);</code>",
 785                          '<code>wp-config.php</code>'
 786                      ) . '</p>';
 787              }
 788  
 789              if ( $plugin_data['Description'] ) {
 790                  $description .= '<p>' . $plugin_data['Description'] . '</p>';
 791              }
 792          } else {
 793              if ( $screen->in_admin( 'network' ) ) {
 794                  $is_active = is_plugin_active_for_network( $plugin_file );
 795              } else {
 796                  $is_active               = is_plugin_active( $plugin_file );
 797                  $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) );
 798                  $restrict_network_only   = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active );
 799              }
 800  
 801              if ( $screen->in_admin( 'network' ) ) {
 802                  if ( $is_active ) {
 803                      if ( current_user_can( 'manage_network_plugins' ) ) {
 804                          if ( $has_active_dependents ) {
 805                              $actions['deactivate'] = __( 'Deactivate' ) .
 806                                  '<span class="screen-reader-text">' .
 807                                  __( 'You cannot deactivate this plugin as other plugins require it.' ) .
 808                                  '</span>';
 809  
 810                          } else {
 811                              $deactivate_url = 'plugins.php?action=deactivate' .
 812                                  '&amp;plugin=' . urlencode( $plugin_file ) .
 813                                  '&amp;plugin_status=' . $context .
 814                                  '&amp;paged=' . $page .
 815                                  '&amp;s=' . $s;
 816  
 817                              $actions['deactivate'] = sprintf(
 818                                  '<a href="%s" id="deactivate-%s" aria-label="%s">%s</a>',
 819                                  wp_nonce_url( $deactivate_url, 'deactivate-plugin_' . $plugin_file ),
 820                                  esc_attr( $plugin_id_attr ),
 821                                  /* translators: %s: Plugin name. */
 822                                  esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ),
 823                                  _x( 'Network Deactivate', 'plugin' )
 824                              );
 825                          }
 826                      }
 827                  } else {
 828                      if ( current_user_can( 'manage_network_plugins' ) ) {
 829                          if ( $compatible_php && $compatible_wp ) {
 830                              if ( $has_unmet_dependencies ) {
 831                                  $actions['activate'] = _x( 'Network Activate', 'plugin' ) .
 832                                      '<span class="screen-reader-text">' .
 833                                      __( 'You cannot activate this plugin as it has unmet requirements.' ) .
 834                                      '</span>';
 835                              } else {
 836                                  $activate_url = 'plugins.php?action=activate' .
 837                                      '&amp;plugin=' . urlencode( $plugin_file ) .
 838                                      '&amp;plugin_status=' . $context .
 839                                      '&amp;paged=' . $page .
 840                                      '&amp;s=' . $s;
 841  
 842                                  $actions['activate'] = sprintf(
 843                                      '<a href="%s" id="activate-%s" class="edit" aria-label="%s">%s</a>',
 844                                      wp_nonce_url( $activate_url, 'activate-plugin_' . $plugin_file ),
 845                                      esc_attr( $plugin_id_attr ),
 846                                      /* translators: %s: Plugin name. */
 847                                      esc_attr( sprintf( _x( 'Network Activate %s', 'plugin' ), $plugin_data['Name'] ) ),
 848                                      _x( 'Network Activate', 'plugin' )
 849                                  );
 850                              }
 851                          } else {
 852                              $actions['activate'] = sprintf(
 853                                  '<span>%s</span>',
 854                                  _x( 'Cannot Activate', 'plugin' )
 855                              );
 856                          }
 857                      }
 858  
 859                      if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) {
 860                          if ( $has_dependents && ! $has_circular_dependency ) {
 861                              $actions['delete'] = __( 'Delete' ) .
 862                                  '<span class="screen-reader-text">' .
 863                                  __( 'You cannot delete this plugin as other plugins require it.' ) .
 864                                  '</span>';
 865                          } else {
 866                              $delete_url = 'plugins.php?action=delete-selected' .
 867                                  '&amp;checked[]=' . urlencode( $plugin_file ) .
 868                                  '&amp;plugin_status=' . $context .
 869                                  '&amp;paged=' . $page .
 870                                  '&amp;s=' . $s;
 871  
 872                              $actions['delete'] = sprintf(
 873                                  '<a href="%s" id="delete-%s" class="delete" aria-label="%s">%s</a>',
 874                                  wp_nonce_url( $delete_url, 'bulk-plugins' ),
 875                                  esc_attr( $plugin_id_attr ),
 876                                  /* translators: %s: Plugin name. */
 877                                  esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ),
 878                                  __( 'Delete' )
 879                              );
 880                          }
 881                      }
 882                  }
 883              } else {
 884                  if ( $restrict_network_active ) {
 885                      $actions = array(
 886                          'network_active' => __( 'Network Active' ),
 887                      );
 888                  } elseif ( $restrict_network_only ) {
 889                      $actions = array(
 890                          'network_only' => __( 'Network Only' ),
 891                      );
 892                  } elseif ( $is_active ) {
 893                      if ( current_user_can( 'deactivate_plugin', $plugin_file ) ) {
 894                          if ( $has_active_dependents ) {
 895                              $actions['deactivate'] = __( 'Deactivate' ) .
 896                                  '<span class="screen-reader-text">' .
 897                                  __( 'You cannot deactivate this plugin as other plugins depend on it.' ) .
 898                                  '</span>';
 899                          } else {
 900                              $deactivate_url = 'plugins.php?action=deactivate' .
 901                                  '&amp;plugin=' . urlencode( $plugin_file ) .
 902                                  '&amp;plugin_status=' . $context .
 903                                  '&amp;paged=' . $page .
 904                                  '&amp;s=' . $s;
 905  
 906                              $actions['deactivate'] = sprintf(
 907                                  '<a href="%s" id="deactivate-%s" aria-label="%s">%s</a>',
 908                                  wp_nonce_url( $deactivate_url, 'deactivate-plugin_' . $plugin_file ),
 909                                  esc_attr( $plugin_id_attr ),
 910                                  /* translators: %s: Plugin name. */
 911                                  esc_attr( sprintf( _x( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ),
 912                                  __( 'Deactivate' )
 913                              );
 914                          }
 915                      }
 916  
 917                      if ( current_user_can( 'resume_plugin', $plugin_file ) && is_plugin_paused( $plugin_file ) ) {
 918                          $resume_url = 'plugins.php?action=resume' .
 919                              '&amp;plugin=' . urlencode( $plugin_file ) .
 920                              '&amp;plugin_status=' . $context .
 921                              '&amp;paged=' . $page .
 922                              '&amp;s=' . $s;
 923  
 924                          $actions['resume'] = sprintf(
 925                              '<a href="%s" id="resume-%s" class="resume-link" aria-label="%s">%s</a>',
 926                              wp_nonce_url( $resume_url, 'resume-plugin_' . $plugin_file ),
 927                              esc_attr( $plugin_id_attr ),
 928                              /* translators: %s: Plugin name. */
 929                              esc_attr( sprintf( _x( 'Resume %s', 'plugin' ), $plugin_data['Name'] ) ),
 930                              __( 'Resume' )
 931                          );
 932                      }
 933                  } else {
 934                      if ( current_user_can( 'activate_plugin', $plugin_file ) ) {
 935                          if ( $compatible_php && $compatible_wp ) {
 936                              if ( $has_unmet_dependencies ) {
 937                                  $actions['activate'] = _x( 'Activate', 'plugin' ) .
 938                                      '<span class="screen-reader-text">' .
 939                                      __( 'You cannot activate this plugin as it has unmet requirements.' ) .
 940                                      '</span>';
 941                              } else {
 942                                  $activate_url = 'plugins.php?action=activate' .
 943                                      '&amp;plugin=' . urlencode( $plugin_file ) .
 944                                      '&amp;plugin_status=' . $context .
 945                                      '&amp;paged=' . $page .
 946                                      '&amp;s=' . $s;
 947  
 948                                  $actions['activate'] = sprintf(
 949                                      '<a href="%s" id="activate-%s" class="edit" aria-label="%s">%s</a>',
 950                                      wp_nonce_url( $activate_url, 'activate-plugin_' . $plugin_file ),
 951                                      esc_attr( $plugin_id_attr ),
 952                                      /* translators: %s: Plugin name. */
 953                                      esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ),
 954                                      _x( 'Activate', 'plugin' )
 955                                  );
 956                              }
 957                          } else {
 958                              $actions['activate'] = sprintf(
 959                                  '<span>%s</span>',
 960                                  _x( 'Cannot Activate', 'plugin' )
 961                              );
 962                          }
 963                      }
 964  
 965                      if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) {
 966                          if ( $has_dependents && ! $has_circular_dependency ) {
 967                              $actions['delete'] = __( 'Delete' ) .
 968                                  '<span class="screen-reader-text">' .
 969                                  __( 'You cannot delete this plugin as other plugins require it.' ) .
 970                                  '</span>';
 971                          } else {
 972                              $delete_url = 'plugins.php?action=delete-selected' .
 973                                  '&amp;checked[]=' . urlencode( $plugin_file ) .
 974                                  '&amp;plugin_status=' . $context .
 975                                  '&amp;paged=' . $page .
 976                                  '&amp;s=' . $s;
 977  
 978                              $actions['delete'] = sprintf(
 979                                  '<a href="%s" id="delete-%s" class="delete" aria-label="%s">%s</a>',
 980                                  wp_nonce_url( $delete_url, 'bulk-plugins' ),
 981                                  esc_attr( $plugin_id_attr ),
 982                                  /* translators: %s: Plugin name. */
 983                                  esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ),
 984                                  __( 'Delete' )
 985                              );
 986                          }
 987                      }
 988                  } // End if $is_active.
 989              } // End if $screen->in_admin( 'network' ).
 990          } // End if $context.
 991  
 992          $actions = array_filter( $actions );
 993  
 994          if ( $screen->in_admin( 'network' ) ) {
 995  
 996              /**
 997               * Filters the action links displayed for each plugin in the Network Admin Plugins list table.
 998               *
 999               * @since 3.1.0
1000               *
1001               * @param string[] $actions     An array of plugin action links. By default this can include
1002               *                              'activate', 'deactivate', and 'delete'.
1003               * @param string   $plugin_file Path to the plugin file relative to the plugins directory.
1004               * @param array    $plugin_data An array of plugin data. See get_plugin_data()
1005               *                              and the {@see 'plugin_row_meta'} filter for the list
1006               *                              of possible values.
1007               * @param string   $context     The plugin context. By default this can include 'all',
1008               *                              'active', 'inactive', 'recently_activated', 'upgrade',
1009               *                              'mustuse', 'dropins', and 'search'.
1010               */
1011              $actions = apply_filters( 'network_admin_plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
1012  
1013              /**
1014               * Filters the list of action links displayed for a specific plugin in the Network Admin Plugins list table.
1015               *
1016               * The dynamic portion of the hook name, `$plugin_file`, refers to the path
1017               * to the plugin file, relative to the plugins directory.
1018               *
1019               * @since 3.1.0
1020               *
1021               * @param string[] $actions     An array of plugin action links. By default this can include
1022               *                              'activate', 'deactivate', and 'delete'.
1023               * @param string   $plugin_file Path to the plugin file relative to the plugins directory.
1024               * @param array    $plugin_data An array of plugin data. See get_plugin_data()
1025               *                              and the {@see 'plugin_row_meta'} filter for the list
1026               *                              of possible values.
1027               * @param string   $context     The plugin context. By default this can include 'all',
1028               *                              'active', 'inactive', 'recently_activated', 'upgrade',
1029               *                              'mustuse', 'dropins', and 'search'.
1030               */
1031              $actions = apply_filters( "network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );
1032  
1033          } else {
1034  
1035              /**
1036               * Filters the action links displayed for each plugin in the Plugins list table.
1037               *
1038               * @since 2.5.0
1039               * @since 2.6.0 The `$context` parameter was added.
1040               * @since 4.9.0 The 'Edit' link was removed from the list of action links.
1041               *
1042               * @param string[] $actions     An array of plugin action links. By default this can include
1043               *                              'activate', 'deactivate', and 'delete'. With Multisite active
1044               *                              this can also include 'network_active' and 'network_only' items.
1045               * @param string   $plugin_file Path to the plugin file relative to the plugins directory.
1046               * @param array    $plugin_data An array of plugin data. See get_plugin_data()
1047               *                              and the {@see 'plugin_row_meta'} filter for the list
1048               *                              of possible values.
1049               * @param string   $context     The plugin context. By default this can include 'all',
1050               *                              'active', 'inactive', 'recently_activated', 'upgrade',
1051               *                              'mustuse', 'dropins', and 'search'.
1052               */
1053              $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
1054  
1055              /**
1056               * Filters the list of action links displayed for a specific plugin in the Plugins list table.
1057               *
1058               * The dynamic portion of the hook name, `$plugin_file`, refers to the path
1059               * to the plugin file, relative to the plugins directory.
1060               *
1061               * @since 2.7.0
1062               * @since 4.9.0 The 'Edit' link was removed from the list of action links.
1063               *
1064               * @param string[] $actions     An array of plugin action links. By default this can include
1065               *                              'activate', 'deactivate', and 'delete'. With Multisite active
1066               *                              this can also include 'network_active' and 'network_only' items.
1067               * @param string   $plugin_file Path to the plugin file relative to the plugins directory.
1068               * @param array    $plugin_data An array of plugin data. See get_plugin_data()
1069               *                              and the {@see 'plugin_row_meta'} filter for the list
1070               *                              of possible values.
1071               * @param string   $context     The plugin context. By default this can include 'all',
1072               *                              'active', 'inactive', 'recently_activated', 'upgrade',
1073               *                              'mustuse', 'dropins', and 'search'.
1074               */
1075              $actions = apply_filters( "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );
1076  
1077          }
1078  
1079          $class       = $is_active ? 'active' : 'inactive';
1080          $checkbox_id = 'checkbox_' . md5( $plugin_file );
1081          $disabled    = '';
1082  
1083          if ( $has_dependents || $has_unmet_dependencies ) {
1084              $disabled = 'disabled';
1085          }
1086  
1087          if (
1088              $restrict_network_active ||
1089              $restrict_network_only ||
1090              in_array( $status, array( 'mustuse', 'dropins' ), true ) ||
1091              ! $compatible_php
1092          ) {
1093              $checkbox = '';
1094          } else {
1095              $checkbox = sprintf(
1096                  '<label class="label-covers-full-cell" for="%1$s">' .
1097                  '<span class="screen-reader-text">%2$s</span></label>' .
1098                  '<input type="checkbox" name="checked[]" value="%3$s" id="%1$s" ' . $disabled . '/>',
1099                  $checkbox_id,
1100                  /* translators: Hidden accessibility text. %s: Plugin name. */
1101                  sprintf( __( 'Select %s' ), $plugin_data['Name'] ),
1102                  esc_attr( $plugin_file )
1103              );
1104          }
1105  
1106          if ( 'dropins' !== $context ) {
1107              $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : '&nbsp;' ) . '</p>';
1108              $plugin_name = $plugin_data['Name'];
1109          }
1110  
1111          if (
1112              ! empty( $totals['upgrade'] ) &&
1113              ! empty( $plugin_data['update'] ) ||
1114              ! $compatible_php ||
1115              ! $compatible_wp
1116          ) {
1117              $class .= ' update';
1118          }
1119  
1120          $paused = ! $screen->in_admin( 'network' ) && is_plugin_paused( $plugin_file );
1121  
1122          if ( $paused ) {
1123              $class .= ' paused';
1124          }
1125  
1126          if ( is_uninstallable_plugin( $plugin_file ) ) {
1127              $class .= ' is-uninstallable';
1128          }
1129  
1130          printf(
1131              '<tr class="%s" data-slug="%s" data-plugin="%s">',
1132              esc_attr( $class ),
1133              esc_attr( $plugin_slug ),
1134              esc_attr( $plugin_file )
1135          );
1136  
1137          list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1138  
1139          $auto_updates = (array) get_site_option( 'auto_update_plugins', array() );
1140  
1141          foreach ( $columns as $column_name => $column_display_name ) {
1142              $extra_classes = '';
1143              if ( in_array( $column_name, $hidden, true ) ) {
1144                  $extra_classes = ' hidden';
1145              }
1146  
1147              switch ( $column_name ) {
1148                  case 'cb':
1149                      echo "<th scope='row' class='check-column'>$checkbox</th>";
1150                      break;
1151                  case 'name':
1152                      echo "<td class='plugin-title column-primary'><strong>$plugin_name</strong>";
1153                      echo $this->row_actions( $actions, true );
1154                      echo '</td>';
1155                      break;
1156                  case 'description':
1157                      $classes = 'column-description desc';
1158  
1159                      echo "<td class='$classes{$extra_classes}'>
1160                          <div class='plugin-description'>$description</div>
1161                          <div class='$class second plugin-version-author-uri'>";
1162  
1163                      $plugin_meta = array();
1164  
1165                      if ( ! empty( $plugin_data['Version'] ) ) {
1166                          /* translators: %s: Plugin version number. */
1167                          $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
1168                      }
1169  
1170                      if ( ! empty( $plugin_data['Author'] ) ) {
1171                          $author = $plugin_data['Author'];
1172  
1173                          if ( ! empty( $plugin_data['AuthorURI'] ) ) {
1174                              $author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>';
1175                          }
1176  
1177                          /* translators: %s: Plugin author name. */
1178                          $plugin_meta[] = sprintf( __( 'By %s' ), $author );
1179                      }
1180  
1181                      // Details link using API info, if available.
1182                      if ( isset( $plugin_data['slug'] ) && current_user_can( 'install_plugins' ) ) {
1183                          $plugin_meta[] = sprintf(
1184                              '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
1185                              esc_url(
1186                                  network_admin_url(
1187                                      'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] .
1188                                      '&TB_iframe=true&width=600&height=550'
1189                                  )
1190                              ),
1191                              /* translators: %s: Plugin name. */
1192                              esc_attr( sprintf( __( 'More information about %s' ), $plugin_name ) ),
1193                              esc_attr( $plugin_name ),
1194                              __( 'View details' )
1195                          );
1196                      } elseif ( ! empty( $plugin_data['PluginURI'] ) ) {
1197                          /* translators: %s: Plugin name. */
1198                          $aria_label = sprintf( __( 'Visit plugin site for %s' ), $plugin_name );
1199  
1200                          $plugin_meta[] = sprintf(
1201                              '<a href="%s" aria-label="%s">%s</a>',
1202                              esc_url( $plugin_data['PluginURI'] ),
1203                              esc_attr( $aria_label ),
1204                              __( 'Visit plugin site' )
1205                          );
1206                      }
1207  
1208                      /**
1209                       * Filters the array of row meta for each plugin in the Plugins list table.
1210                       *
1211                       * @since 2.8.0
1212                       *
1213                       * @param string[] $plugin_meta An array of the plugin's metadata, including
1214                       *                              the version, author, author URI, and plugin URI.
1215                       * @param string   $plugin_file Path to the plugin file relative to the plugins directory.
1216                       * @param array    $plugin_data {
1217                       *     An array of plugin data.
1218                       *
1219                       *     @type string   $id               Plugin ID, e.g. `w.org/plugins/[plugin-name]`.
1220                       *     @type string   $slug             Plugin slug.
1221                       *     @type string   $plugin           Plugin basename.
1222                       *     @type string   $new_version      New plugin version.
1223                       *     @type string   $url              Plugin URL.
1224                       *     @type string   $package          Plugin update package URL.
1225                       *     @type string[] $icons            An array of plugin icon URLs.
1226                       *     @type string[] $banners          An array of plugin banner URLs.
1227                       *     @type string[] $banners_rtl      An array of plugin RTL banner URLs.
1228                       *     @type string   $requires         The version of WordPress which the plugin requires.
1229                       *     @type string   $tested           The version of WordPress the plugin is tested against.
1230                       *     @type string   $requires_php     The version of PHP which the plugin requires.
1231                       *     @type string   $upgrade_notice   The upgrade notice for the new plugin version.
1232                       *     @type bool     $update-supported Whether the plugin supports updates.
1233                       *     @type string   $Name             The human-readable name of the plugin.
1234                       *     @type string   $PluginURI        Plugin URI.
1235                       *     @type string   $Version          Plugin version.
1236                       *     @type string   $Description      Plugin description.
1237                       *     @type string   $Author           Plugin author.
1238                       *     @type string   $AuthorURI        Plugin author URI.
1239                       *     @type string   $TextDomain       Plugin textdomain.
1240                       *     @type string   $DomainPath       Relative path to the plugin's .mo file(s).
1241                       *     @type bool     $Network          Whether the plugin can only be activated network-wide.
1242                       *     @type string   $RequiresWP       The version of WordPress which the plugin requires.
1243                       *     @type string   $RequiresPHP      The version of PHP which the plugin requires.
1244                       *     @type string   $UpdateURI        ID of the plugin for update purposes, should be a URI.
1245                       *     @type string   $Title            The human-readable title of the plugin.
1246                       *     @type string   $AuthorName       Plugin author's name.
1247                       *     @type bool     $update           Whether there's an available update. Default null.
1248                       * }
1249                       * @param string   $status      Status filter currently applied to the plugin list. Possible
1250                       *                              values are: 'all', 'active', 'inactive', 'recently_activated',
1251                       *                              'upgrade', 'mustuse', 'dropins', 'search', 'paused',
1252                       *                              'auto-update-enabled', 'auto-update-disabled'.
1253                       */
1254                      $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
1255  
1256                      echo implode( ' | ', $plugin_meta );
1257  
1258                      echo '</div>';
1259  
1260                      if ( $has_dependents ) {
1261                          $this->add_dependents_to_dependency_plugin_row( $plugin_file );
1262                      }
1263  
1264                      if ( WP_Plugin_Dependencies::has_dependencies( $plugin_file ) ) {
1265                          $this->add_dependencies_to_dependent_plugin_row( $plugin_file );
1266                      }
1267  
1268                      /**
1269                       * Fires after plugin row meta.
1270                       *
1271                       * @since 6.5.0
1272                       *
1273                       * @param string $plugin_file Refer to {@see 'plugin_row_meta'} filter.
1274                       * @param array  $plugin_data Refer to {@see 'plugin_row_meta'} filter.
1275                       */
1276                      do_action( 'after_plugin_row_meta', $plugin_file, $plugin_data );
1277  
1278                      if ( $paused ) {
1279                          $notice_text = __( 'This plugin failed to load properly and is paused during recovery mode.' );
1280  
1281                          printf( '<p><span class="dashicons dashicons-warning"></span> <strong>%s</strong></p>', $notice_text );
1282  
1283                          $error = wp_get_plugin_error( $plugin_file );
1284  
1285                          if ( false !== $error ) {
1286                              printf( '<div class="error-display"><p>%s</p></div>', wp_get_extension_error_description( $error ) );
1287                          }
1288                      }
1289  
1290                      echo '</td>';
1291                      break;
1292                  case 'auto-updates':
1293                      if ( ! $this->show_autoupdates || in_array( $status, array( 'mustuse', 'dropins' ), true ) ) {
1294                          break;
1295                      }
1296  
1297                      echo "<td class='column-auto-updates{$extra_classes}'>";
1298  
1299                      $html = array();
1300  
1301                      if ( isset( $plugin_data['auto-update-forced'] ) ) {
1302                          if ( $plugin_data['auto-update-forced'] ) {
1303                              // Forced on.
1304                              $text = __( 'Auto-updates enabled' );
1305                          } else {
1306                              $text = __( 'Auto-updates disabled' );
1307                          }
1308                          $action     = 'unavailable';
1309                          $time_class = ' hidden';
1310                      } elseif ( empty( $plugin_data['update-supported'] ) ) {
1311                          $text       = '';
1312                          $action     = 'unavailable';
1313                          $time_class = ' hidden';
1314                      } elseif ( in_array( $plugin_file, $auto_updates, true ) ) {
1315                          $text       = __( 'Disable auto-updates' );
1316                          $action     = 'disable';
1317                          $time_class = '';
1318                      } else {
1319                          $text       = __( 'Enable auto-updates' );
1320                          $action     = 'enable';
1321                          $time_class = ' hidden';
1322                      }
1323  
1324                      $query_args = array(
1325                          'action'        => "{$action}-auto-update",
1326                          'plugin'        => $plugin_file,
1327                          'paged'         => $page,
1328                          'plugin_status' => $status,
1329                      );
1330  
1331                      $url = add_query_arg( $query_args, 'plugins.php' );
1332  
1333                      if ( 'unavailable' === $action ) {
1334                          $html[] = '<span class="label">' . $text . '</span>';
1335                      } else {
1336                          $html[] = sprintf(
1337                              '<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">',
1338                              wp_nonce_url( $url, 'updates' ),
1339                              $action
1340                          );
1341  
1342                          $html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
1343                          $html[] = '<span class="label">' . $text . '</span>';
1344                          $html[] = '</a>';
1345                      }
1346  
1347                      if ( ! empty( $plugin_data['update'] ) ) {
1348                          $html[] = sprintf(
1349                              '<div class="auto-update-time%s">%s</div>',
1350                              $time_class,
1351                              wp_get_auto_update_message()
1352                          );
1353                      }
1354  
1355                      $html = implode( '', $html );
1356  
1357                      /**
1358                       * Filters the HTML of the auto-updates setting for each plugin in the Plugins list table.
1359                       *
1360                       * @since 5.5.0
1361                       *
1362                       * @param string $html        The HTML of the plugin's auto-update column content,
1363                       *                            including toggle auto-update action links and
1364                       *                            time to next update.
1365                       * @param string $plugin_file Path to the plugin file relative to the plugins directory.
1366                       * @param array  $plugin_data An array of plugin data. See get_plugin_data()
1367                       *                            and the {@see 'plugin_row_meta'} filter for the list
1368                       *                            of possible values.
1369                       */
1370                      echo apply_filters( 'plugin_auto_update_setting_html', $html, $plugin_file, $plugin_data );
1371  
1372                      wp_admin_notice(
1373                          '',
1374                          array(
1375                              'type'               => 'error',
1376                              'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ),
1377                          )
1378                      );
1379  
1380                      echo '</td>';
1381  
1382                      break;
1383                  default:
1384                      $classes = "$column_name column-$column_name $class";
1385  
1386                      echo "<td class='$classes{$extra_classes}'>";
1387  
1388                      /**
1389                       * Fires inside each custom column of the Plugins list table.
1390                       *
1391                       * @since 3.1.0
1392                       *
1393                       * @param string $column_name Name of the column.
1394                       * @param string $plugin_file Path to the plugin file relative to the plugins directory.
1395                       * @param array  $plugin_data An array of plugin data. See get_plugin_data()
1396                       *                            and the {@see 'plugin_row_meta'} filter for the list
1397                       *                            of possible values.
1398                       */
1399                      do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
1400  
1401                      echo '</td>';
1402              }
1403          }
1404  
1405          echo '</tr>';
1406  
1407          if ( ! $compatible_php || ! $compatible_wp ) {
1408              printf(
1409                  '<tr class="plugin-update-tr"><td colspan="%s" class="plugin-update colspanchange">',
1410                  esc_attr( $this->get_column_count() )
1411              );
1412  
1413              $incompatible_message = '';
1414              if ( ! $compatible_php && ! $compatible_wp ) {
1415                  $incompatible_message .= __( 'This plugin does not work with your versions of WordPress and PHP.' );
1416                  if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
1417                      $incompatible_message .= sprintf(
1418                          /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
1419                          ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
1420                          self_admin_url( 'update-core.php' ),
1421                          esc_url( wp_get_update_php_url() )
1422                      );
1423                      $incompatible_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
1424                  } elseif ( current_user_can( 'update_core' ) ) {
1425                      $incompatible_message .= sprintf(
1426                          /* translators: %s: URL to WordPress Updates screen. */
1427                          ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
1428                          self_admin_url( 'update-core.php' )
1429                      );
1430                  } elseif ( current_user_can( 'update_php' ) ) {
1431                      $incompatible_message .= sprintf(
1432                          /* translators: %s: URL to Update PHP page. */
1433                          ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
1434                          esc_url( wp_get_update_php_url() )
1435                      );
1436                      $incompatible_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
1437                  }
1438              } elseif ( ! $compatible_wp ) {
1439                  $incompatible_message .= __( 'This plugin does not work with your version of WordPress.' );
1440                  if ( current_user_can( 'update_core' ) ) {
1441                      $incompatible_message .= sprintf(
1442                          /* translators: %s: URL to WordPress Updates screen. */
1443                          ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
1444                          self_admin_url( 'update-core.php' )
1445                      );
1446                  }
1447              } elseif ( ! $compatible_php ) {
1448                  $incompatible_message .= __( 'This plugin does not work with your version of PHP.' );
1449                  if ( current_user_can( 'update_php' ) ) {
1450                      $incompatible_message .= sprintf(
1451                          /* translators: %s: URL to Update PHP page. */
1452                          ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
1453                          esc_url( wp_get_update_php_url() )
1454                      );
1455                      $incompatible_message .= wp_update_php_annotation( '</p><p><em>', '</em>', false );
1456                  }
1457              }
1458  
1459              wp_admin_notice(
1460                  $incompatible_message,
1461                  array(
1462                      'type'               => 'error',
1463                      'additional_classes' => array( 'notice-alt', 'inline', 'update-message' ),
1464                  )
1465              );
1466  
1467              echo '</td></tr>';
1468          }
1469  
1470          /**
1471           * Fires after each row in the Plugins list table.
1472           *
1473           * @since 2.3.0
1474           * @since 5.5.0 Added 'auto-update-enabled' and 'auto-update-disabled'
1475           *              to possible values for `$status`.
1476           *
1477           * @param string $plugin_file Path to the plugin file relative to the plugins directory.
1478           * @param array  $plugin_data An array of plugin data. See get_plugin_data()
1479           *                            and the {@see 'plugin_row_meta'} filter for the list
1480           *                            of possible values.
1481           * @param string $status      Status filter currently applied to the plugin list.
1482           *                            Possible values are: 'all', 'active', 'inactive',
1483           *                            'recently_activated', 'upgrade', 'mustuse', 'dropins',
1484           *                            'search', 'paused', 'auto-update-enabled', 'auto-update-disabled'.
1485           */
1486          do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
1487  
1488          /**
1489           * Fires after each specific row in the Plugins list table.
1490           *
1491           * The dynamic portion of the hook name, `$plugin_file`, refers to the path
1492           * to the plugin file, relative to the plugins directory.
1493           *
1494           * @since 2.7.0
1495           * @since 5.5.0 Added 'auto-update-enabled' and 'auto-update-disabled'
1496           *              to possible values for `$status`.
1497           *
1498           * @param string $plugin_file Path to the plugin file relative to the plugins directory.
1499           * @param array  $plugin_data An array of plugin data. See get_plugin_data()
1500           *                            and the {@see 'plugin_row_meta'} filter for the list
1501           *                            of possible values.
1502           * @param string $status      Status filter currently applied to the plugin list.
1503           *                            Possible values are: 'all', 'active', 'inactive',
1504           *                            'recently_activated', 'upgrade', 'mustuse', 'dropins',
1505           *                            'search', 'paused', 'auto-update-enabled', 'auto-update-disabled'.
1506           */
1507          do_action( "after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $status );
1508      }
1509  
1510      /**
1511       * Gets the name of the primary column for this specific list table.
1512       *
1513       * @since 4.3.0
1514       *
1515       * @return string Unalterable name for the primary column, in this case, 'name'.
1516       */
1517  	protected function get_primary_column_name() {
1518          return 'name';
1519      }
1520  
1521      /**
1522       * Prints a list of other plugins that depend on the plugin.
1523       *
1524       * @since 6.5.0
1525       *
1526       * @param string $dependency The dependency's filepath, relative to the plugins directory.
1527       */
1528  	protected function add_dependents_to_dependency_plugin_row( $dependency ) {
1529          $dependent_names = WP_Plugin_Dependencies::get_dependent_names( $dependency );
1530  
1531          if ( empty( $dependent_names ) ) {
1532              return;
1533          }
1534  
1535          $dependency_note = __( 'Note: This plugin cannot be deactivated or deleted until the plugins that require it are deactivated or deleted.' );
1536  
1537          $comma       = wp_get_list_item_separator();
1538          $required_by = sprintf(
1539              /* translators: %s: List of dependencies. */
1540              __( '<strong>Required by:</strong> %s' ),
1541              implode( $comma, $dependent_names )
1542          );
1543  
1544          printf(
1545              '<div class="required-by"><p>%1$s</p><p>%2$s</p></div>',
1546              $required_by,
1547              $dependency_note
1548          );
1549      }
1550  
1551      /**
1552       * Prints a list of other plugins that the plugin depends on.
1553       *
1554       * @since 6.5.0
1555       *
1556       * @param string $dependent The dependent plugin's filepath, relative to the plugins directory.
1557       */
1558  	protected function add_dependencies_to_dependent_plugin_row( $dependent ) {
1559          $dependency_names = WP_Plugin_Dependencies::get_dependency_names( $dependent );
1560  
1561          if ( array() === $dependency_names ) {
1562              return;
1563          }
1564  
1565          $links = array();
1566          foreach ( $dependency_names as $slug => $name ) {
1567              $links[] = $this->get_dependency_view_details_link( $name, $slug );
1568          }
1569  
1570          $is_active = is_multisite() ? is_plugin_active_for_network( $dependent ) : is_plugin_active( $dependent );
1571          $comma     = wp_get_list_item_separator();
1572          $requires  = sprintf(
1573              /* translators: %s: List of dependency names. */
1574              __( '<strong>Requires:</strong> %s' ),
1575              implode( $comma, $links )
1576          );
1577  
1578          $notice        = '';
1579          $error_message = '';
1580          if ( WP_Plugin_Dependencies::has_unmet_dependencies( $dependent ) ) {
1581              if ( $is_active ) {
1582                  $error_message = __( 'This plugin is active but may not function correctly because required plugins are missing or inactive.' );
1583              } else {
1584                  $error_message = __( 'This plugin cannot be activated because required plugins are missing or inactive.' );
1585              }
1586              $notice = wp_get_admin_notice(
1587                  $error_message,
1588                  array(
1589                      'type'               => 'error',
1590                      'additional_classes' => array( 'inline', 'notice-alt' ),
1591                  )
1592              );
1593          }
1594  
1595          printf(
1596              '<div class="requires"><p>%1$s</p><p>%2$s</p></div>',
1597              $requires,
1598              $notice
1599          );
1600      }
1601  
1602      /**
1603       * Returns a 'View details' like link for a dependency.
1604       *
1605       * @since 6.5.0
1606       *
1607       * @param string $name The dependency's name.
1608       * @param string $slug The dependency's slug.
1609       * @return string A 'View details' link for the dependency.
1610       */
1611  	protected function get_dependency_view_details_link( $name, $slug ) {
1612          $dependency_data = WP_Plugin_Dependencies::get_dependency_data( $slug );
1613  
1614          if ( false === $dependency_data
1615              || $name === $slug
1616              || $name !== $dependency_data['name']
1617              || empty( $dependency_data['version'] )
1618          ) {
1619              return $name;
1620          }
1621  
1622          return $this->get_view_details_link( $name, $slug );
1623      }
1624  
1625      /**
1626       * Returns a 'View details' link for the plugin.
1627       *
1628       * @since 6.5.0
1629       *
1630       * @param string $name The plugin's name.
1631       * @param string $slug The plugin's slug.
1632       * @return string A 'View details' link for the plugin.
1633       */
1634  	protected function get_view_details_link( $name, $slug ) {
1635          $url = add_query_arg(
1636              array(
1637                  'tab'       => 'plugin-information',
1638                  'plugin'    => $slug,
1639                  'TB_iframe' => 'true',
1640                  'width'     => '600',
1641                  'height'    => '550',
1642              ),
1643              network_admin_url( 'plugin-install.php' )
1644          );
1645  
1646          $name_attr = esc_attr( $name );
1647          return sprintf(
1648              "<a href='%s' class='thickbox open-plugin-details-modal' aria-label='%s' data-title='%s'>%s</a>",
1649              esc_url( $url ),
1650              /* translators: %s: Plugin name. */
1651              sprintf( __( 'More information about %s' ), $name_attr ),
1652              $name_attr,
1653              esc_html( $name )
1654          );
1655      }
1656  }


Generated : Tue Mar 19 08:20:01 2024 Cross-referenced by PHPXref