Nenhuma Descrição

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

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