PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

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

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