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

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