PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

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

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