home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-admin / includes / class-wp-plugins-list-table.php < prev    next >
Encoding:
PHP Script  |  2017-10-04  |  32.0 KB  |  873 lines

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