WP_Plugins_List_Table

Core class used to implement displaying installed plugins in a list table.

Defined (1)

The class is defined in the following location(s).

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