class-wp-plugins-list-table.php 32 KB

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