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. ) ); 
  200.  
  201. if ( ! $orderby ) { 
  202. $orderby = 'Name'; 
  203. } else { 
  204. $orderby = ucfirst( $orderby ); 
  205.  
  206. $order = strtoupper( $order ); 
  207.  
  208. uasort( $this->items, array( $this, '_order_callback' ) ); 
  209.  
  210. $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 ); 
  211.  
  212. $start = ( $page - 1 ) * $plugins_per_page; 
  213.  
  214. if ( $total_this_page > $plugins_per_page ) 
  215. $this->items = array_slice( $this->items, $start, $plugins_per_page ); 
  216.  
  217. $this->set_pagination_args( array( 
  218. 'total_items' => $total_this_page,  
  219. 'per_page' => $plugins_per_page,  
  220. ) ); 
  221.  
  222. /** 
  223. * @global string $s URL encoded search term. 
  224. * @param array $plugin 
  225. * @return bool 
  226. */ 
  227. public function _search_callback( $plugin ) { 
  228. global $s; 
  229.  
  230. foreach ( $plugin as $value ) { 
  231. if ( is_string( $value ) && false !== stripos( strip_tags( $value ), urldecode( $s ) ) ) { 
  232. return true; 
  233.  
  234. return false; 
  235.  
  236. /** 
  237. * @global string $orderby 
  238. * @global string $order 
  239. * @param array $plugin_a 
  240. * @param array $plugin_b 
  241. * @return int 
  242. */ 
  243. public function _order_callback( $plugin_a, $plugin_b ) { 
  244. global $orderby, $order; 
  245.  
  246. $a = $plugin_a[$orderby]; 
  247. $b = $plugin_b[$orderby]; 
  248.  
  249. if ( $a == $b ) 
  250. return 0; 
  251.  
  252. if ( 'DESC' === $order ) { 
  253. return strcasecmp( $b, $a ); 
  254. } else { 
  255. return strcasecmp( $a, $b ); 
  256.  
  257. /** 
  258. * @global array $plugins 
  259. */ 
  260. public function no_items() { 
  261. global $plugins; 
  262.  
  263. if ( ! empty( $_REQUEST['s'] ) ) { 
  264. $s = esc_html( wp_unslash( $_REQUEST['s'] ) ); 
  265.  
  266. printf( __( 'No plugins found for “%s”.' ), $s ); 
  267.  
  268. // We assume that somebody who can install plugins in multisite is experienced enough to not need this helper link. 
  269. if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) { 
  270. echo ' <a href="' . esc_url( admin_url( 'plugin-install.php?tab=search&s=' . urlencode( $s ) ) ) . '">' . __( 'Search for plugins in the WordPress Plugin Directory.' ) . '</a>'; 
  271. } elseif ( ! empty( $plugins['all'] ) ) 
  272. _e( 'No plugins found.' ); 
  273. else 
  274. _e( 'You do not appear to have any plugins available at this time.' ); 
  275.  
  276. /** 
  277. * Displays the search box. 
  278. * @since 4.6.0 
  279. * @access public 
  280. * @param string $text The 'submit' button label. 
  281. * @param string $input_id ID attribute value for the search input field. 
  282. */ 
  283. public function search_box( $text, $input_id ) { 
  284. if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { 
  285. return; 
  286.  
  287. $input_id = $input_id . '-search-input'; 
  288.  
  289. if ( ! empty( $_REQUEST['orderby'] ) ) { 
  290. echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; 
  291. if ( ! empty( $_REQUEST['order'] ) ) { 
  292. echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; 
  293. ?> 
  294. <p class="search-box"> 
  295. <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label> 
  296. <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...' ); ?>"/> 
  297. <?php submit_button( $text, 'button hide-if-js', '', false, array( 'id' => 'search-submit' ) ); ?> 
  298. </p> 
  299. <?php 
  300.  
  301. /** 
  302. * @global string $status 
  303. * @return array 
  304. */ 
  305. public function get_columns() { 
  306. global $status; 
  307.  
  308. return array( 
  309. 'cb' => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',  
  310. 'name' => __( 'Plugin' ),  
  311. 'description' => __( 'Description' ),  
  312. ); 
  313.  
  314. /** 
  315. * @return array 
  316. */ 
  317. protected function get_sortable_columns() { 
  318. return array(); 
  319.  
  320. /** 
  321. * @global array $totals 
  322. * @global string $status 
  323. * @return array 
  324. */ 
  325. protected function get_views() { 
  326. global $totals, $status; 
  327.  
  328. $status_links = array(); 
  329. foreach ( $totals as $type => $count ) { 
  330. if ( !$count ) 
  331. continue; 
  332.  
  333. switch ( $type ) { 
  334. case 'all': 
  335. $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' ); 
  336. break; 
  337. case 'active': 
  338. $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count ); 
  339. break; 
  340. case 'recently_activated': 
  341. $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count ); 
  342. break; 
  343. case 'inactive': 
  344. $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count ); 
  345. break; 
  346. case 'mustuse': 
  347. $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count ); 
  348. break; 
  349. case 'dropins': 
  350. $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count ); 
  351. break; 
  352. case 'upgrade': 
  353. $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count ); 
  354. break; 
  355.  
  356. if ( 'search' !== $type ) { 
  357. $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",  
  358. add_query_arg('plugin_status', $type, 'plugins.php'),  
  359. ( $type === $status ) ? ' class="current"' : '',  
  360. sprintf( $text, number_format_i18n( $count ) ) 
  361. ); 
  362.  
  363. return $status_links; 
  364.  
  365. /** 
  366. * @global string $status 
  367. * @return array 
  368. */ 
  369. protected function get_bulk_actions() { 
  370. global $status; 
  371.  
  372. $actions = array(); 
  373.  
  374. if ( 'active' != $status ) 
  375. $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' ); 
  376.  
  377. if ( 'inactive' != $status && 'recent' != $status ) 
  378. $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' ); 
  379.  
  380. if ( !is_multisite() || $this->screen->in_admin( 'network' ) ) { 
  381. if ( current_user_can( 'update_plugins' ) ) 
  382. $actions['update-selected'] = __( 'Update' ); 
  383. if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) 
  384. $actions['delete-selected'] = __( 'Delete' ); 
  385.  
  386. return $actions; 
  387.  
  388. /** 
  389. * @global string $status 
  390. * @param string $which 
  391. */ 
  392. public function bulk_actions( $which = '' ) { 
  393. global $status; 
  394.  
  395. if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) 
  396. return; 
  397.  
  398. parent::bulk_actions( $which ); 
  399.  
  400. /** 
  401. * @global string $status 
  402. * @param string $which 
  403. */ 
  404. protected function extra_tablenav( $which ) { 
  405. global $status; 
  406.  
  407. if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) ) 
  408. return; 
  409.  
  410. echo '<div class="alignleft actions">'; 
  411.  
  412. if ( 'recently_activated' == $status ) { 
  413. submit_button( __( 'Clear List' ), 'button', 'clear-recent-list', false ); 
  414. } elseif ( 'top' === $which && 'mustuse' === $status ) { 
  415. /** translators: %s: mu-plugins directory name */ 
  416. echo '<p>' . sprintf( __( 'Files in the %s directory are executed automatically.' ),  
  417. '<code>' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . '</code>' 
  418. ) . '</p>'; 
  419. } elseif ( 'top' === $which && 'dropins' === $status ) { 
  420. /** translators: %s: wp-content directory name */ 
  421. echo '<p>' . sprintf( __( 'Drop-ins are advanced plugins in the %s directory that replace WordPress functionality when present.' ),  
  422. '<code>' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '</code>' 
  423. ) . '</p>'; 
  424. echo '</div>'; 
  425.  
  426. /** 
  427. * @return string 
  428. */ 
  429. public function current_action() { 
  430. if ( isset($_POST['clear-recent-list']) ) 
  431. return 'clear-recent-list'; 
  432.  
  433. return parent::current_action(); 
  434.  
  435. /** 
  436. * @global string $status 
  437. */ 
  438. public function display_rows() { 
  439. global $status; 
  440.  
  441. if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) ) 
  442. return; 
  443.  
  444. foreach ( $this->items as $plugin_file => $plugin_data ) 
  445. $this->single_row( array( $plugin_file, $plugin_data ) ); 
  446.  
  447. /** 
  448. * @global string $status 
  449. * @global int $page 
  450. * @global string $s 
  451. * @global array $totals 
  452. * @param array $item 
  453. */ 
  454. public function single_row( $item ) { 
  455. global $status, $page, $s, $totals; 
  456.  
  457. list( $plugin_file, $plugin_data ) = $item; 
  458. $context = $status; 
  459. $screen = $this->screen; 
  460.  
  461. // Pre-order. 
  462. $actions = array( 
  463. 'deactivate' => '',  
  464. 'activate' => '',  
  465. 'details' => '',  
  466. 'edit' => '',  
  467. 'delete' => '',  
  468. ); 
  469.  
  470. // Do not restrict by default 
  471. $restrict_network_active = false; 
  472. $restrict_network_only = false; 
  473.  
  474. if ( 'mustuse' === $context ) { 
  475. $is_active = true; 
  476. } elseif ( 'dropins' === $context ) { 
  477. $dropins = _get_dropins(); 
  478. $plugin_name = $plugin_file; 
  479. if ( $plugin_file != $plugin_data['Name'] ) 
  480. $plugin_name .= '<br/>' . $plugin_data['Name']; 
  481. if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant 
  482. $is_active = true; 
  483. $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; 
  484. } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true 
  485. $is_active = true; 
  486. $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; 
  487. } else { 
  488. $is_active = false; 
  489. $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="error-message">' . __( 'Inactive:' ) . '</span></strong> ' . 
  490. /** translators: 1: drop-in constant name, 2: wp-config.php */ 
  491. sprintf( __( 'Requires %1$s in %2$s file.' ),  
  492. "<code>define('" . $dropins[ $plugin_file ][1] . "', true);</code>",  
  493. '<code>wp-config.php</code>' 
  494. ) . '</p>'; 
  495. if ( $plugin_data['Description'] ) 
  496. $description .= '<p>' . $plugin_data['Description'] . '</p>'; 
  497. } else { 
  498. if ( $screen->in_admin( 'network' ) ) { 
  499. $is_active = is_plugin_active_for_network( $plugin_file ); 
  500. } else { 
  501. $is_active = is_plugin_active( $plugin_file ); 
  502. $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) ); 
  503. $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active ); 
  504.  
  505. if ( $screen->in_admin( 'network' ) ) { 
  506. if ( $is_active ) { 
  507. if ( current_user_can( 'manage_network_plugins' ) ) { 
  508. /** translators: %s: plugin name */ 
  509. $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>'; 
  510. } else { 
  511. if ( current_user_can( 'manage_network_plugins' ) ) { 
  512. /** translators: %s: plugin name */ 
  513. $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>'; 
  514. if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) { 
  515. /** translators: %s: plugin name */ 
  516. $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>'; 
  517. } else { 
  518. if ( $restrict_network_active ) { 
  519. $actions = array( 
  520. 'network_active' => __( 'Network Active' ),  
  521. ); 
  522. } elseif ( $restrict_network_only ) { 
  523. $actions = array( 
  524. 'network_only' => __( 'Network Only' ),  
  525. ); 
  526. } elseif ( $is_active ) { 
  527. /** translators: %s: plugin name */ 
  528. $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>'; 
  529. } else { 
  530. /** translators: %s: plugin name */ 
  531. $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>'; 
  532.  
  533. if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) { 
  534. /** translators: %s: plugin name */ 
  535. $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>'; 
  536. } // end if $is_active 
  537.  
  538. } // end if $screen->in_admin( 'network' ) 
  539.  
  540. if ( ( ! is_multisite() || $screen->in_admin( 'network' ) ) && current_user_can( 'edit_plugins' ) && is_writable( WP_PLUGIN_DIR . '/' . $plugin_file ) ) { 
  541. /** translators: %s: plugin name */ 
  542. $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" class="edit" aria-label="' . esc_attr( sprintf( __( 'Edit %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Edit' ) . '</a>'; 
  543. } // end if $context 
  544.  
  545. $actions = array_filter( $actions ); 
  546.  
  547. if ( $screen->in_admin( 'network' ) ) { 
  548.  
  549. /** 
  550. * Filters the action links displayed for each plugin in the Network Admin Plugins list table. 
  551. * The default action links for the Network plugins list table include 
  552. * 'Network Activate', 'Network Deactivate', 'Edit', and 'Delete'. 
  553. * @since 3.1.0 As `{$prefix}_plugin_action_links` 
  554. * @since 4.4.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 As `{$prefix}_plugin_action_links_{$plugin_file}` 
  569. * @since 4.4.0 
  570. * @param array $actions An array of plugin action links. 
  571. * @param string $plugin_file Path to the plugin file relative to the plugins directory. 
  572. * @param array $plugin_data An array of plugin data. 
  573. * @param string $context The plugin context. Defaults are 'All', 'Active',  
  574. * 'Inactive', 'Recently Activated', 'Upgrade',  
  575. * 'Must-Use', 'Drop-ins', 'Search'. 
  576. */ 
  577. $actions = apply_filters( "network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context ); 
  578.  
  579. } else { 
  580.  
  581. /** 
  582. * Filters the action links displayed for each plugin in the Plugins list table. 
  583. * The default action links for the site plugins list table include 
  584. * 'Activate', 'Deactivate', and 'Edit', for a network site, and 
  585. * 'Activate', 'Deactivate', 'Edit', and 'Delete' for a single site. 
  586. * @since 2.5.0 As `{$prefix}_plugin_action_links` 
  587. * @since 4.4.0 
  588. * @param array $actions An array of plugin action links. 
  589. * @param string $plugin_file Path to the plugin file relative to the plugins directory. 
  590. * @param array $plugin_data An array of plugin data. 
  591. * @param string $context The plugin context. Defaults are 'All', 'Active',  
  592. * 'Inactive', 'Recently Activated', 'Upgrade',  
  593. * 'Must-Use', 'Drop-ins', 'Search'. 
  594. */ 
  595. $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context ); 
  596.  
  597. /** 
  598. * Filters the list of action links displayed for a specific plugin in the Plugins list table. 
  599. * The dynamic portion of the hook name, $plugin_file, refers to the path 
  600. * to the plugin file, relative to the plugins directory. 
  601. * @since 2.7.0 As `{$prefix}_plugin_action_links_{$plugin_file}` 
  602. * @since 4.4.0 
  603. * @param array $actions An array of plugin action links. 
  604. * @param string $plugin_file Path to the plugin file relative to the plugins directory. 
  605. * @param array $plugin_data An array of plugin data. 
  606. * @param string $context The plugin context. Defaults are 'All', 'Active',  
  607. * 'Inactive', 'Recently Activated', 'Upgrade',  
  608. * 'Must-Use', 'Drop-ins', 'Search'. 
  609. */ 
  610. $actions = apply_filters( "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context ); 
  611.  
  612.  
  613. $class = $is_active ? 'active' : 'inactive'; 
  614. $checkbox_id = "checkbox_" . md5($plugin_data['Name']); 
  615. if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) ) { 
  616. $checkbox = ''; 
  617. } else { 
  618. $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . "</label>" 
  619. . "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' />"; 
  620. if ( 'dropins' != $context ) { 
  621. $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : ' ' ) . '</p>'; 
  622. $plugin_name = $plugin_data['Name']; 
  623.  
  624. if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) ) 
  625. $class .= ' update'; 
  626.  
  627. $plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_name ); 
  628. printf( '<tr class="%s" data-slug="%s" data-plugin="%s">',  
  629. esc_attr( $class ),  
  630. esc_attr( $plugin_slug ),  
  631. esc_attr( $plugin_file ) 
  632. ); 
  633.  
  634. list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); 
  635.  
  636. foreach ( $columns as $column_name => $column_display_name ) { 
  637. $extra_classes = ''; 
  638. if ( in_array( $column_name, $hidden ) ) { 
  639. $extra_classes = ' hidden'; 
  640.  
  641. switch ( $column_name ) { 
  642. case 'cb': 
  643. echo "<th scope='row' class='check-column'>$checkbox</th>"; 
  644. break; 
  645. case 'name': 
  646. echo "<td class='plugin-title column-primary'><strong>$plugin_name</strong>"; 
  647. echo $this->row_actions( $actions, true ); 
  648. echo "</td>"; 
  649. break; 
  650. case 'description': 
  651. $classes = 'column-description desc'; 
  652.  
  653. echo "<td class='$classes{$extra_classes}'> 
  654. <div class='plugin-description'>$description</div> 
  655. <div class='$class second plugin-version-author-uri'>"; 
  656.  
  657. $plugin_meta = array(); 
  658. if ( !empty( $plugin_data['Version'] ) ) 
  659. $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); 
  660. if ( !empty( $plugin_data['Author'] ) ) { 
  661. $author = $plugin_data['Author']; 
  662. if ( !empty( $plugin_data['AuthorURI'] ) ) 
  663. $author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; 
  664. $plugin_meta[] = sprintf( __( 'By %s' ), $author ); 
  665.  
  666. // Details link using API info, if available 
  667. if ( isset( $plugin_data['slug'] ) && current_user_can( 'install_plugins' ) ) { 
  668. $plugin_meta[] = sprintf( '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',  
  669. esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] . 
  670. '&TB_iframe=true&width=600&height=550' ) ),  
  671. esc_attr( sprintf( __( 'More information about %s' ), $plugin_name ) ),  
  672. esc_attr( $plugin_name ),  
  673. __( 'View details' ) 
  674. ); 
  675. } elseif ( ! empty( $plugin_data['PluginURI'] ) ) { 
  676. $plugin_meta[] = sprintf( '<a href="%s">%s</a>',  
  677. esc_url( $plugin_data['PluginURI'] ),  
  678. __( 'Visit plugin site' ) 
  679. ); 
  680.  
  681. /** 
  682. * Filters the array of row meta for each plugin in the Plugins list table. 
  683. * @since 2.8.0 
  684. * @param array $plugin_meta An array of the plugin's metadata,  
  685. * including the version, author,  
  686. * author URI, and plugin URI. 
  687. * @param string $plugin_file Path to the plugin file, relative to the plugins directory. 
  688. * @param array $plugin_data An array of plugin data. 
  689. * @param string $status Status of the plugin. Defaults are 'All', 'Active',  
  690. * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',  
  691. * 'Drop-ins', 'Search'. 
  692. */ 
  693. $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status ); 
  694. echo implode( ' | ', $plugin_meta ); 
  695.  
  696. echo "</div></td>"; 
  697. break; 
  698. default: 
  699. $classes = "$column_name column-$column_name $class"; 
  700.  
  701. echo "<td class='$classes{$extra_classes}'>"; 
  702.  
  703. /** 
  704. * Fires inside each custom column of the Plugins list table. 
  705. * @since 3.1.0 
  706. * @param string $column_name Name of the column. 
  707. * @param string $plugin_file Path to the plugin file. 
  708. * @param array $plugin_data An array of plugin data. 
  709. */ 
  710. do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data ); 
  711.  
  712. echo "</td>"; 
  713.  
  714. echo "</tr>"; 
  715.  
  716. /** 
  717. * Fires after each row in the Plugins list table. 
  718. * @since 2.3.0 
  719. * @param string $plugin_file Path to the plugin file, relative to the plugins directory. 
  720. * @param array $plugin_data An array of plugin data. 
  721. * @param string $status Status of the plugin. Defaults are 'All', 'Active',  
  722. * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',  
  723. * 'Drop-ins', 'Search'. 
  724. */ 
  725. do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status ); 
  726.  
  727. /** 
  728. * Fires after each specific row in the Plugins list table. 
  729. * The dynamic portion of the hook name, `$plugin_file`, refers to the path 
  730. * to the plugin file, relative to the plugins directory. 
  731. * @since 2.7.0 
  732. * @param string $plugin_file Path to the plugin file, relative to the plugins directory. 
  733. * @param array $plugin_data An array of plugin data. 
  734. * @param string $status Status of the plugin. Defaults are 'All', 'Active',  
  735. * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',  
  736. * 'Drop-ins', 'Search'. 
  737. */ 
  738. do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status ); 
  739.  
  740. /** 
  741. * Gets the name of the primary column for this specific list table. 
  742. * @since 4.3.0 
  743. * @access protected 
  744. * @return string Unalterable name for the primary column, in this case, 'name'. 
  745. */ 
  746. protected function get_primary_column_name() { 
  747. return 'name';