[ 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   * @access private
  15   *
  16   * @see WP_List_Table
  17   */
  18  class WP_Plugins_List_Table extends WP_List_Table {
  19      /**
  20       * Whether to show the auto-updates UI.
  21       *
  22       * @since 5.5.0
  23       *
  24       * @var bool True if auto-updates UI is to be shown, false otherwise.
  25       */
  26      protected $show_autoupdates = true;
  27  
  28      /**
  29       * Constructor.
  30       *
  31       * @since 3.1.0
  32       *
  33       * @see WP_List_Table::__construct() for more information on default arguments.
  34       *
  35       * @global string $status
  36       * @global int    $page
  37       *
  38       * @param array $args An associative array of arguments.
  39       */
  40  	public function __construct( $args = array() ) {
  41          global $status, $page;
  42  
  43          parent::__construct(
  44              array(
  45                  'plural' => 'plugins',
  46                  'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
  47              )
  48          );
  49  
  50          $status_whitelist = array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused', 'auto-update-enabled', 'auto-update-disabled' );
  51  
  52          $status = 'all';
  53          if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], $status_whitelist, true ) ) {
  54              $status = $_REQUEST['plugin_status'];
  55          }
  56  
  57          if ( isset( $_REQUEST['s'] ) ) {
  58              $_SERVER['REQUEST_URI'] = add_query_arg( 's', wp_unslash( $_REQUEST['s'] ) );
  59          }
  60  
  61          $page = $this->get_pagenum();
  62  
  63          $this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'plugin' ) &&
  64              current_user_can( 'update_plugins' ) &&
  65              ( ! is_multisite() || $this->screen->in_admin( 'network' ) );
  66      }
  67  
  68      /**
  69       * @return array
  70       */
  71  	protected function get_table_classes() {
  72          return array( 'widefat', $this->_args['plural'] );
  73      }
  74  
  75      /**
  76       * @return bool
  77       */
  78  	public function ajax_user_can() {
  79          return current_user_can( 'activate_plugins' );
  80      }
  81  
  82      /**
  83       * @global string $status
  84       * @global array  $plugins
  85       * @global array  $totals
  86       * @global int    $page
  87       * @global string $orderby
  88       * @global string $order
  89       * @global string $s
  90       */
  91  	public function prepare_items() {
  92          global $status, $plugins, $totals, $page, $orderby, $order, $s;
  93  
  94          wp_reset_vars( array( 'orderby', 'order' ) );
  95  
  96          /**
  97           * Filters the full array of plugins to list in the Plugins list table.
  98           *
  99           * @since 3.0.0
 100           *
 101           * @see get_plugins()
 102           *
 103           * @param array $all_plugins An array of plugins to display in the list table.
 104           */
 105          $all_plugins = apply_filters( 'all_plugins', get_plugins() );
 106  
 107          $plugins = array(
 108              'all'                => $all_plugins,
 109              'search'             => array(),
 110              'active'             => array(),
 111              'inactive'           => array(),
 112              'recently_activated' => array(),
 113              'upgrade'            => array(),
 114              'mustuse'            => array(),
 115              'dropins'            => array(),
 116              'paused'             => array(),
 117          );
 118          if ( $this->show_autoupdates ) {
 119              $auto_updates = (array) get_site_option( 'auto_update_plugins', array() );
 120  
 121              $plugins['auto-update-enabled']  = array();
 122              $plugins['auto-update-disabled'] = array();
 123          }
 124  
 125          $screen = $this->screen;
 126  
 127          if ( ! is_multisite() || ( $screen->in_admin( 'network' ) && current_user_can( 'manage_network_plugins' ) ) ) {
 128  
 129              /**
 130               * Filters whether to display the advanced plugins list table.
 131               *
 132               * There are two types of advanced plugins - must-use and drop-ins -
 133               * which can be used in a single site or Multisite network.
 134               *
 135               * The $type parameter allows you to differentiate between the type of advanced
 136               * plugins to filter the display of. Contexts include 'mustuse' and 'dropins'.
 137               *
 138               * @since 3.0.0
 139               *
 140               * @param bool   $show Whether to show the advanced plugins for the specified
 141               *                     plugin type. Default true.
 142               * @param string $type The plugin type. Accepts 'mustuse', 'dropins'.
 143               */
 144              if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ) {
 145                  $plugins['mustuse'] = get_mu_plugins();
 146              }
 147  
 148              /** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */
 149              if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) {
 150                  $plugins['dropins'] = get_dropins();
 151              }
 152  
 153              if ( current_user_can( 'update_plugins' ) ) {
 154                  $current = get_site_transient( 'update_plugins' );
 155                  foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
 156                      if ( isset( $current->response[ $plugin_file ] ) ) {
 157                          $plugins['all'][ $plugin_file ]['update'] = true;
 158                          $plugins['upgrade'][ $plugin_file ]       = $plugins['all'][ $plugin_file ];
 159                      }
 160                  }
 161              }
 162          }
 163  
 164          if ( ! $screen->in_admin( 'network' ) ) {
 165              $show = current_user_can( 'manage_network_plugins' );
 166              /**
 167               * Filters whether to display network-active plugins alongside plugins active for the current site.
 168               *
 169               * This also controls the display of inactive network-only plugins (plugins with
 170               * "Network: true" in the plugin header).
 171               *
 172               * Plugins cannot be network-activated or network-deactivated from this screen.
 173               *
 174               * @since 4.4.0
 175               *
 176               * @param bool $show Whether to show network-active plugins. Default is whether the current
 177               *                   user can manage network plugins (ie. a Super Admin).
 178               */
 179              $show_network_active = apply_filters( 'show_network_active_plugins', $show );
 180          }
 181  
 182          if ( $screen->in_admin( 'network' ) ) {
 183              $recently_activated = get_site_option( 'recently_activated', array() );
 184          } else {
 185              $recently_activated = get_option( 'recently_activated', array() );
 186          }
 187  
 188          foreach ( $recently_activated as $key => $time ) {
 189              if ( $time + WEEK_IN_SECONDS < time() ) {
 190                  unset( $recently_activated[ $key ] );
 191              }
 192          }
 193  
 194          if ( $screen->in_admin( 'network' ) ) {
 195              update_site_option( 'recently_activated', $recently_activated );
 196          } else {
 197              update_option( 'recently_activated', $recently_activated );
 198          }
 199  
 200          $plugin_info = get_site_transient( 'update_plugins' );
 201  
 202          foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
 203              // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide.
 204              if ( isset( $plugin_info->response[ $plugin_file ] ) ) {
 205                  $plugin_data                    = array_merge( (array) $plugin_info->response[ $plugin_file ], $plugin_data );
 206                  $plugins['all'][ $plugin_file ] = $plugin_data;
 207                  // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade.
 208                  if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) {
 209                      $plugins['upgrade'][ $plugin_file ] = $plugin_data;
 210                  }
 211              } elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) {
 212                  $plugin_data                    = array_merge( (array) $plugin_info->no_update[ $plugin_file ], $plugin_data );
 213                  $plugins['all'][ $plugin_file ] = $plugin_data;
 214                  // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade.
 215                  if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) {
 216                      $plugins['upgrade'][ $plugin_file ] = $plugin_data;
 217                  }
 218              }
 219  
 220              // Filter into individual sections.
 221              if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) && ! is_plugin_active( $plugin_file ) ) {
 222                  if ( $show_network_active ) {
 223                      // On the non-network screen, show inactive network-only plugins if allowed.
 224                      $plugins['inactive'][ $plugin_file ] = $plugin_data;
 225                  } else {
 226                      // On the non-network screen, filter out network-only plugins as long as they're not individually active.
 227                      unset( $plugins['all'][ $plugin_file ] );
 228                  }
 229              } elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) {
 230                  if ( $show_network_active ) {
 231                      // On the non-network screen, show network-active plugins if allowed.
 232                      $plugins['active'][ $plugin_file ] = $plugin_data;
 233                  } else {
 234                      // On the non-network screen, filter out network-active plugins.
 235                      unset( $plugins['all'][ $plugin_file ] );
 236                  }
 237              } elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) )
 238                  || ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) {
 239                  // On the non-network screen, populate the active list with plugins that are individually activated.
 240                  // On the network admin screen, populate the active list with plugins that are network-activated.
 241                  $plugins['active'][ $plugin_file ] = $plugin_data;
 242  
 243                  if ( ! $screen->in_admin( 'network' ) && is_plugin_paused( $plugin_file ) ) {
 244                      $plugins['paused'][ $plugin_file ] = $plugin_data;
 245                  }
 246              } else {
 247                  if ( isset( $recently_activated[ $plugin_file ] ) ) {
 248                      // Populate the recently activated list with plugins that have been recently activated.
 249                      $plugins['recently_activated'][ $plugin_file ] = $plugin_data;
 250                  }
 251                  // Populate the inactive list with plugins that aren't activated.
 252                  $plugins['inactive'][ $plugin_file ] = $plugin_data;
 253              }
 254  
 255              if ( $this->show_autoupdates ) {
 256                  if ( in_array( $plugin_file, $auto_updates, true ) ) {
 257                      $plugins['auto-update-enabled'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
 258                  } else {
 259                      $plugins['auto-update-disabled'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
 260                  }
 261              }
 262          }
 263  
 264          if ( strlen( $s ) ) {
 265              $status            = 'search';
 266              $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) );
 267          }
 268  
 269          $totals = array();
 270          foreach ( $plugins as $type => $list ) {
 271              $totals[ $type ] = count( $list );
 272          }
 273  
 274          if ( empty( $plugins[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) {
 275              $status = 'all';
 276          }
 277  
 278          $this->items = array();
 279          foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) {
 280              // Translate, don't apply markup, sanitize HTML.
 281              $this->items[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
 282          }
 283  
 284          $total_this_page = $totals[ $status ];
 285  
 286          $js_plugins = array();
 287          foreach ( $plugins as $key => $list ) {
 288              $js_plugins[ $key ] = array_keys( (array) $list );
 289          }
 290  
 291          wp_localize_script(
 292              'updates',
 293              '_wpUpdatesItemCounts',
 294              array(
 295                  'plugins' => $js_plugins,
 296                  'totals'  => wp_get_update_data(),
 297              )
 298          );
 299  
 300          if ( ! $orderby ) {
 301              $orderby = 'Name';
 302          } else {
 303              $orderby = ucfirst( $orderby );
 304          }
 305  
 306          $order = strtoupper( $order );
 307  
 308          uasort( $this->items, array( $this, '_order_callback' ) );
 309  
 310          $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 );
 311  
 312          $start = ( $page - 1 ) * $plugins_per_page;
 313  
 314          if ( $total_this_page > $plugins_per_page ) {
 315              $this->items = array_slice( $this->items, $start, $plugins_per_page );
 316          }
 317  
 318          $this->set_pagination_args(
 319              array(
 320                  'total_items' => $total_this_page,
 321                  'per_page'    => $plugins_per_page,
 322              )
 323          );
 324      }
 325  
 326      /**
 327       * @global string $s URL encoded search term.
 328       *
 329       * @param array $plugin
 330       * @return bool
 331       */
 332  	public function _search_callback( $plugin ) {
 333          global $s;
 334  
 335          foreach ( $plugin as $value ) {
 336              if ( is_string( $value ) && false !== stripos( strip_tags( $value ), urldecode( $s ) ) ) {
 337                  return true;
 338              }
 339          }
 340  
 341          return false;
 342      }
 343  
 344      /**
 345       * @global string $orderby
 346       * @global string $order
 347       * @param array $plugin_a
 348       * @param array $plugin_b
 349       * @return int
 350       */
 351  	public function _order_callback( $plugin_a, $plugin_b ) {
 352          global $orderby, $order;
 353  
 354          $a = $plugin_a[ $orderby ];
 355          $b = $plugin_b[ $orderby ];
 356  
 357          if ( $a == $b ) {
 358              return 0;
 359          }
 360  
 361          if ( 'DESC' === $order ) {
 362              return strcasecmp( $b, $a );
 363          } else {
 364              return strcasecmp( $a, $b );
 365          }
 366      }
 367  
 368      /**
 369       * @global array $plugins
 370       */
 371  	public function no_items() {
 372          global $plugins;
 373  
 374          if ( ! empty( $_REQUEST['s'] ) ) {
 375              $s = esc_html( wp_unslash( $_REQUEST['s'] ) );
 376  
 377              /* translators: %s: Plugin search term. */
 378              printf( __( 'No plugins found for &#8220;%s&#8221;.' ), $s );
 379  
 380              // We assume that somebody who can install plugins in multisite is experienced enough to not need this helper link.
 381              if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) {
 382                  echo ' <a href="' . esc_url( admin_url( 'plugin-install.php?tab=search&s=' . urlencode( $s ) ) ) . '">' . __( 'Search for plugins in the WordPress Plugin Directory.' ) . '</a>';
 383              }
 384          } elseif ( ! empty( $plugins['all'] ) ) {
 385              _e( 'No plugins found.' );
 386          } else {
 387              _e( 'You do not appear to have any plugins available at this time.' );
 388          }
 389      }
 390  
 391      /**
 392       * Displays the search box.
 393       *
 394       * @since 4.6.0
 395       *
 396       * @param string $text     The 'submit' button label.
 397       * @param string $input_id ID attribute value for the search input field.
 398       */
 399  	public function search_box( $text, $input_id ) {
 400          if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
 401              return;
 402          }
 403  
 404          $input_id = $input_id . '-search-input';
 405  
 406          if ( ! empty( $_REQUEST['orderby'] ) ) {
 407              echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
 408          }
 409          if ( ! empty( $_REQUEST['order'] ) ) {
 410              echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
 411          }
 412          ?>
 413          <p class="search-box">
 414              <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label>
 415              <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...' ); ?>"/>
 416              <?php submit_button( $text, 'hide-if-js', '', false, array( 'id' => 'search-submit' ) ); ?>
 417          </p>
 418          <?php
 419      }
 420  
 421      /**
 422       * @global string $status
 423       * @return array
 424       */
 425  	public function get_columns() {
 426          global $status;
 427  
 428          $columns = array(
 429              'cb'          => ! in_array( $status, array( 'mustuse', 'dropins' ), true ) ? '<input type="checkbox" />' : '',
 430              'name'        => __( 'Plugin' ),
 431              'description' => __( 'Description' ),
 432          );
 433  
 434          if ( $this->show_autoupdates ) {
 435              $columns['auto-updates'] = __( 'Automatic Updates' );
 436          }
 437  
 438          return $columns;
 439      }
 440  
 441      /**
 442       * @return array
 443       */
 444  	protected function get_sortable_columns() {
 445          return array();
 446      }
 447  
 448      /**
 449       * @global array $totals
 450       * @global string $status
 451       * @return array
 452       */
 453  	protected function get_views() {
 454          global $totals, $status;
 455  
 456          $status_links = array();
 457          foreach ( $totals as $type => $count ) {
 458              if ( ! $count ) {
 459                  continue;
 460              }
 461  
 462              switch ( $type ) {
 463                  case 'all':
 464                      /* translators: %s: Number of plugins. */
 465                      $text = _nx(
 466                          'All <span class="count">(%s)</span>',
 467                          'All <span class="count">(%s)</span>',
 468                          $count,
 469                          'plugins'
 470                      );
 471                      break;
 472                  case 'active':
 473                      /* translators: %s: Number of plugins. */
 474                      $text = _n(
 475                          'Active <span class="count">(%s)</span>',
 476                          'Active <span class="count">(%s)</span>',
 477                          $count
 478                      );
 479                      break;
 480                  case 'recently_activated':
 481                      /* translators: %s: Number of plugins. */
 482                      $text = _n(
 483                          'Recently Active <span class="count">(%s)</span>',
 484                          'Recently Active <span class="count">(%s)</span>',
 485                          $count
 486                      );
 487                      break;
 488                  case 'inactive':
 489                      /* translators: %s: Number of plugins. */
 490                      $text = _n(
 491                          'Inactive <span class="count">(%s)</span>',
 492                          'Inactive <span class="count">(%s)</span>',
 493                          $count
 494                      );
 495                      break;
 496                  case 'mustuse':
 497                      /* translators: %s: Number of plugins. */
 498                      $text = _n(
 499                          'Must-Use <span class="count">(%s)</span>',
 500                          'Must-Use <span class="count">(%s)</span>',
 501                          $count
 502                      );
 503                      break;
 504                  case 'dropins':
 505                      /* translators: %s: Number of plugins. */
 506                      $text = _n(
 507                          'Drop-in <span class="count">(%s)</span>',
 508                          'Drop-ins <span class="count">(%s)</span>',
 509                          $count
 510                      );
 511                      break;
 512                  case 'paused':
 513                      /* translators: %s: Number of plugins. */
 514                      $text = _n(
 515                          'Paused <span class="count">(%s)</span>',
 516                          'Paused <span class="count">(%s)</span>',
 517                          $count
 518                      );
 519                      break;
 520                  case 'upgrade':
 521                      /* translators: %s: Number of plugins. */
 522                      $text = _n(
 523                          'Update Available <span class="count">(%s)</span>',
 524                          'Update Available <span class="count">(%s)</span>',
 525                          $count
 526                      );
 527                      break;
 528                  case 'auto-update-enabled':
 529                      /* translators: %s: Number of plugins. */
 530                      $text = _n(
 531                          'Auto-updates Enabled <span class="count">(%s)</span>',
 532                          'Auto-updates Enabled <span class="count">(%s)</span>',
 533                          $count
 534                      );
 535                      break;
 536                  case 'auto-update-disabled':
 537                      /* translators: %s: Number of plugins. */
 538                      $text = _n(
 539                          'Auto-updates Disabled <span class="count">(%s)</span>',
 540                          'Auto-updates Disabled <span class="count">(%s)</span>',
 541                          $count
 542                      );
 543                      break;
 544              }
 545  
 546              if ( 'search' !== $type ) {
 547                  $status_links[ $type ] = sprintf(
 548                      "<a href='%s'%s>%s</a>",
 549                      add_query_arg( 'plugin_status', $type, 'plugins.php' ),
 550                      ( $type === $status ) ? ' class="current" aria-current="page"' : '',
 551                      sprintf( $text, number_format_i18n( $count ) )
 552                  );
 553              }
 554          }
 555  
 556          return $status_links;
 557      }
 558  
 559      /**
 560       * @global string $status
 561       * @return array
 562       */
 563  	protected function get_bulk_actions() {
 564          global $status;
 565  
 566          $actions = array();
 567  
 568          if ( 'active' !== $status ) {
 569              $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' );
 570          }
 571  
 572          if ( 'inactive' !== $status && 'recent' !== $status ) {
 573              $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' );
 574          }
 575  
 576          if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) {
 577              if ( current_user_can( 'update_plugins' ) ) {
 578                  $actions['update-selected'] = __( 'Update' );
 579              }
 580  
 581              if ( current_user_can( 'delete_plugins' ) && ( 'active' !== $status ) ) {
 582                  $actions['delete-selected'] = __( 'Delete' );
 583              }
 584  
 585              if ( $this->show_autoupdates ) {
 586                  if ( 'auto-update-enabled' !== $status ) {
 587                      $actions['enable-auto-update-selected'] = __( 'Enable Auto-updates' );
 588                  }
 589                  if ( 'auto-update-disabled' !== $status ) {
 590                      $actions['disable-auto-update-selected'] = __( 'Disable Auto-updates' );
 591                  }
 592              }
 593          }
 594  
 595          return $actions;
 596      }
 597  
 598      /**
 599       * @global string $status
 600       * @param string $which
 601       */
 602  	public function bulk_actions( $which = '' ) {
 603          global $status;
 604  
 605          if ( in_array( $status, array( 'mustuse', 'dropins' ), true ) ) {
 606              return;
 607          }
 608  
 609          parent::bulk_actions( $which );
 610      }
 611  
 612      /**
 613       * @global string $status
 614       * @param string $which
 615       */
 616  	protected function extra_tablenav( $which ) {
 617          global $status;
 618  
 619          if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ), true ) ) {
 620              return;
 621          }
 622  
 623          echo '<div class="alignleft actions">';
 624  
 625          if ( 'recently_activated' === $status ) {
 626              submit_button( __( 'Clear List' ), '', 'clear-recent-list', false );
 627          } elseif ( 'top' === $which && 'mustuse' === $status ) {
 628              echo '<p>' . sprintf(
 629                  /* translators: %s: mu-plugins directory name. */
 630                  __( 'Files in the %s directory are executed automatically.' ),
 631                  '<code>' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . '</code>'
 632              ) . '</p>';
 633          } elseif ( 'top' === $which && 'dropins' === $status ) {
 634              echo '<p>' . sprintf(
 635                  /* translators: %s: wp-content directory name. */
 636                  __( '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.' ),
 637                  '<code>' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '</code>'
 638              ) . '</p>';
 639          }
 640          echo '</div>';
 641      }
 642  
 643      /**
 644       * @return string
 645       */
 646  	public function current_action() {
 647          if ( isset( $_POST['clear-recent-list'] ) ) {
 648              return 'clear-recent-list';
 649          }
 650  
 651          return parent::current_action();
 652      }
 653  
 654      /**
 655       * @global string $status
 656       */
 657  	public function display_rows() {
 658          global $status;
 659  
 660          if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ), true ) ) {
 661              return;
 662          }
 663  
 664          foreach ( $this->items as $plugin_file => $plugin_data ) {
 665              $this->single_row( array( $plugin_file, $plugin_data ) );
 666          }
 667      }
 668  
 669      /**
 670       * @global string $status
 671       * @global int $page
 672       * @global string $s
 673       * @global array $totals
 674       *
 675       * @param array $item
 676       */
 677  	public function single_row( $item ) {
 678          global $status, $page, $s, $totals;
 679  
 680          list( $plugin_file, $plugin_data ) = $item;
 681  
 682          $plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_data['Name'] );
 683  
 684          $context = $status;
 685          $screen  = $this->screen;
 686  
 687          // Pre-order.
 688          $actions = array(
 689              'deactivate' => '',
 690              'activate'   => '',
 691              'details'    => '',
 692              'delete'     => '',
 693          );
 694  
 695          // Do not restrict by default.
 696          $restrict_network_active = false;
 697          $restrict_network_only   = false;
 698  
 699          if ( 'mustuse' === $context ) {
 700              $is_active = true;
 701          } elseif ( 'dropins' === $context ) {
 702              $dropins     = _get_dropins();
 703              $plugin_name = $plugin_file;
 704              if ( $plugin_file != $plugin_data['Name'] ) {
 705                  $plugin_name .= '<br/>' . $plugin_data['Name'];
 706              }
 707              if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant.
 708                  $is_active   = true;
 709                  $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
 710              } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true.
 711                  $is_active   = true;
 712                  $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
 713              } else {
 714                  $is_active   = false;
 715                  $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="error-message">' . __( 'Inactive:' ) . '</span></strong> ' .
 716                      sprintf(
 717                          /* translators: 1: Drop-in constant name, 2: wp-config.php */
 718                          __( 'Requires %1$s in %2$s file.' ),
 719                          "<code>define('" . $dropins[ $plugin_file ][1] . "', true);</code>",
 720                          '<code>wp-config.php</code>'
 721                      ) . '</p>';
 722              }
 723              if ( $plugin_data['Description'] ) {
 724                  $description .= '<p>' . $plugin_data['Description'] . '</p>';
 725              }
 726          } else {
 727              if ( $screen->in_admin( 'network' ) ) {
 728                  $is_active = is_plugin_active_for_network( $plugin_file );
 729              } else {
 730                  $is_active               = is_plugin_active( $plugin_file );
 731                  $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) );
 732                  $restrict_network_only   = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active );
 733              }
 734  
 735              if ( $screen->in_admin( 'network' ) ) {
 736                  if ( $is_active ) {
 737                      if ( current_user_can( 'manage_network_plugins' ) ) {
 738                          $actions['deactivate'] = sprintf(
 739                              '<a href="%s" id="deactivate-%s" aria-label="%s">%s</a>',
 740                              wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file ),
 741                              esc_attr( $plugin_slug ),
 742                              /* translators: %s: Plugin name. */
 743                              esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ),
 744                              __( 'Network Deactivate' )
 745                          );
 746                      }
 747                  } else {
 748                      if ( current_user_can( 'manage_network_plugins' ) ) {
 749                          $actions['activate'] = sprintf(
 750                              '<a href="%s" id="activate-%s" class="edit" aria-label="%s">%s</a>',
 751                              wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file ),
 752                              esc_attr( $plugin_slug ),
 753                              /* translators: %s: Plugin name. */
 754                              esc_attr( sprintf( _x( 'Network Activate %s', 'plugin' ), $plugin_data['Name'] ) ),
 755                              __( 'Network Activate' )
 756                          );
 757                      }
 758  
 759                      if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) {
 760                          $actions['delete'] = sprintf(
 761                              '<a href="%s" id="delete-%s" class="delete" aria-label="%s">%s</a>',
 762                              wp_nonce_url( 'plugins.php?action=delete-selected&amp;checked[]=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins' ),
 763                              esc_attr( $plugin_slug ),
 764                              /* translators: %s: Plugin name. */
 765                              esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ),
 766                              __( 'Delete' )
 767                          );
 768                      }
 769                  }
 770              } else {
 771                  if ( $restrict_network_active ) {
 772                      $actions = array(
 773                          'network_active' => __( 'Network Active' ),
 774                      );
 775                  } elseif ( $restrict_network_only ) {
 776                      $actions = array(
 777                          'network_only' => __( 'Network Only' ),
 778                      );
 779                  } elseif ( $is_active ) {
 780                      if ( current_user_can( 'deactivate_plugin', $plugin_file ) ) {
 781                          $actions['deactivate'] = sprintf(
 782                              '<a href="%s" id="deactivate-%s" aria-label="%s">%s</a>',
 783                              wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file ),
 784                              esc_attr( $plugin_slug ),
 785                              /* translators: %s: Plugin name. */
 786                              esc_attr( sprintf( _x( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ),
 787                              __( 'Deactivate' )
 788                          );
 789                      }
 790  
 791                      if ( current_user_can( 'resume_plugin', $plugin_file ) && is_plugin_paused( $plugin_file ) ) {
 792                          $actions['resume'] = sprintf(
 793                              '<a href="%s" id="resume-%s" class="resume-link" aria-label="%s">%s</a>',
 794                              wp_nonce_url( 'plugins.php?action=resume&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'resume-plugin_' . $plugin_file ),
 795                              esc_attr( $plugin_slug ),
 796                              /* translators: %s: Plugin name. */
 797                              esc_attr( sprintf( _x( 'Resume %s', 'plugin' ), $plugin_data['Name'] ) ),
 798                              __( 'Resume' )
 799                          );
 800                      }
 801                  } else {
 802                      if ( current_user_can( 'activate_plugin', $plugin_file ) ) {
 803                          $actions['activate'] = sprintf(
 804                              '<a href="%s" id="activate-%s" class="edit" aria-label="%s">%s</a>',
 805                              wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file ),
 806                              esc_attr( $plugin_slug ),
 807                              /* translators: %s: Plugin name. */
 808                              esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ),
 809                              __( 'Activate' )
 810                          );
 811                      }
 812  
 813                      if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) {
 814                          $actions['delete'] = sprintf(
 815                              '<a href="%s" id="delete-%s" class="delete" aria-label="%s">%s</a>',
 816                              wp_nonce_url( 'plugins.php?action=delete-selected&amp;checked[]=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins' ),
 817                              esc_attr( $plugin_slug ),
 818                              /* translators: %s: Plugin name. */
 819                              esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ),
 820                              __( 'Delete' )
 821                          );
 822                      }
 823                  } // End if $is_active.
 824              } // End if $screen->in_admin( 'network' ).
 825          } // End if $context.
 826  
 827          $actions = array_filter( $actions );
 828  
 829          if ( $screen->in_admin( 'network' ) ) {
 830  
 831              /**
 832               * Filters the action links displayed for each plugin in the Network Admin Plugins list table.
 833               *
 834               * @since 3.1.0
 835               *
 836               * @param string[] $actions     An array of plugin action links. By default this can include 'activate',
 837               *                              'deactivate', and 'delete'.
 838               * @param string   $plugin_file Path to the plugin file relative to the plugins directory.
 839               * @param array    $plugin_data An array of plugin data. See `get_plugin_data()`.
 840               * @param string   $context     The plugin context. By default this can include 'all', 'active', 'inactive',
 841               *                              'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
 842               */
 843              $actions = apply_filters( 'network_admin_plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
 844  
 845              /**
 846               * Filters the list of action links displayed for a specific plugin in the Network Admin Plugins list table.
 847               *
 848               * The dynamic portion of the hook name, `$plugin_file`, refers to the path
 849               * to the plugin file, relative to the plugins directory.
 850               *
 851               * @since 3.1.0
 852               *
 853               * @param string[] $actions     An array of plugin action links. By default this can include 'activate',
 854               *                              'deactivate', and 'delete'.
 855               * @param string   $plugin_file Path to the plugin file relative to the plugins directory.
 856               * @param array    $plugin_data An array of plugin data. See `get_plugin_data()`.
 857               * @param string   $context     The plugin context. By default this can include 'all', 'active', 'inactive',
 858               *                              'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
 859               */
 860              $actions = apply_filters( "network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );
 861  
 862          } else {
 863  
 864              /**
 865               * Filters the action links displayed for each plugin in the Plugins list table.
 866               *
 867               * @since 2.5.0
 868               * @since 2.6.0 The `$context` parameter was added.
 869               * @since 4.9.0 The 'Edit' link was removed from the list of action links.
 870               *
 871               * @param string[] $actions     An array of plugin action links. By default this can include 'activate',
 872               *                              'deactivate', and 'delete'. With Multisite active this can also include
 873               *                              'network_active' and 'network_only' items.
 874               * @param string   $plugin_file Path to the plugin file relative to the plugins directory.
 875               * @param array    $plugin_data An array of plugin data. See `get_plugin_data()`.
 876               * @param string   $context     The plugin context. By default this can include 'all', 'active', 'inactive',
 877               *                              'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
 878               */
 879              $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
 880  
 881              /**
 882               * Filters the list of action links displayed for a specific plugin in the Plugins list table.
 883               *
 884               * The dynamic portion of the hook name, `$plugin_file`, refers to the path
 885               * to the plugin file, relative to the plugins directory.
 886               *
 887               * @since 2.7.0
 888               * @since 4.9.0 The 'Edit' link was removed from the list of action links.
 889               *
 890               * @param string[] $actions     An array of plugin action links. By default this can include 'activate',
 891               *                              'deactivate', and 'delete'. With Multisite active this can also include
 892               *                              'network_active' and 'network_only' items.
 893               * @param string   $plugin_file Path to the plugin file relative to the plugins directory.
 894               * @param array    $plugin_data An array of plugin data. See `get_plugin_data()`.
 895               * @param string   $context     The plugin context. By default this can include 'all', 'active', 'inactive',
 896               *                              'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
 897               */
 898              $actions = apply_filters( "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );
 899  
 900          }
 901  
 902          $requires_php   = isset( $plugin_data['requires_php'] ) ? $plugin_data['requires_php'] : null;
 903          $compatible_php = is_php_version_compatible( $requires_php );
 904          $class          = $is_active ? 'active' : 'inactive';
 905          $checkbox_id    = 'checkbox_' . md5( $plugin_data['Name'] );
 906          if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ), true ) || ! $compatible_php ) {
 907              $checkbox = '';
 908          } else {
 909              $checkbox = sprintf(
 910                  '<label class="screen-reader-text" for="%1$s">%2$s</label>' .
 911                  '<input type="checkbox" name="checked[]" value="%3$s" id="%1$s" />',
 912                  $checkbox_id,
 913                  /* translators: %s: Plugin name. */
 914                  sprintf( __( 'Select %s' ), $plugin_data['Name'] ),
 915                  esc_attr( $plugin_file )
 916              );
 917          }
 918          if ( 'dropins' !== $context ) {
 919              $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : '&nbsp;' ) . '</p>';
 920              $plugin_name = $plugin_data['Name'];
 921          }
 922  
 923          if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) ) {
 924              $class .= ' update';
 925          }
 926  
 927          $paused = ! $screen->in_admin( 'network' ) && is_plugin_paused( $plugin_file );
 928  
 929          if ( $paused ) {
 930              $class .= ' paused';
 931          }
 932  
 933          printf(
 934              '<tr class="%s" data-slug="%s" data-plugin="%s">',
 935              esc_attr( $class ),
 936              esc_attr( $plugin_slug ),
 937              esc_attr( $plugin_file )
 938          );
 939  
 940          list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
 941  
 942          $auto_updates      = (array) get_site_option( 'auto_update_plugins', array() );
 943          $available_updates = get_site_transient( 'update_plugins' );
 944  
 945          foreach ( $columns as $column_name => $column_display_name ) {
 946              $extra_classes = '';
 947              if ( in_array( $column_name, $hidden, true ) ) {
 948                  $extra_classes = ' hidden';
 949              }
 950  
 951              switch ( $column_name ) {
 952                  case 'cb':
 953                      echo "<th scope='row' class='check-column'>$checkbox</th>";
 954                      break;
 955                  case 'name':
 956                      echo "<td class='plugin-title column-primary'><strong>$plugin_name</strong>";
 957                      echo $this->row_actions( $actions, true );
 958                      echo '</td>';
 959                      break;
 960                  case 'description':
 961                      $classes = 'column-description desc';
 962  
 963                      echo "<td class='$classes{$extra_classes}'>
 964                          <div class='plugin-description'>$description</div>
 965                          <div class='$class second plugin-version-author-uri'>";
 966  
 967                      $plugin_meta = array();
 968                      if ( ! empty( $plugin_data['Version'] ) ) {
 969                          /* translators: %s: Plugin version number. */
 970                          $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
 971                      }
 972                      if ( ! empty( $plugin_data['Author'] ) ) {
 973                          $author = $plugin_data['Author'];
 974                          if ( ! empty( $plugin_data['AuthorURI'] ) ) {
 975                              $author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>';
 976                          }
 977                          /* translators: %s: Plugin author name. */
 978                          $plugin_meta[] = sprintf( __( 'By %s' ), $author );
 979                      }
 980  
 981                      // Details link using API info, if available.
 982                      if ( isset( $plugin_data['slug'] ) && current_user_can( 'install_plugins' ) ) {
 983                          $plugin_meta[] = sprintf(
 984                              '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
 985                              esc_url(
 986                                  network_admin_url(
 987                                      'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] .
 988                                      '&TB_iframe=true&width=600&height=550'
 989                                  )
 990                              ),
 991                              /* translators: %s: Plugin name. */
 992                              esc_attr( sprintf( __( 'More information about %s' ), $plugin_name ) ),
 993                              esc_attr( $plugin_name ),
 994                              __( 'View details' )
 995                          );
 996                      } elseif ( ! empty( $plugin_data['PluginURI'] ) ) {
 997                          $plugin_meta[] = sprintf(
 998                              '<a href="%s">%s</a>',
 999                              esc_url( $plugin_data['PluginURI'] ),
1000                              __( 'Visit plugin site' )
1001                          );
1002                      }
1003  
1004                      /**
1005                       * Filters the array of row meta for each plugin in the Plugins list table.
1006                       *
1007                       * @since 2.8.0
1008                       *
1009                       * @param string[] $plugin_meta An array of the plugin's metadata,
1010                       *                              including the version, author,
1011                       *                              author URI, and plugin URI.
1012                       * @param string   $plugin_file Path to the plugin file relative to the plugins directory.
1013                       * @param array    $plugin_data An array of plugin data.
1014                       * @param string   $status      Status of the plugin. Defaults are 'All', 'Active',
1015                       *                              'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
1016                       *                              'Drop-ins', 'Search', 'Paused'.
1017                       */
1018                      $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status );
1019                      echo implode( ' | ', $plugin_meta );
1020  
1021                      echo '</div>';
1022  
1023                      if ( $paused ) {
1024                          $notice_text = __( 'This plugin failed to load properly and is paused during recovery mode.' );
1025  
1026                          printf( '<p><span class="dashicons dashicons-warning"></span> <strong>%s</strong></p>', $notice_text );
1027  
1028                          $error = wp_get_plugin_error( $plugin_file );
1029  
1030                          if ( false !== $error ) {
1031                              printf( '<div class="error-display"><p>%s</p></div>', wp_get_extension_error_description( $error ) );
1032                          }
1033                      }
1034  
1035                      echo '</td>';
1036                      break;
1037                  case 'auto-updates':
1038                      if ( ! $this->show_autoupdates ) {
1039                          break;
1040                      }
1041  
1042                      echo "<td class='column-auto-updates{$extra_classes}'>";
1043  
1044                      if ( in_array( $plugin_file, $auto_updates, true ) ) {
1045                          $text       = __( 'Disable auto-updates' );
1046                          $action     = 'disable';
1047                          $time_class = '';
1048                      } else {
1049                          $text       = __( 'Enable auto-updates' );
1050                          $action     = 'enable';
1051                          $time_class = ' hidden';
1052                      }
1053  
1054                      $query_args = array(
1055                          'action'        => "{$action}-auto-update",
1056                          'plugin'        => $plugin_file,
1057                          'paged'         => $page,
1058                          'plugin_status' => $status,
1059                      );
1060  
1061                      $url = add_query_arg( $query_args, 'plugins.php' );
1062  
1063                      printf(
1064                          '<a href="%s" class="toggle-auto-update" data-wp-action="%s">',
1065                          wp_nonce_url( $url, 'updates' ),
1066                          $action
1067                      );
1068  
1069                      echo '<span class="dashicons dashicons-update spin hidden"></span>';
1070                      echo '<span class="label">' . $text . '</span>';
1071                      echo '</a>';
1072  
1073                      $available_updates = get_site_transient( 'update_plugins' );
1074  
1075                      if ( isset( $available_updates->response[ $plugin_file ] ) ) {
1076                          printf(
1077                              '<div class="auto-update-time%s">%s</div>',
1078                              $time_class,
1079                              wp_get_auto_update_message()
1080                          );
1081                      }
1082  
1083                      echo '<div class="inline notice error hidden"><p></p></div>';
1084                      echo '</td>';
1085  
1086                      break;
1087                  default:
1088                      $classes = "$column_name column-$column_name $class";
1089  
1090                      echo "<td class='$classes{$extra_classes}'>";
1091  
1092                      /**
1093                       * Fires inside each custom column of the Plugins list table.
1094                       *
1095                       * @since 3.1.0
1096                       *
1097                       * @param string $column_name Name of the column.
1098                       * @param string $plugin_file Path to the plugin file relative to the plugins directory.
1099                       * @param array  $plugin_data An array of plugin data.
1100                       */
1101                      do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
1102  
1103                      echo '</td>';
1104              }
1105          }
1106  
1107          echo '</tr>';
1108  
1109          /**
1110           * Fires after each row in the Plugins list table.
1111           *
1112           * @since 2.3.0
1113           * @since 5.5.0 Added 'Auto-updates Enabled' and 'Auto-updates Disabled' `$status`.
1114           *
1115           * @param string $plugin_file Path to the plugin file relative to the plugins directory.
1116           * @param array  $plugin_data An array of plugin data.
1117           * @param string $status      Status of the plugin. Defaults are 'All', 'Active',
1118           *                            'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
1119           *                            'Drop-ins', 'Search', 'Paused', 'Auto-updates Enabled',
1120           *                            'Auto-updates Disabled'.
1121           */
1122          do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
1123  
1124          /**
1125           * Fires after each specific row in the Plugins list table.
1126           *
1127           * The dynamic portion of the hook name, `$plugin_file`, refers to the path
1128           * to the plugin file, relative to the plugins directory.
1129           *
1130           * @since 2.7.0
1131           * @since 5.5.0 Added 'Auto-updates Enabled' and 'Auto-updates Disabled' `$status`.
1132           *
1133           * @param string $plugin_file Path to the plugin file relative to the plugins directory.
1134           * @param array  $plugin_data An array of plugin data.
1135           * @param string $status      Status of the plugin. Defaults are 'All', 'Active',
1136           *                            'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
1137           *                            'Drop-ins', 'Search', 'Paused', 'Auto-updates Enabled',
1138           *                            'Auto-updates Disabled'.
1139           */
1140          do_action( "after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $status );
1141      }
1142  
1143      /**
1144       * Gets the name of the primary column for this specific list table.
1145       *
1146       * @since 4.3.0
1147       *
1148       * @return string Unalterable name for the primary column, in this case, 'name'.
1149       */
1150  	protected function get_primary_column_name() {
1151          return 'name';
1152      }
1153  }


Generated : Thu May 28 08:20:02 2020 Cross-referenced by PHPXref