class-wp-plugin-install-list-table.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. <?php
  2. /**
  3. * List Table API: WP_Plugin_Install_List_Table class
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. * @since 3.1.0
  8. */
  9. /**
  10. * Core class used to implement displaying plugins to install in a list table.
  11. *
  12. * @since 3.1.0
  13. *
  14. * @see WP_List_Table
  15. */
  16. class WP_Plugin_Install_List_Table extends WP_List_Table {
  17. public $order = 'ASC';
  18. public $orderby = null;
  19. public $groups = array();
  20. private $error;
  21. /**
  22. * @return bool
  23. */
  24. public function ajax_user_can() {
  25. return current_user_can( 'install_plugins' );
  26. }
  27. /**
  28. * Return the list of known plugins.
  29. *
  30. * Uses the transient data from the updates API to determine the known
  31. * installed plugins.
  32. *
  33. * @since 4.9.0
  34. * @access protected
  35. *
  36. * @return array
  37. */
  38. protected function get_installed_plugins() {
  39. $plugins = array();
  40. $plugin_info = get_site_transient( 'update_plugins' );
  41. if ( isset( $plugin_info->no_update ) ) {
  42. foreach ( $plugin_info->no_update as $plugin ) {
  43. if ( isset( $plugin->slug ) ) {
  44. $plugin->upgrade = false;
  45. $plugins[ $plugin->slug ] = $plugin;
  46. }
  47. }
  48. }
  49. if ( isset( $plugin_info->response ) ) {
  50. foreach ( $plugin_info->response as $plugin ) {
  51. if ( isset( $plugin->slug ) ) {
  52. $plugin->upgrade = true;
  53. $plugins[ $plugin->slug ] = $plugin;
  54. }
  55. }
  56. }
  57. return $plugins;
  58. }
  59. /**
  60. * Returns a list of slugs of installed plugins, if known.
  61. *
  62. * Uses the transient data from the updates API to determine the slugs of
  63. * known installed plugins. This might be better elsewhere, perhaps even
  64. * within get_plugins().
  65. *
  66. * @since 4.0.0
  67. *
  68. * @return array
  69. */
  70. protected function get_installed_plugin_slugs() {
  71. return array_keys( $this->get_installed_plugins() );
  72. }
  73. /**
  74. * @global array $tabs
  75. * @global string $tab
  76. * @global int $paged
  77. * @global string $type
  78. * @global string $term
  79. */
  80. public function prepare_items() {
  81. include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
  82. global $tabs, $tab, $paged, $type, $term;
  83. wp_reset_vars( array( 'tab' ) );
  84. $paged = $this->get_pagenum();
  85. $per_page = 36;
  86. // These are the tabs which are shown on the page.
  87. $tabs = array();
  88. if ( 'search' === $tab ) {
  89. $tabs['search'] = __( 'Search Results' );
  90. }
  91. if ( 'beta' === $tab || false !== strpos( get_bloginfo( 'version' ), '-' ) ) {
  92. $tabs['beta'] = _x( 'Beta Testing', 'Plugin Installer' );
  93. }
  94. $tabs['featured'] = _x( 'Featured', 'Plugin Installer' );
  95. $tabs['popular'] = _x( 'Popular', 'Plugin Installer' );
  96. $tabs['recommended'] = _x( 'Recommended', 'Plugin Installer' );
  97. $tabs['favorites'] = _x( 'Favorites', 'Plugin Installer' );
  98. if ( current_user_can( 'upload_plugins' ) ) {
  99. // No longer a real tab. Here for filter compatibility.
  100. // Gets skipped in get_views().
  101. $tabs['upload'] = __( 'Upload Plugin' );
  102. }
  103. $nonmenu_tabs = array( 'plugin-information' ); // Valid actions to perform which do not have a Menu item.
  104. /**
  105. * Filters the tabs shown on the Add Plugins screen.
  106. *
  107. * @since 2.7.0
  108. *
  109. * @param string[] $tabs The tabs shown on the Add Plugins screen. Defaults include
  110. * 'featured', 'popular', 'recommended', 'favorites', and 'upload'.
  111. */
  112. $tabs = apply_filters( 'install_plugins_tabs', $tabs );
  113. /**
  114. * Filters tabs not associated with a menu item on the Add Plugins screen.
  115. *
  116. * @since 2.7.0
  117. *
  118. * @param string[] $nonmenu_tabs The tabs that don't have a menu item on the Add Plugins screen.
  119. */
  120. $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
  121. // If a non-valid menu tab has been selected, And it's not a non-menu action.
  122. if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs, true ) ) ) {
  123. $tab = key( $tabs );
  124. }
  125. $installed_plugins = $this->get_installed_plugins();
  126. $args = array(
  127. 'page' => $paged,
  128. 'per_page' => $per_page,
  129. // Send the locale to the API so it can provide context-sensitive results.
  130. 'locale' => get_user_locale(),
  131. );
  132. switch ( $tab ) {
  133. case 'search':
  134. $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
  135. $term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
  136. switch ( $type ) {
  137. case 'tag':
  138. $args['tag'] = sanitize_title_with_dashes( $term );
  139. break;
  140. case 'term':
  141. $args['search'] = $term;
  142. break;
  143. case 'author':
  144. $args['author'] = $term;
  145. break;
  146. }
  147. break;
  148. case 'featured':
  149. case 'popular':
  150. case 'new':
  151. case 'beta':
  152. $args['browse'] = $tab;
  153. break;
  154. case 'recommended':
  155. $args['browse'] = $tab;
  156. // Include the list of installed plugins so we can get relevant results.
  157. $args['installed_plugins'] = array_keys( $installed_plugins );
  158. break;
  159. case 'favorites':
  160. $action = 'save_wporg_username_' . get_current_user_id();
  161. if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), $action ) ) {
  162. $user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
  163. // If the save url parameter is passed with a falsey value, don't save the favorite user.
  164. if ( ! isset( $_GET['save'] ) || $_GET['save'] ) {
  165. update_user_meta( get_current_user_id(), 'wporg_favorites', $user );
  166. }
  167. } else {
  168. $user = get_user_option( 'wporg_favorites' );
  169. }
  170. if ( $user ) {
  171. $args['user'] = $user;
  172. } else {
  173. $args = false;
  174. }
  175. add_action( 'install_plugins_favorites', 'install_plugins_favorites_form', 9, 0 );
  176. break;
  177. default:
  178. $args = false;
  179. break;
  180. }
  181. /**
  182. * Filters API request arguments for each Add Plugins screen tab.
  183. *
  184. * The dynamic portion of the hook name, `$tab`, refers to the plugin install tabs.
  185. *
  186. * Possible hook names include:
  187. *
  188. * - `install_plugins_table_api_args_favorites`
  189. * - `install_plugins_table_api_args_featured`
  190. * - `install_plugins_table_api_args_popular`
  191. * - `install_plugins_table_api_args_recommended`
  192. * - `install_plugins_table_api_args_upload`
  193. * - `install_plugins_table_api_args_search`
  194. * - `install_plugins_table_api_args_beta`
  195. *
  196. * @since 3.7.0
  197. *
  198. * @param array|false $args Plugin install API arguments.
  199. */
  200. $args = apply_filters( "install_plugins_table_api_args_{$tab}", $args );
  201. if ( ! $args ) {
  202. return;
  203. }
  204. $api = plugins_api( 'query_plugins', $args );
  205. if ( is_wp_error( $api ) ) {
  206. $this->error = $api;
  207. return;
  208. }
  209. $this->items = $api->plugins;
  210. if ( $this->orderby ) {
  211. uasort( $this->items, array( $this, 'order_callback' ) );
  212. }
  213. $this->set_pagination_args(
  214. array(
  215. 'total_items' => $api->info['results'],
  216. 'per_page' => $args['per_page'],
  217. )
  218. );
  219. if ( isset( $api->info['groups'] ) ) {
  220. $this->groups = $api->info['groups'];
  221. }
  222. if ( $installed_plugins ) {
  223. $js_plugins = array_fill_keys(
  224. array( 'all', 'search', 'active', 'inactive', 'recently_activated', 'mustuse', 'dropins' ),
  225. array()
  226. );
  227. $js_plugins['all'] = array_values( wp_list_pluck( $installed_plugins, 'plugin' ) );
  228. $upgrade_plugins = wp_filter_object_list( $installed_plugins, array( 'upgrade' => true ), 'and', 'plugin' );
  229. if ( $upgrade_plugins ) {
  230. $js_plugins['upgrade'] = array_values( $upgrade_plugins );
  231. }
  232. wp_localize_script(
  233. 'updates',
  234. '_wpUpdatesItemCounts',
  235. array(
  236. 'plugins' => $js_plugins,
  237. 'totals' => wp_get_update_data(),
  238. )
  239. );
  240. }
  241. }
  242. /**
  243. */
  244. public function no_items() {
  245. if ( isset( $this->error ) ) { ?>
  246. <div class="inline error"><p><?php echo $this->error->get_error_message(); ?></p>
  247. <p class="hide-if-no-js"><button class="button try-again"><?php _e( 'Try Again' ); ?></button></p>
  248. </div>
  249. <?php } else { ?>
  250. <div class="no-plugin-results"><?php _e( 'No plugins found. Try a different search.' ); ?></div>
  251. <?php
  252. }
  253. }
  254. /**
  255. * @global array $tabs
  256. * @global string $tab
  257. *
  258. * @return array
  259. */
  260. protected function get_views() {
  261. global $tabs, $tab;
  262. $display_tabs = array();
  263. foreach ( (array) $tabs as $action => $text ) {
  264. $display_tabs[ 'plugin-install-' . $action ] = array(
  265. 'url' => self_admin_url( 'plugin-install.php?tab=' . $action ),
  266. 'label' => $text,
  267. 'current' => $action === $tab,
  268. );
  269. }
  270. // No longer a real tab.
  271. unset( $display_tabs['plugin-install-upload'] );
  272. return $this->get_views_links( $display_tabs );
  273. }
  274. /**
  275. * Overrides parent views so we can use the filter bar display.
  276. */
  277. public function views() {
  278. $views = $this->get_views();
  279. /** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
  280. $views = apply_filters( "views_{$this->screen->id}", $views );
  281. $this->screen->render_screen_reader_content( 'heading_views' );
  282. ?>
  283. <div class="wp-filter">
  284. <ul class="filter-links">
  285. <?php
  286. if ( ! empty( $views ) ) {
  287. foreach ( $views as $class => $view ) {
  288. $views[ $class ] = "\t<li class='$class'>$view";
  289. }
  290. echo implode( " </li>\n", $views ) . "</li>\n";
  291. }
  292. ?>
  293. </ul>
  294. <?php install_search_form(); ?>
  295. </div>
  296. <?php
  297. }
  298. /**
  299. * Displays the plugin install table.
  300. *
  301. * Overrides the parent display() method to provide a different container.
  302. *
  303. * @since 4.0.0
  304. */
  305. public function display() {
  306. $singular = $this->_args['singular'];
  307. $data_attr = '';
  308. if ( $singular ) {
  309. $data_attr = " data-wp-lists='list:$singular'";
  310. }
  311. $this->display_tablenav( 'top' );
  312. ?>
  313. <div class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
  314. <?php
  315. $this->screen->render_screen_reader_content( 'heading_list' );
  316. ?>
  317. <div id="the-list"<?php echo $data_attr; ?>>
  318. <?php $this->display_rows_or_placeholder(); ?>
  319. </div>
  320. </div>
  321. <?php
  322. $this->display_tablenav( 'bottom' );
  323. }
  324. /**
  325. * @global string $tab
  326. *
  327. * @param string $which
  328. */
  329. protected function display_tablenav( $which ) {
  330. if ( 'featured' === $GLOBALS['tab'] ) {
  331. return;
  332. }
  333. if ( 'top' === $which ) {
  334. wp_referer_field();
  335. ?>
  336. <div class="tablenav top">
  337. <div class="alignleft actions">
  338. <?php
  339. /**
  340. * Fires before the Plugin Install table header pagination is displayed.
  341. *
  342. * @since 2.7.0
  343. */
  344. do_action( 'install_plugins_table_header' );
  345. ?>
  346. </div>
  347. <?php $this->pagination( $which ); ?>
  348. <br class="clear" />
  349. </div>
  350. <?php } else { ?>
  351. <div class="tablenav bottom">
  352. <?php $this->pagination( $which ); ?>
  353. <br class="clear" />
  354. </div>
  355. <?php
  356. }
  357. }
  358. /**
  359. * @return array
  360. */
  361. protected function get_table_classes() {
  362. return array( 'widefat', $this->_args['plural'] );
  363. }
  364. /**
  365. * @return array
  366. */
  367. public function get_columns() {
  368. return array();
  369. }
  370. /**
  371. * @param object $plugin_a
  372. * @param object $plugin_b
  373. * @return int
  374. */
  375. private function order_callback( $plugin_a, $plugin_b ) {
  376. $orderby = $this->orderby;
  377. if ( ! isset( $plugin_a->$orderby, $plugin_b->$orderby ) ) {
  378. return 0;
  379. }
  380. $a = $plugin_a->$orderby;
  381. $b = $plugin_b->$orderby;
  382. if ( $a === $b ) {
  383. return 0;
  384. }
  385. if ( 'DESC' === $this->order ) {
  386. return ( $a < $b ) ? 1 : -1;
  387. } else {
  388. return ( $a < $b ) ? -1 : 1;
  389. }
  390. }
  391. public function display_rows() {
  392. $plugins_allowedtags = array(
  393. 'a' => array(
  394. 'href' => array(),
  395. 'title' => array(),
  396. 'target' => array(),
  397. ),
  398. 'abbr' => array( 'title' => array() ),
  399. 'acronym' => array( 'title' => array() ),
  400. 'code' => array(),
  401. 'pre' => array(),
  402. 'em' => array(),
  403. 'strong' => array(),
  404. 'ul' => array(),
  405. 'ol' => array(),
  406. 'li' => array(),
  407. 'p' => array(),
  408. 'br' => array(),
  409. );
  410. $plugins_group_titles = array(
  411. 'Performance' => _x( 'Performance', 'Plugin installer group title' ),
  412. 'Social' => _x( 'Social', 'Plugin installer group title' ),
  413. 'Tools' => _x( 'Tools', 'Plugin installer group title' ),
  414. );
  415. $group = null;
  416. foreach ( (array) $this->items as $plugin ) {
  417. if ( is_object( $plugin ) ) {
  418. $plugin = (array) $plugin;
  419. }
  420. // Display the group heading if there is one.
  421. if ( isset( $plugin['group'] ) && $plugin['group'] !== $group ) {
  422. if ( isset( $this->groups[ $plugin['group'] ] ) ) {
  423. $group_name = $this->groups[ $plugin['group'] ];
  424. if ( isset( $plugins_group_titles[ $group_name ] ) ) {
  425. $group_name = $plugins_group_titles[ $group_name ];
  426. }
  427. } else {
  428. $group_name = $plugin['group'];
  429. }
  430. // Starting a new group, close off the divs of the last one.
  431. if ( ! empty( $group ) ) {
  432. echo '</div></div>';
  433. }
  434. echo '<div class="plugin-group"><h3>' . esc_html( $group_name ) . '</h3>';
  435. // Needs an extra wrapping div for nth-child selectors to work.
  436. echo '<div class="plugin-items">';
  437. $group = $plugin['group'];
  438. }
  439. $title = wp_kses( $plugin['name'], $plugins_allowedtags );
  440. // Remove any HTML from the description.
  441. $description = strip_tags( $plugin['short_description'] );
  442. /**
  443. * Filters the plugin card description on the Add Plugins screen.
  444. *
  445. * @since 6.0.0
  446. *
  447. * @param string $description Plugin card description.
  448. * @param array $plugin An array of plugin data. See {@see plugins_api()}
  449. * for the list of possible values.
  450. */
  451. $description = apply_filters( 'plugin_install_description', $description, $plugin );
  452. $version = wp_kses( $plugin['version'], $plugins_allowedtags );
  453. $name = strip_tags( $title . ' ' . $version );
  454. $author = wp_kses( $plugin['author'], $plugins_allowedtags );
  455. if ( ! empty( $author ) ) {
  456. /* translators: %s: Plugin author. */
  457. $author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '</cite>';
  458. }
  459. $requires_php = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;
  460. $requires_wp = isset( $plugin['requires'] ) ? $plugin['requires'] : null;
  461. $compatible_php = is_php_version_compatible( $requires_php );
  462. $compatible_wp = is_wp_version_compatible( $requires_wp );
  463. $tested_wp = ( empty( $plugin['tested'] ) || version_compare( get_bloginfo( 'version' ), $plugin['tested'], '<=' ) );
  464. $action_links = array();
  465. if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
  466. $status = install_plugin_install_status( $plugin );
  467. switch ( $status['status'] ) {
  468. case 'install':
  469. if ( $status['url'] ) {
  470. if ( $compatible_php && $compatible_wp ) {
  471. $action_links[] = sprintf(
  472. '<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
  473. esc_attr( $plugin['slug'] ),
  474. esc_url( $status['url'] ),
  475. /* translators: %s: Plugin name and version. */
  476. esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $name ) ),
  477. esc_attr( $name ),
  478. __( 'Install Now' )
  479. );
  480. } else {
  481. $action_links[] = sprintf(
  482. '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
  483. _x( 'Cannot Install', 'plugin' )
  484. );
  485. }
  486. }
  487. break;
  488. case 'update_available':
  489. if ( $status['url'] ) {
  490. if ( $compatible_php && $compatible_wp ) {
  491. $action_links[] = sprintf(
  492. '<a class="update-now button aria-button-if-js" data-plugin="%s" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
  493. esc_attr( $status['file'] ),
  494. esc_attr( $plugin['slug'] ),
  495. esc_url( $status['url'] ),
  496. /* translators: %s: Plugin name and version. */
  497. esc_attr( sprintf( _x( 'Update %s now', 'plugin' ), $name ) ),
  498. esc_attr( $name ),
  499. __( 'Update Now' )
  500. );
  501. } else {
  502. $action_links[] = sprintf(
  503. '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
  504. _x( 'Cannot Update', 'plugin' )
  505. );
  506. }
  507. }
  508. break;
  509. case 'latest_installed':
  510. case 'newer_installed':
  511. if ( is_plugin_active( $status['file'] ) ) {
  512. $action_links[] = sprintf(
  513. '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
  514. _x( 'Active', 'plugin' )
  515. );
  516. } elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
  517. if ( $compatible_php && $compatible_wp ) {
  518. $button_text = __( 'Activate' );
  519. /* translators: %s: Plugin name. */
  520. $button_label = _x( 'Activate %s', 'plugin' );
  521. $activate_url = add_query_arg(
  522. array(
  523. '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
  524. 'action' => 'activate',
  525. 'plugin' => $status['file'],
  526. ),
  527. network_admin_url( 'plugins.php' )
  528. );
  529. if ( is_network_admin() ) {
  530. $button_text = __( 'Network Activate' );
  531. /* translators: %s: Plugin name. */
  532. $button_label = _x( 'Network Activate %s', 'plugin' );
  533. $activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url );
  534. }
  535. $action_links[] = sprintf(
  536. '<a href="%1$s" class="button activate-now" aria-label="%2$s">%3$s</a>',
  537. esc_url( $activate_url ),
  538. esc_attr( sprintf( $button_label, $plugin['name'] ) ),
  539. $button_text
  540. );
  541. } else {
  542. $action_links[] = sprintf(
  543. '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
  544. _x( 'Cannot Activate', 'plugin' )
  545. );
  546. }
  547. } else {
  548. $action_links[] = sprintf(
  549. '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
  550. _x( 'Installed', 'plugin' )
  551. );
  552. }
  553. break;
  554. }
  555. }
  556. $details_link = self_admin_url(
  557. 'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
  558. '&amp;TB_iframe=true&amp;width=600&amp;height=550'
  559. );
  560. $action_links[] = sprintf(
  561. '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
  562. esc_url( $details_link ),
  563. /* translators: %s: Plugin name and version. */
  564. esc_attr( sprintf( __( 'More information about %s' ), $name ) ),
  565. esc_attr( $name ),
  566. __( 'More Details' )
  567. );
  568. if ( ! empty( $plugin['icons']['svg'] ) ) {
  569. $plugin_icon_url = $plugin['icons']['svg'];
  570. } elseif ( ! empty( $plugin['icons']['2x'] ) ) {
  571. $plugin_icon_url = $plugin['icons']['2x'];
  572. } elseif ( ! empty( $plugin['icons']['1x'] ) ) {
  573. $plugin_icon_url = $plugin['icons']['1x'];
  574. } else {
  575. $plugin_icon_url = $plugin['icons']['default'];
  576. }
  577. /**
  578. * Filters the install action links for a plugin.
  579. *
  580. * @since 2.7.0
  581. *
  582. * @param string[] $action_links An array of plugin action links.
  583. * Defaults are links to Details and Install Now.
  584. * @param array $plugin An array of plugin data. See {@see plugins_api()}
  585. * for the list of possible values.
  586. */
  587. $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
  588. $last_updated_timestamp = strtotime( $plugin['last_updated'] );
  589. ?>
  590. <div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
  591. <?php
  592. if ( ! $compatible_php || ! $compatible_wp ) {
  593. echo '<div class="notice inline notice-error notice-alt"><p>';
  594. if ( ! $compatible_php && ! $compatible_wp ) {
  595. _e( 'This plugin does not work with your versions of WordPress and PHP.' );
  596. if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
  597. printf(
  598. /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
  599. ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
  600. self_admin_url( 'update-core.php' ),
  601. esc_url( wp_get_update_php_url() )
  602. );
  603. wp_update_php_annotation( '</p><p><em>', '</em>' );
  604. } elseif ( current_user_can( 'update_core' ) ) {
  605. printf(
  606. /* translators: %s: URL to WordPress Updates screen. */
  607. ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
  608. self_admin_url( 'update-core.php' )
  609. );
  610. } elseif ( current_user_can( 'update_php' ) ) {
  611. printf(
  612. /* translators: %s: URL to Update PHP page. */
  613. ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
  614. esc_url( wp_get_update_php_url() )
  615. );
  616. wp_update_php_annotation( '</p><p><em>', '</em>' );
  617. }
  618. } elseif ( ! $compatible_wp ) {
  619. _e( 'This plugin does not work with your version of WordPress.' );
  620. if ( current_user_can( 'update_core' ) ) {
  621. printf(
  622. /* translators: %s: URL to WordPress Updates screen. */
  623. ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
  624. self_admin_url( 'update-core.php' )
  625. );
  626. }
  627. } elseif ( ! $compatible_php ) {
  628. _e( 'This plugin does not work with your version of PHP.' );
  629. if ( current_user_can( 'update_php' ) ) {
  630. printf(
  631. /* translators: %s: URL to Update PHP page. */
  632. ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
  633. esc_url( wp_get_update_php_url() )
  634. );
  635. wp_update_php_annotation( '</p><p><em>', '</em>' );
  636. }
  637. }
  638. echo '</p></div>';
  639. }
  640. ?>
  641. <div class="plugin-card-top">
  642. <div class="name column-name">
  643. <h3>
  644. <a href="<?php echo esc_url( $details_link ); ?>" class="thickbox open-plugin-details-modal">
  645. <?php echo $title; ?>
  646. <img src="<?php echo esc_url( $plugin_icon_url ); ?>" class="plugin-icon" alt="" />
  647. </a>
  648. </h3>
  649. </div>
  650. <div class="action-links">
  651. <?php
  652. if ( $action_links ) {
  653. echo '<ul class="plugin-action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
  654. }
  655. ?>
  656. </div>
  657. <div class="desc column-description">
  658. <p><?php echo $description; ?></p>
  659. <p class="authors"><?php echo $author; ?></p>
  660. </div>
  661. </div>
  662. <div class="plugin-card-bottom">
  663. <div class="vers column-rating">
  664. <?php
  665. wp_star_rating(
  666. array(
  667. 'rating' => $plugin['rating'],
  668. 'type' => 'percent',
  669. 'number' => $plugin['num_ratings'],
  670. )
  671. );
  672. ?>
  673. <span class="num-ratings" aria-hidden="true">(<?php echo number_format_i18n( $plugin['num_ratings'] ); ?>)</span>
  674. </div>
  675. <div class="column-updated">
  676. <strong><?php _e( 'Last Updated:' ); ?></strong>
  677. <?php
  678. /* translators: %s: Human-readable time difference. */
  679. printf( __( '%s ago' ), human_time_diff( $last_updated_timestamp ) );
  680. ?>
  681. </div>
  682. <div class="column-downloaded">
  683. <?php
  684. if ( $plugin['active_installs'] >= 1000000 ) {
  685. $active_installs_millions = floor( $plugin['active_installs'] / 1000000 );
  686. $active_installs_text = sprintf(
  687. /* translators: %s: Number of millions. */
  688. _nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
  689. number_format_i18n( $active_installs_millions )
  690. );
  691. } elseif ( 0 === $plugin['active_installs'] ) {
  692. $active_installs_text = _x( 'Less Than 10', 'Active plugin installations' );
  693. } else {
  694. $active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
  695. }
  696. /* translators: %s: Number of installations. */
  697. printf( __( '%s Active Installations' ), $active_installs_text );
  698. ?>
  699. </div>
  700. <div class="column-compatibility">
  701. <?php
  702. if ( ! $tested_wp ) {
  703. echo '<span class="compatibility-untested">' . __( 'Untested with your version of WordPress' ) . '</span>';
  704. } elseif ( ! $compatible_wp ) {
  705. echo '<span class="compatibility-incompatible">' . __( '<strong>Incompatible</strong> with your version of WordPress' ) . '</span>';
  706. } else {
  707. echo '<span class="compatibility-compatible">' . __( '<strong>Compatible</strong> with your version of WordPress' ) . '</span>';
  708. }
  709. ?>
  710. </div>
  711. </div>
  712. </div>
  713. <?php
  714. }
  715. // Close off the group divs of the last one.
  716. if ( ! empty( $group ) ) {
  717. echo '</div></div>';
  718. }
  719. }
  720. }