Нема описа

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

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. * @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. * - `install_plugins_table_api_args_search`
  195. * - `install_plugins_table_api_args_beta`
  196. *
  197. * @since 3.7.0
  198. *
  199. * @param array|false $args Plugin install API arguments.
  200. */
  201. $args = apply_filters( "install_plugins_table_api_args_{$tab}", $args );
  202. if ( ! $args ) {
  203. return;
  204. }
  205. $api = plugins_api( 'query_plugins', $args );
  206. if ( is_wp_error( $api ) ) {
  207. $this->error = $api;
  208. return;
  209. }
  210. $this->items = $api->plugins;
  211. if ( $this->orderby ) {
  212. uasort( $this->items, array( $this, 'order_callback' ) );
  213. }
  214. $this->set_pagination_args(
  215. array(
  216. 'total_items' => $api->info['results'],
  217. 'per_page' => $args['per_page'],
  218. )
  219. );
  220. if ( isset( $api->info['groups'] ) ) {
  221. $this->groups = $api->info['groups'];
  222. }
  223. if ( $installed_plugins ) {
  224. $js_plugins = array_fill_keys(
  225. array( 'all', 'search', 'active', 'inactive', 'recently_activated', 'mustuse', 'dropins' ),
  226. array()
  227. );
  228. $js_plugins['all'] = array_values( wp_list_pluck( $installed_plugins, 'plugin' ) );
  229. $upgrade_plugins = wp_filter_object_list( $installed_plugins, array( 'upgrade' => true ), 'and', 'plugin' );
  230. if ( $upgrade_plugins ) {
  231. $js_plugins['upgrade'] = array_values( $upgrade_plugins );
  232. }
  233. wp_localize_script(
  234. 'updates',
  235. '_wpUpdatesItemCounts',
  236. array(
  237. 'plugins' => $js_plugins,
  238. 'totals' => wp_get_update_data(),
  239. )
  240. );
  241. }
  242. }
  243. /**
  244. */
  245. public function no_items() {
  246. if ( isset( $this->error ) ) { ?>
  247. <div class="inline error"><p><?php echo $this->error->get_error_message(); ?></p>
  248. <p class="hide-if-no-js"><button class="button try-again"><?php _e( 'Try Again' ); ?></button></p>
  249. </div>
  250. <?php } else { ?>
  251. <div class="no-plugin-results"><?php _e( 'No plugins found. Try a different search.' ); ?></div>
  252. <?php
  253. }
  254. }
  255. /**
  256. * @global array $tabs
  257. * @global string $tab
  258. *
  259. * @return array
  260. */
  261. protected function get_views() {
  262. global $tabs, $tab;
  263. $display_tabs = array();
  264. foreach ( (array) $tabs as $action => $text ) {
  265. $current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : '';
  266. $href = self_admin_url( 'plugin-install.php?tab=' . $action );
  267. $display_tabs[ 'plugin-install-' . $action ] = "<a href='$href'$current_link_attributes>$text</a>";
  268. }
  269. // No longer a real tab.
  270. unset( $display_tabs['plugin-install-upload'] );
  271. return $display_tabs;
  272. }
  273. /**
  274. * Override parent views so we can use the filter bar display.
  275. */
  276. public function views() {
  277. $views = $this->get_views();
  278. /** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
  279. $views = apply_filters( "views_{$this->screen->id}", $views );
  280. $this->screen->render_screen_reader_content( 'heading_views' );
  281. ?>
  282. <div class="wp-filter">
  283. <ul class="filter-links">
  284. <?php
  285. if ( ! empty( $views ) ) {
  286. foreach ( $views as $class => $view ) {
  287. $views[ $class ] = "\t<li class='$class'>$view";
  288. }
  289. echo implode( " </li>\n", $views ) . "</li>\n";
  290. }
  291. ?>
  292. </ul>
  293. <?php install_search_form(); ?>
  294. </div>
  295. <?php
  296. }
  297. /**
  298. * Displays the plugin install table.
  299. *
  300. * Overrides the parent display() method to provide a different container.
  301. *
  302. * @since 4.0.0
  303. */
  304. public function display() {
  305. $singular = $this->_args['singular'];
  306. $data_attr = '';
  307. if ( $singular ) {
  308. $data_attr = " data-wp-lists='list:$singular'";
  309. }
  310. $this->display_tablenav( 'top' );
  311. ?>
  312. <div class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
  313. <?php
  314. $this->screen->render_screen_reader_content( 'heading_list' );
  315. ?>
  316. <div id="the-list"<?php echo $data_attr; ?>>
  317. <?php $this->display_rows_or_placeholder(); ?>
  318. </div>
  319. </div>
  320. <?php
  321. $this->display_tablenav( 'bottom' );
  322. }
  323. /**
  324. * @global string $tab
  325. *
  326. * @param string $which
  327. */
  328. protected function display_tablenav( $which ) {
  329. if ( 'featured' === $GLOBALS['tab'] ) {
  330. return;
  331. }
  332. if ( 'top' === $which ) {
  333. wp_referer_field();
  334. ?>
  335. <div class="tablenav top">
  336. <div class="alignleft actions">
  337. <?php
  338. /**
  339. * Fires before the Plugin Install table header pagination is displayed.
  340. *
  341. * @since 2.7.0
  342. */
  343. do_action( 'install_plugins_table_header' );
  344. ?>
  345. </div>
  346. <?php $this->pagination( $which ); ?>
  347. <br class="clear" />
  348. </div>
  349. <?php } else { ?>
  350. <div class="tablenav bottom">
  351. <?php $this->pagination( $which ); ?>
  352. <br class="clear" />
  353. </div>
  354. <?php
  355. }
  356. }
  357. /**
  358. * @return array
  359. */
  360. protected function get_table_classes() {
  361. return array( 'widefat', $this->_args['plural'] );
  362. }
  363. /**
  364. * @return array
  365. */
  366. public function get_columns() {
  367. return array();
  368. }
  369. /**
  370. * @param object $plugin_a
  371. * @param object $plugin_b
  372. * @return int
  373. */
  374. private function order_callback( $plugin_a, $plugin_b ) {
  375. $orderby = $this->orderby;
  376. if ( ! isset( $plugin_a->$orderby, $plugin_b->$orderby ) ) {
  377. return 0;
  378. }
  379. $a = $plugin_a->$orderby;
  380. $b = $plugin_b->$orderby;
  381. if ( $a === $b ) {
  382. return 0;
  383. }
  384. if ( 'DESC' === $this->order ) {
  385. return ( $a < $b ) ? 1 : -1;
  386. } else {
  387. return ( $a < $b ) ? -1 : 1;
  388. }
  389. }
  390. public function display_rows() {
  391. $plugins_allowedtags = array(
  392. 'a' => array(
  393. 'href' => array(),
  394. 'title' => array(),
  395. 'target' => array(),
  396. ),
  397. 'abbr' => array( 'title' => array() ),
  398. 'acronym' => array( 'title' => array() ),
  399. 'code' => array(),
  400. 'pre' => array(),
  401. 'em' => array(),
  402. 'strong' => array(),
  403. 'ul' => array(),
  404. 'ol' => array(),
  405. 'li' => array(),
  406. 'p' => array(),
  407. 'br' => array(),
  408. );
  409. $plugins_group_titles = array(
  410. 'Performance' => _x( 'Performance', 'Plugin installer group title' ),
  411. 'Social' => _x( 'Social', 'Plugin installer group title' ),
  412. 'Tools' => _x( 'Tools', 'Plugin installer group title' ),
  413. );
  414. $group = null;
  415. foreach ( (array) $this->items as $plugin ) {
  416. if ( is_object( $plugin ) ) {
  417. $plugin = (array) $plugin;
  418. }
  419. // Display the group heading if there is one.
  420. if ( isset( $plugin['group'] ) && $plugin['group'] !== $group ) {
  421. if ( isset( $this->groups[ $plugin['group'] ] ) ) {
  422. $group_name = $this->groups[ $plugin['group'] ];
  423. if ( isset( $plugins_group_titles[ $group_name ] ) ) {
  424. $group_name = $plugins_group_titles[ $group_name ];
  425. }
  426. } else {
  427. $group_name = $plugin['group'];
  428. }
  429. // Starting a new group, close off the divs of the last one.
  430. if ( ! empty( $group ) ) {
  431. echo '</div></div>';
  432. }
  433. echo '<div class="plugin-group"><h3>' . esc_html( $group_name ) . '</h3>';
  434. // Needs an extra wrapping div for nth-child selectors to work.
  435. echo '<div class="plugin-items">';
  436. $group = $plugin['group'];
  437. }
  438. $title = wp_kses( $plugin['name'], $plugins_allowedtags );
  439. // Remove any HTML from the description.
  440. $description = strip_tags( $plugin['short_description'] );
  441. /**
  442. * Filters the plugin card description on the Add Plugins screen.
  443. *
  444. * @since 6.0.0
  445. *
  446. * @param string $description Plugin card description.
  447. * @param array $plugin An array of plugin data. See {@see plugins_api()}
  448. * for the list of possible values.
  449. */
  450. $description = apply_filters( 'plugin_install_description', $description, $plugin );
  451. $version = wp_kses( $plugin['version'], $plugins_allowedtags );
  452. $name = strip_tags( $title . ' ' . $version );
  453. $author = wp_kses( $plugin['author'], $plugins_allowedtags );
  454. if ( ! empty( $author ) ) {
  455. /* translators: %s: Plugin author. */
  456. $author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '</cite>';
  457. }
  458. $requires_php = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;
  459. $requires_wp = isset( $plugin['requires'] ) ? $plugin['requires'] : null;
  460. $compatible_php = is_php_version_compatible( $requires_php );
  461. $compatible_wp = is_wp_version_compatible( $requires_wp );
  462. $tested_wp = ( empty( $plugin['tested'] ) || version_compare( get_bloginfo( 'version' ), $plugin['tested'], '<=' ) );
  463. $action_links = array();
  464. if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
  465. $status = install_plugin_install_status( $plugin );
  466. switch ( $status['status'] ) {
  467. case 'install':
  468. if ( $status['url'] ) {
  469. if ( $compatible_php && $compatible_wp ) {
  470. $action_links[] = sprintf(
  471. '<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
  472. esc_attr( $plugin['slug'] ),
  473. esc_url( $status['url'] ),
  474. /* translators: %s: Plugin name and version. */
  475. esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $name ) ),
  476. esc_attr( $name ),
  477. __( 'Install Now' )
  478. );
  479. } else {
  480. $action_links[] = sprintf(
  481. '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
  482. _x( 'Cannot Install', 'plugin' )
  483. );
  484. }
  485. }
  486. break;
  487. case 'update_available':
  488. if ( $status['url'] ) {
  489. if ( $compatible_php && $compatible_wp ) {
  490. $action_links[] = sprintf(
  491. '<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>',
  492. esc_attr( $status['file'] ),
  493. esc_attr( $plugin['slug'] ),
  494. esc_url( $status['url'] ),
  495. /* translators: %s: Plugin name and version. */
  496. esc_attr( sprintf( _x( 'Update %s now', 'plugin' ), $name ) ),
  497. esc_attr( $name ),
  498. __( 'Update Now' )
  499. );
  500. } else {
  501. $action_links[] = sprintf(
  502. '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
  503. _x( 'Cannot Update', 'plugin' )
  504. );
  505. }
  506. }
  507. break;
  508. case 'latest_installed':
  509. case 'newer_installed':
  510. if ( is_plugin_active( $status['file'] ) ) {
  511. $action_links[] = sprintf(
  512. '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
  513. _x( 'Active', 'plugin' )
  514. );
  515. } elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
  516. if ( $compatible_php && $compatible_wp ) {
  517. $button_text = __( 'Activate' );
  518. /* translators: %s: Plugin name. */
  519. $button_label = _x( 'Activate %s', 'plugin' );
  520. $activate_url = add_query_arg(
  521. array(
  522. '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
  523. 'action' => 'activate',
  524. 'plugin' => $status['file'],
  525. ),
  526. network_admin_url( 'plugins.php' )
  527. );
  528. if ( is_network_admin() ) {
  529. $button_text = __( 'Network Activate' );
  530. /* translators: %s: Plugin name. */
  531. $button_label = _x( 'Network Activate %s', 'plugin' );
  532. $activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url );
  533. }
  534. $action_links[] = sprintf(
  535. '<a href="%1$s" class="button activate-now" aria-label="%2$s">%3$s</a>',
  536. esc_url( $activate_url ),
  537. esc_attr( sprintf( $button_label, $plugin['name'] ) ),
  538. $button_text
  539. );
  540. } else {
  541. $action_links[] = sprintf(
  542. '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
  543. _x( 'Cannot Activate', 'plugin' )
  544. );
  545. }
  546. } else {
  547. $action_links[] = sprintf(
  548. '<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
  549. _x( 'Installed', 'plugin' )
  550. );
  551. }
  552. break;
  553. }
  554. }
  555. $details_link = self_admin_url(
  556. 'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
  557. '&amp;TB_iframe=true&amp;width=600&amp;height=550'
  558. );
  559. $action_links[] = sprintf(
  560. '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
  561. esc_url( $details_link ),
  562. /* translators: %s: Plugin name and version. */
  563. esc_attr( sprintf( __( 'More information about %s' ), $name ) ),
  564. esc_attr( $name ),
  565. __( 'More Details' )
  566. );
  567. if ( ! empty( $plugin['icons']['svg'] ) ) {
  568. $plugin_icon_url = $plugin['icons']['svg'];
  569. } elseif ( ! empty( $plugin['icons']['2x'] ) ) {
  570. $plugin_icon_url = $plugin['icons']['2x'];
  571. } elseif ( ! empty( $plugin['icons']['1x'] ) ) {
  572. $plugin_icon_url = $plugin['icons']['1x'];
  573. } else {
  574. $plugin_icon_url = $plugin['icons']['default'];
  575. }
  576. /**
  577. * Filters the install action links for a plugin.
  578. *
  579. * @since 2.7.0
  580. *
  581. * @param string[] $action_links An array of plugin action links.
  582. * Defaults are links to Details and Install Now.
  583. * @param array $plugin An array of plugin data. See {@see plugins_api()}
  584. * for the list of possible values.
  585. */
  586. $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
  587. $last_updated_timestamp = strtotime( $plugin['last_updated'] );
  588. ?>
  589. <div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
  590. <?php
  591. if ( ! $compatible_php || ! $compatible_wp ) {
  592. echo '<div class="notice inline notice-error notice-alt"><p>';
  593. if ( ! $compatible_php && ! $compatible_wp ) {
  594. _e( 'This plugin does not work with your versions of WordPress and PHP.' );
  595. if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
  596. printf(
  597. /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
  598. ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
  599. self_admin_url( 'update-core.php' ),
  600. esc_url( wp_get_update_php_url() )
  601. );
  602. wp_update_php_annotation( '</p><p><em>', '</em>' );
  603. } elseif ( current_user_can( 'update_core' ) ) {
  604. printf(
  605. /* translators: %s: URL to WordPress Updates screen. */
  606. ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
  607. self_admin_url( 'update-core.php' )
  608. );
  609. } elseif ( current_user_can( 'update_php' ) ) {
  610. printf(
  611. /* translators: %s: URL to Update PHP page. */
  612. ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
  613. esc_url( wp_get_update_php_url() )
  614. );
  615. wp_update_php_annotation( '</p><p><em>', '</em>' );
  616. }
  617. } elseif ( ! $compatible_wp ) {
  618. _e( 'This plugin does not work with your version of WordPress.' );
  619. if ( current_user_can( 'update_core' ) ) {
  620. printf(
  621. /* translators: %s: URL to WordPress Updates screen. */
  622. ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
  623. self_admin_url( 'update-core.php' )
  624. );
  625. }
  626. } elseif ( ! $compatible_php ) {
  627. _e( 'This plugin does not work with your version of PHP.' );
  628. if ( current_user_can( 'update_php' ) ) {
  629. printf(
  630. /* translators: %s: URL to Update PHP page. */
  631. ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
  632. esc_url( wp_get_update_php_url() )
  633. );
  634. wp_update_php_annotation( '</p><p><em>', '</em>' );
  635. }
  636. }
  637. echo '</p></div>';
  638. }
  639. ?>
  640. <div class="plugin-card-top">
  641. <div class="name column-name">
  642. <h3>
  643. <a href="<?php echo esc_url( $details_link ); ?>" class="thickbox open-plugin-details-modal">
  644. <?php echo $title; ?>
  645. <img src="<?php echo esc_url( $plugin_icon_url ); ?>" class="plugin-icon" alt="" />
  646. </a>
  647. </h3>
  648. </div>
  649. <div class="action-links">
  650. <?php
  651. if ( $action_links ) {
  652. echo '<ul class="plugin-action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
  653. }
  654. ?>
  655. </div>
  656. <div class="desc column-description">
  657. <p><?php echo $description; ?></p>
  658. <p class="authors"><?php echo $author; ?></p>
  659. </div>
  660. </div>
  661. <div class="plugin-card-bottom">
  662. <div class="vers column-rating">
  663. <?php
  664. wp_star_rating(
  665. array(
  666. 'rating' => $plugin['rating'],
  667. 'type' => 'percent',
  668. 'number' => $plugin['num_ratings'],
  669. )
  670. );
  671. ?>
  672. <span class="num-ratings" aria-hidden="true">(<?php echo number_format_i18n( $plugin['num_ratings'] ); ?>)</span>
  673. </div>
  674. <div class="column-updated">
  675. <strong><?php _e( 'Last Updated:' ); ?></strong>
  676. <?php
  677. /* translators: %s: Human-readable time difference. */
  678. printf( __( '%s ago' ), human_time_diff( $last_updated_timestamp ) );
  679. ?>
  680. </div>
  681. <div class="column-downloaded">
  682. <?php
  683. if ( $plugin['active_installs'] >= 1000000 ) {
  684. $active_installs_millions = floor( $plugin['active_installs'] / 1000000 );
  685. $active_installs_text = sprintf(
  686. /* translators: %s: Number of millions. */
  687. _nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
  688. number_format_i18n( $active_installs_millions )
  689. );
  690. } elseif ( 0 === $plugin['active_installs'] ) {
  691. $active_installs_text = _x( 'Less Than 10', 'Active plugin installations' );
  692. } else {
  693. $active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
  694. }
  695. /* translators: %s: Number of installations. */
  696. printf( __( '%s Active Installations' ), $active_installs_text );
  697. ?>
  698. </div>
  699. <div class="column-compatibility">
  700. <?php
  701. if ( ! $tested_wp ) {
  702. echo '<span class="compatibility-untested">' . __( 'Untested with your version of WordPress' ) . '</span>';
  703. } elseif ( ! $compatible_wp ) {
  704. echo '<span class="compatibility-incompatible">' . __( '<strong>Incompatible</strong> with your version of WordPress' ) . '</span>';
  705. } else {
  706. echo '<span class="compatibility-compatible">' . __( '<strong>Compatible</strong> with your version of WordPress' ) . '</span>';
  707. }
  708. ?>
  709. </div>
  710. </div>
  711. </div>
  712. <?php
  713. }
  714. // Close off the group divs of the last one.
  715. if ( ! empty( $group ) ) {
  716. echo '</div></div>';
  717. }
  718. }
  719. }