[ Index ]

PHP Cross Reference of WordPress

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


Generated: Wed Jul 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1