/wp-admin/includes/class-wp-plugins-list-table.php

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