angelovcom.net

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-wp-plugin-install-list-table.php (23491B)


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