wp/wp-admin/includes/class-wp-plugin-install-list-table.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * Plugin Installer List Table class.
     3  * List Table API: WP_Plugin_Install_List_Table class
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage List_Table
     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  *
     7  * @since 3.1.0
    13  * @since 3.1.0
     8  * @access private
    14  * @access private
       
    15  *
       
    16  * @see WP_List_Table
     9  */
    17  */
    10 class WP_Plugin_Install_List_Table extends WP_List_Table {
    18 class WP_Plugin_Install_List_Table extends WP_List_Table {
    11 
    19 
    12 	public $order = 'ASC';
    20 	public $order = 'ASC';
    13 	public $orderby = null;
    21 	public $orderby = null;
    14 	public $groups = array();
    22 	public $groups = array();
    15 
    23 
    16 	private $error;
    24 	private $error;
    17 
    25 
       
    26 	/**
       
    27 	 *
       
    28 	 * @return bool
       
    29 	 */
    18 	public function ajax_user_can() {
    30 	public function ajax_user_can() {
    19 		return current_user_can('install_plugins');
    31 		return current_user_can('install_plugins');
       
    32 	}
       
    33 
       
    34 	/**
       
    35 	 * Return the list of known plugins.
       
    36 	 *
       
    37 	 * Uses the transient data from the updates API to determine the known
       
    38 	 * installed plugins.
       
    39 	 *
       
    40 	 * @since 4.9.0
       
    41 	 * @access protected
       
    42 	 *
       
    43 	 * @return array
       
    44 	 */
       
    45 	protected function get_installed_plugins() {
       
    46 		$plugins = array();
       
    47 
       
    48 		$plugin_info = get_site_transient( 'update_plugins' );
       
    49 		if ( isset( $plugin_info->no_update ) ) {
       
    50 			foreach ( $plugin_info->no_update as $plugin ) {
       
    51 				$plugin->upgrade          = false;
       
    52 				$plugins[ $plugin->slug ] = $plugin;
       
    53 			}
       
    54 		}
       
    55 
       
    56 		if ( isset( $plugin_info->response ) ) {
       
    57 			foreach ( $plugin_info->response as $plugin ) {
       
    58 				$plugin->upgrade          = true;
       
    59 				$plugins[ $plugin->slug ] = $plugin;
       
    60 			}
       
    61 		}
       
    62 
       
    63 		return $plugins;
    20 	}
    64 	}
    21 
    65 
    22 	/**
    66 	/**
    23 	 * Return a list of slugs of installed plugins, if known.
    67 	 * Return a list of slugs of installed plugins, if known.
    24 	 *
    68 	 *
    25 	 * Uses the transient data from the updates API to determine the slugs of
    69 	 * Uses the transient data from the updates API to determine the slugs of
    26 	 * known installed plugins. This might be better elsewhere, perhaps even
    70 	 * known installed plugins. This might be better elsewhere, perhaps even
    27 	 * within get_plugins().
    71 	 * within get_plugins().
    28 	 *
    72 	 *
    29 	 * @since 4.0.0
    73 	 * @since 4.0.0
    30 	 * @access protected
    74 	 *
       
    75 	 * @return array
    31 	 */
    76 	 */
    32 	protected function get_installed_plugin_slugs() {
    77 	protected function get_installed_plugin_slugs() {
    33 		$slugs = array();
    78 		return array_keys( $this->get_installed_plugins() );
    34 
    79 	}
    35 		$plugin_info = get_site_transient( 'update_plugins' );
    80 
    36 		if ( isset( $plugin_info->no_update ) ) {
    81 	/**
    37 			foreach ( $plugin_info->no_update as $plugin ) {
    82 	 *
    38 				$slugs[] = $plugin->slug;
    83 	 * @global array  $tabs
    39 			}
    84 	 * @global string $tab
    40 		}
    85 	 * @global int    $paged
    41 
    86 	 * @global string $type
    42 		if ( isset( $plugin_info->response ) ) {
    87 	 * @global string $term
    43 			foreach ( $plugin_info->response as $plugin ) {
    88 	 */
    44 				$slugs[] = $plugin->slug;
       
    45 			}
       
    46 		}
       
    47 
       
    48 		return $slugs;
       
    49 	}
       
    50 
       
    51 	public function prepare_items() {
    89 	public function prepare_items() {
    52 		include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
    90 		include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
    53 
    91 
    54 		global $tabs, $tab, $paged, $type, $term;
    92 		global $tabs, $tab, $paged, $type, $term;
    55 
    93 
    60 		$per_page = 30;
    98 		$per_page = 30;
    61 
    99 
    62 		// These are the tabs which are shown on the page
   100 		// These are the tabs which are shown on the page
    63 		$tabs = array();
   101 		$tabs = array();
    64 
   102 
    65 		if ( 'search' == $tab )
   103 		if ( 'search' === $tab ) {
    66 			$tabs['search']	= __( 'Search Results' );
   104 			$tabs['search'] = __( 'Search Results' );
    67 		$tabs['featured']  = _x( 'Featured', 'Plugin Installer' );
   105 		}
    68 		$tabs['popular']   = _x( 'Popular', 'Plugin Installer' );
   106 		if ( $tab === 'beta' || false !== strpos( get_bloginfo( 'version' ), '-' ) ) {
    69 		$tabs['recommended']   = _x( 'Recommended', 'Plugin Installer' );
   107 			$tabs['beta'] = _x( 'Beta Testing', 'Plugin Installer' );
    70 		$tabs['favorites'] = _x( 'Favorites', 'Plugin Installer' );
   108 		}
    71 		if ( $tab === 'beta' || false !== strpos( $GLOBALS['wp_version'], '-' ) ) {
   109 		$tabs['featured']    = _x( 'Featured', 'Plugin Installer' );
    72 			$tabs['beta']      = _x( 'Beta Testing', 'Plugin Installer' );
   110 		$tabs['popular']     = _x( 'Popular', 'Plugin Installer' );
    73 		}
   111 		$tabs['recommended'] = _x( 'Recommended', 'Plugin Installer' );
       
   112 		$tabs['favorites']   = _x( 'Favorites', 'Plugin Installer' );
    74 		if ( current_user_can( 'upload_plugins' ) ) {
   113 		if ( current_user_can( 'upload_plugins' ) ) {
    75 			// No longer a real tab. Here for filter compatibility.
   114 			// No longer a real tab. Here for filter compatibility.
    76 			// Gets skipped in get_views().
   115 			// Gets skipped in get_views().
    77 			$tabs['upload'] = __( 'Upload Plugin' );
   116 			$tabs['upload'] = __( 'Upload Plugin' );
    78 		}
   117 		}
    79 
   118 
    80 		$nonmenu_tabs = array( 'plugin-information' ); // Valid actions to perform which do not have a Menu item.
   119 		$nonmenu_tabs = array( 'plugin-information' ); // Valid actions to perform which do not have a Menu item.
    81 
   120 
    82 		/**
   121 		/**
    83 		 * Filter the tabs shown on the Plugin Install screen.
   122 		 * Filters the tabs shown on the Plugin Install screen.
    84 		 *
   123 		 *
    85 		 * @since 2.7.0
   124 		 * @since 2.7.0
    86 		 *
   125 		 *
    87 		 * @param array $tabs The tabs shown on the Plugin Install screen. Defaults include 'featured', 'popular',
   126 		 * @param array $tabs The tabs shown on the Plugin Install screen. Defaults include 'featured', 'popular',
    88 		 *                    'recommended', 'favorites', and 'upload'.
   127 		 *                    'recommended', 'favorites', and 'upload'.
    89 		 */
   128 		 */
    90 		$tabs = apply_filters( 'install_plugins_tabs', $tabs );
   129 		$tabs = apply_filters( 'install_plugins_tabs', $tabs );
    91 
   130 
    92 		/**
   131 		/**
    93 		 * Filter tabs not associated with a menu item on the Plugin Install screen.
   132 		 * Filters tabs not associated with a menu item on the Plugin Install screen.
    94 		 *
   133 		 *
    95 		 * @since 2.7.0
   134 		 * @since 2.7.0
    96 		 *
   135 		 *
    97 		 * @param array $nonmenu_tabs The tabs that don't have a Menu item on the Plugin Install screen.
   136 		 * @param array $nonmenu_tabs The tabs that don't have a Menu item on the Plugin Install screen.
    98 		 */
   137 		 */
    99 		$nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
   138 		$nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
   100 
   139 
   101 		// If a non-valid menu tab has been selected, And it's not a non-menu action.
   140 		// If a non-valid menu tab has been selected, And it's not a non-menu action.
   102 		if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
   141 		if ( empty( $tab ) || ( !isset( $tabs[ $tab ] ) && !in_array( $tab, (array) $nonmenu_tabs ) ) )
   103 			$tab = key( $tabs );
   142 			$tab = key( $tabs );
       
   143 
       
   144 		$installed_plugins = $this->get_installed_plugins();
   104 
   145 
   105 		$args = array(
   146 		$args = array(
   106 			'page' => $paged,
   147 			'page' => $paged,
   107 			'per_page' => $per_page,
   148 			'per_page' => $per_page,
   108 			'fields' => array(
   149 			'fields' => array(
   109 				'last_updated' => true,
   150 				'last_updated' => true,
   110 				'icons' => true,
   151 				'icons' => true,
   111 				'active_installs' => true
   152 				'active_installs' => true
   112 			),
   153 			),
   113 			// Send the locale and installed plugin slugs to the API so it can provide context-sensitive results.
   154 			// Send the locale and installed plugin slugs to the API so it can provide context-sensitive results.
   114 			'locale' => get_locale(),
   155 			'locale' => get_user_locale(),
   115 			'installed_plugins' => $this->get_installed_plugin_slugs(),
   156 			'installed_plugins' => array_keys( $installed_plugins ),
   116 		);
   157 		);
   117 
   158 
   118 		switch ( $tab ) {
   159 		switch ( $tab ) {
   119 			case 'search':
   160 			case 'search':
   120 				$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
   161 				$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
   144 			case 'recommended':
   185 			case 'recommended':
   145 				$args['browse'] = $tab;
   186 				$args['browse'] = $tab;
   146 				break;
   187 				break;
   147 
   188 
   148 			case 'favorites':
   189 			case 'favorites':
   149 				$user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
   190 				$action = 'save_wporg_username_' . get_current_user_id();
   150 				update_user_meta( get_current_user_id(), 'wporg_favorites', $user );
   191 				if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), $action ) ) {
       
   192 					$user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
       
   193 					update_user_meta( get_current_user_id(), 'wporg_favorites', $user );
       
   194 				} else {
       
   195 					$user = get_user_option( 'wporg_favorites' );
       
   196 				}
   151 				if ( $user )
   197 				if ( $user )
   152 					$args['user'] = $user;
   198 					$args['user'] = $user;
   153 				else
   199 				else
   154 					$args = false;
   200 					$args = false;
   155 
   201 
   160 				$args = false;
   206 				$args = false;
   161 				break;
   207 				break;
   162 		}
   208 		}
   163 
   209 
   164 		/**
   210 		/**
   165 		 * Filter API request arguments for each Plugin Install screen tab.
   211 		 * Filters API request arguments for each Plugin Install screen tab.
   166 		 *
   212 		 *
   167 		 * The dynamic portion of the hook name, `$tab`, refers to the plugin install tabs.
   213 		 * The dynamic portion of the hook name, `$tab`, refers to the plugin install tabs.
   168 		 * Default tabs include 'featured', 'popular', 'recommended', 'favorites', and 'upload'.
   214 		 * Default tabs include 'featured', 'popular', 'recommended', 'favorites', and 'upload'.
   169 		 *
   215 		 *
   170 		 * @since 3.7.0
   216 		 * @since 3.7.0
   171 		 *
   217 		 *
   172 		 * @param array|bool $args Plugin Install API arguments.
   218 		 * @param array|bool $args Plugin Install API arguments.
   173 		 */
   219 		 */
   174 		$args = apply_filters( "install_plugins_table_api_args_$tab", $args );
   220 		$args = apply_filters( "install_plugins_table_api_args_{$tab}", $args );
   175 
   221 
   176 		if ( !$args )
   222 		if ( !$args )
   177 			return;
   223 			return;
   178 
   224 
   179 		$api = plugins_api( 'query_plugins', $args );
   225 		$api = plugins_api( 'query_plugins', $args );
   195 		) );
   241 		) );
   196 
   242 
   197 		if ( isset( $api->info['groups'] ) ) {
   243 		if ( isset( $api->info['groups'] ) ) {
   198 			$this->groups = $api->info['groups'];
   244 			$this->groups = $api->info['groups'];
   199 		}
   245 		}
   200 	}
   246 
   201 
   247 		if ( $installed_plugins ) {
       
   248 			$js_plugins = array_fill_keys(
       
   249 				array( 'all', 'search', 'active', 'inactive', 'recently_activated', 'mustuse', 'dropins' ),
       
   250 				array()
       
   251 			);
       
   252 
       
   253 			$js_plugins['all'] = array_values( wp_list_pluck( $installed_plugins, 'plugin' ) );
       
   254 			$upgrade_plugins   = wp_filter_object_list( $installed_plugins, array( 'upgrade' => true ), 'and', 'plugin' );
       
   255 
       
   256 			if ( $upgrade_plugins ) {
       
   257 				$js_plugins['upgrade'] = array_values( $upgrade_plugins );
       
   258 			}
       
   259 
       
   260 			wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
       
   261 				'plugins' => $js_plugins,
       
   262 				'totals'  => wp_get_update_data(),
       
   263 			) );
       
   264 		}
       
   265 	}
       
   266 
       
   267 	/**
       
   268 	 */
   202 	public function no_items() {
   269 	public function no_items() {
   203 		if ( isset( $this->error ) ) {
   270 		if ( isset( $this->error ) ) { ?>
   204 			$message = $this->error->get_error_message() . '<p class="hide-if-no-js"><a href="#" class="button" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a></p>';
   271 			<div class="inline error"><p><?php echo $this->error->get_error_message(); ?></p>
   205 		} else {
   272 				<p class="hide-if-no-js"><button class="button try-again"><?php _e( 'Try Again' ); ?></button></p>
   206 			$message = __( 'No plugins match your request.' );
   273 			</div>
   207 		}
   274 		<?php } else { ?>
   208 		echo '<div class="no-plugin-results">' . $message . '</div>';
   275 			<div class="no-plugin-results"><?php _e( 'No plugins found. Try a different search.' ); ?></div>
   209 	}
   276 		<?php
   210 
   277 		}
       
   278 	}
       
   279 
       
   280 	/**
       
   281 	 *
       
   282 	 * @global array $tabs
       
   283 	 * @global string $tab
       
   284 	 *
       
   285 	 * @return array
       
   286 	 */
   211 	protected function get_views() {
   287 	protected function get_views() {
   212 		global $tabs, $tab;
   288 		global $tabs, $tab;
   213 
   289 
   214 		$display_tabs = array();
   290 		$display_tabs = array();
   215 		foreach ( (array) $tabs as $action => $text ) {
   291 		foreach ( (array) $tabs as $action => $text ) {
   216 			$class = ( $action == $tab ) ? ' current' : '';
   292 			$current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : '';
   217 			$href = self_admin_url('plugin-install.php?tab=' . $action);
   293 			$href = self_admin_url('plugin-install.php?tab=' . $action);
   218 			$display_tabs['plugin-install-'.$action] = "<a href='$href' class='$class'>$text</a>";
   294 			$display_tabs['plugin-install-'.$action] = "<a href='$href'$current_link_attributes>$text</a>";
   219 		}
   295 		}
   220 		// No longer a real tab.
   296 		// No longer a real tab.
   221 		unset( $display_tabs['plugin-install-upload'] );
   297 		unset( $display_tabs['plugin-install-upload'] );
   222 
   298 
   223 		return $display_tabs;
   299 		return $display_tabs;
   230 		$views = $this->get_views();
   306 		$views = $this->get_views();
   231 
   307 
   232 		/** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
   308 		/** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
   233 		$views = apply_filters( "views_{$this->screen->id}", $views );
   309 		$views = apply_filters( "views_{$this->screen->id}", $views );
   234 
   310 
       
   311 		$this->screen->render_screen_reader_content( 'heading_views' );
   235 ?>
   312 ?>
   236 <div class="wp-filter">
   313 <div class="wp-filter">
   237 	<ul class="filter-links">
   314 	<ul class="filter-links">
   238 		<?php
   315 		<?php
   239 		if ( ! empty( $views ) ) {
   316 		if ( ! empty( $views ) ) {
   243 			echo implode( " </li>\n", $views ) . "</li>\n";
   320 			echo implode( " </li>\n", $views ) . "</li>\n";
   244 		}
   321 		}
   245 		?>
   322 		?>
   246 	</ul>
   323 	</ul>
   247 
   324 
   248 	<?php install_search_form( isset( $views['plugin-install-search'] ) ); ?>
   325 	<?php install_search_form(); ?>
   249 </div>
   326 </div>
   250 <?php
   327 <?php
   251 	}
   328 	}
   252 
   329 
   253 	/**
   330 	/**
   264 
   341 
   265 		$this->display_tablenav( 'top' );
   342 		$this->display_tablenav( 'top' );
   266 
   343 
   267 ?>
   344 ?>
   268 <div class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
   345 <div class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
   269 
   346 <?php
       
   347 	$this->screen->render_screen_reader_content( 'heading_list' );
       
   348 ?>
   270 	<div id="the-list"<?php echo $data_attr; ?>>
   349 	<div id="the-list"<?php echo $data_attr; ?>>
   271 		<?php $this->display_rows_or_placeholder(); ?>
   350 		<?php $this->display_rows_or_placeholder(); ?>
   272 	</div>
   351 	</div>
   273 </div>
   352 </div>
   274 <?php
   353 <?php
   275 		$this->display_tablenav( 'bottom' );
   354 		$this->display_tablenav( 'bottom' );
   276 	}
   355 	}
   277 
   356 
   278 	/**
   357 	/**
       
   358 	 * @global string $tab
       
   359 	 *
   279 	 * @param string $which
   360 	 * @param string $which
   280 	 */
   361 	 */
   281 	protected function display_tablenav( $which ) {
   362 	protected function display_tablenav( $which ) {
   282 		if ( $GLOBALS['tab'] === 'featured' ) {
   363 		if ( $GLOBALS['tab'] === 'featured' ) {
   283 			return;
   364 			return;
   284 		}
   365 		}
   285 
   366 
   286 		if ( 'top' ==  $which ) {
   367 		if ( 'top' === $which ) {
   287 			wp_referer_field();
   368 			wp_referer_field();
   288 		?>
   369 		?>
   289 			<div class="tablenav top">
   370 			<div class="tablenav top">
   290 				<div class="alignleft actions">
   371 				<div class="alignleft actions">
   291 					<?php
   372 					<?php
   306 			</div>
   387 			</div>
   307 		<?php
   388 		<?php
   308 		}
   389 		}
   309 	}
   390 	}
   310 
   391 
       
   392 	/**
       
   393 	 * @return array
       
   394 	 */
   311 	protected function get_table_classes() {
   395 	protected function get_table_classes() {
   312 		return array( 'widefat', $this->_args['plural'] );
   396 		return array( 'widefat', $this->_args['plural'] );
   313 	}
   397 	}
   314 
   398 
       
   399 	/**
       
   400 	 * @return array
       
   401 	 */
   315 	public function get_columns() {
   402 	public function get_columns() {
   316 		return array();
   403 		return array();
   317 	}
   404 	}
   318 
   405 
   319 	/**
   406 	/**
   332 
   419 
   333 		if ( $a == $b ) {
   420 		if ( $a == $b ) {
   334 			return 0;
   421 			return 0;
   335 		}
   422 		}
   336 
   423 
   337 		if ( 'DESC' == $this->order ) {
   424 		if ( 'DESC' === $this->order ) {
   338 			return ( $a < $b ) ? 1 : -1;
   425 			return ( $a < $b ) ? 1 : -1;
   339 		} else {
   426 		} else {
   340 			return ( $a < $b ) ? -1 : 1;
   427 			return ( $a < $b ) ? -1 : 1;
   341 		}
   428 		}
   342 	}
   429 	}
   406 					case 'install':
   493 					case 'install':
   407 						if ( $status['url'] ) {
   494 						if ( $status['url'] ) {
   408 							/* translators: 1: Plugin name and version. */
   495 							/* translators: 1: Plugin name and version. */
   409 							$action_links[] = '<a class="install-now button" data-slug="' . esc_attr( $plugin['slug'] ) . '" href="' . esc_url( $status['url'] ) . '" aria-label="' . esc_attr( sprintf( __( 'Install %s now' ), $name ) ) . '" data-name="' . esc_attr( $name ) . '">' . __( 'Install Now' ) . '</a>';
   496 							$action_links[] = '<a class="install-now button" data-slug="' . esc_attr( $plugin['slug'] ) . '" href="' . esc_url( $status['url'] ) . '" aria-label="' . esc_attr( sprintf( __( 'Install %s now' ), $name ) ) . '" data-name="' . esc_attr( $name ) . '">' . __( 'Install Now' ) . '</a>';
   410 						}
   497 						}
   411 
       
   412 						break;
   498 						break;
       
   499 
   413 					case 'update_available':
   500 					case 'update_available':
   414 						if ( $status['url'] ) {
   501 						if ( $status['url'] ) {
   415 							/* translators: 1: Plugin name and version */
   502 							/* translators: 1: Plugin name and version */
   416 							$action_links[] = '<a class="update-now button" data-plugin="' . esc_attr( $status['file'] ) . '" data-slug="' . esc_attr( $plugin['slug'] ) . '" href="' . esc_url( $status['url'] ) . '" aria-label="' . esc_attr( sprintf( __( 'Update %s now' ), $name ) ) . '" data-name="' . esc_attr( $name ) . '">' . __( 'Update Now' ) . '</a>';
   503 							$action_links[] = '<a class="update-now button aria-button-if-js" data-plugin="' . esc_attr( $status['file'] ) . '" data-slug="' . esc_attr( $plugin['slug'] ) . '" href="' . esc_url( $status['url'] ) . '" aria-label="' . esc_attr( sprintf( __( 'Update %s now' ), $name ) ) . '" data-name="' . esc_attr( $name ) . '">' . __( 'Update Now' ) . '</a>';
   417 						}
   504 						}
   418 
       
   419 						break;
   505 						break;
       
   506 
   420 					case 'latest_installed':
   507 					case 'latest_installed':
   421 					case 'newer_installed':
   508 					case 'newer_installed':
   422 						$action_links[] = '<span class="button button-disabled" title="' . esc_attr__( 'This plugin is already installed and is up to date' ) . ' ">' . _x( 'Installed', 'plugin' ) . '</span>';
   509 						if ( is_plugin_active( $status['file'] ) ) {
       
   510 							$action_links[] = '<button type="button" class="button button-disabled" disabled="disabled">' . _x( 'Active', 'plugin' ) . '</button>';
       
   511 						} elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
       
   512 							$button_text  = __( 'Activate' );
       
   513 							/* translators: %s: Plugin name */
       
   514 							$button_label = _x( 'Activate %s', 'plugin' );
       
   515 							$activate_url = add_query_arg( array(
       
   516 								'_wpnonce'    => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
       
   517 								'action'      => 'activate',
       
   518 								'plugin'      => $status['file'],
       
   519 							), network_admin_url( 'plugins.php' ) );
       
   520 
       
   521 							if ( is_network_admin() ) {
       
   522 								$button_text  = __( 'Network Activate' );
       
   523 								/* translators: %s: Plugin name */
       
   524 								$button_label = _x( 'Network Activate %s', 'plugin' );
       
   525 								$activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url );
       
   526 							}
       
   527 
       
   528 							$action_links[] = sprintf(
       
   529 								'<a href="%1$s" class="button activate-now" aria-label="%2$s">%3$s</a>',
       
   530 								esc_url( $activate_url ),
       
   531 								esc_attr( sprintf( $button_label, $plugin['name'] ) ),
       
   532 								$button_text
       
   533 							);
       
   534 						} else {
       
   535 							$action_links[] = '<button type="button" class="button button-disabled" disabled="disabled">' . _x( 'Installed', 'plugin' ) . '</button>';
       
   536 						}
   423 						break;
   537 						break;
   424 				}
   538 				}
   425 			}
   539 			}
   426 
   540 
   427 			$details_link   = self_admin_url( 'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
   541 			$details_link   = self_admin_url( 'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
   428 								'&amp;TB_iframe=true&amp;width=600&amp;height=550' );
   542 								'&amp;TB_iframe=true&amp;width=600&amp;height=550' );
   429 
   543 
   430 			/* translators: 1: Plugin name and version. */
   544 			/* translators: 1: Plugin name and version. */
   431 			$action_links[] = '<a href="' . esc_url( $details_link ) . '" class="thickbox" aria-label="' . esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '" data-title="' . esc_attr( $name ) . '">' . __( 'More Details' ) . '</a>';
   545 			$action_links[] = '<a href="' . esc_url( $details_link ) . '" class="thickbox open-plugin-details-modal" aria-label="' . esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '" data-title="' . esc_attr( $name ) . '">' . __( 'More Details' ) . '</a>';
   432 
   546 
   433 			if ( !empty( $plugin['icons']['svg'] ) ) {
   547 			if ( !empty( $plugin['icons']['svg'] ) ) {
   434 				$plugin_icon_url = $plugin['icons']['svg'];
   548 				$plugin_icon_url = $plugin['icons']['svg'];
   435 			} elseif ( !empty( $plugin['icons']['2x'] ) ) {
   549 			} elseif ( !empty( $plugin['icons']['2x'] ) ) {
   436 				$plugin_icon_url = $plugin['icons']['2x'];
   550 				$plugin_icon_url = $plugin['icons']['2x'];
   439 			} else {
   553 			} else {
   440 				$plugin_icon_url = $plugin['icons']['default'];
   554 				$plugin_icon_url = $plugin['icons']['default'];
   441 			}
   555 			}
   442 
   556 
   443 			/**
   557 			/**
   444 			 * Filter the install action links for a plugin.
   558 			 * Filters the install action links for a plugin.
   445 			 *
   559 			 *
   446 			 * @since 2.7.0
   560 			 * @since 2.7.0
   447 			 *
   561 			 *
   448 			 * @param array $action_links An array of plugin action hyperlinks. Defaults are links to Details and Install Now.
   562 			 * @param array $action_links An array of plugin action hyperlinks. Defaults are links to Details and Install Now.
   449 			 * @param array $plugin       The plugin currently being listed.
   563 			 * @param array $plugin       The plugin currently being listed.
   450 			 */
   564 			 */
   451 			$action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
   565 			$action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
   452 
   566 
   453 			$date_format = __( 'M j, Y @ H:i' );
       
   454 			$last_updated_timestamp = strtotime( $plugin['last_updated'] );
   567 			$last_updated_timestamp = strtotime( $plugin['last_updated'] );
   455 		?>
   568 		?>
   456 		<div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
   569 		<div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
   457 			<div class="plugin-card-top">
   570 			<div class="plugin-card-top">
   458 				<a href="<?php echo esc_url( $details_link ); ?>" class="thickbox plugin-icon"><img src="<?php echo esc_attr( $plugin_icon_url ) ?>" /></a>
       
   459 				<div class="name column-name">
   571 				<div class="name column-name">
   460 					<h4><a href="<?php echo esc_url( $details_link ); ?>" class="thickbox"><?php echo $title; ?></a></h4>
   572 					<h3>
       
   573 						<a href="<?php echo esc_url( $details_link ); ?>" class="thickbox open-plugin-details-modal">
       
   574 						<?php echo $title; ?>
       
   575 						<img src="<?php echo esc_attr( $plugin_icon_url ) ?>" class="plugin-icon" alt="">
       
   576 						</a>
       
   577 					</h3>
   461 				</div>
   578 				</div>
   462 				<div class="action-links">
   579 				<div class="action-links">
   463 					<?php
   580 					<?php
   464 						if ( $action_links ) {
   581 						if ( $action_links ) {
   465 							echo '<ul class="plugin-action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
   582 							echo '<ul class="plugin-action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
   472 				</div>
   589 				</div>
   473 			</div>
   590 			</div>
   474 			<div class="plugin-card-bottom">
   591 			<div class="plugin-card-bottom">
   475 				<div class="vers column-rating">
   592 				<div class="vers column-rating">
   476 					<?php wp_star_rating( array( 'rating' => $plugin['rating'], 'type' => 'percent', 'number' => $plugin['num_ratings'] ) ); ?>
   593 					<?php wp_star_rating( array( 'rating' => $plugin['rating'], 'type' => 'percent', 'number' => $plugin['num_ratings'] ) ); ?>
   477 					<span class="num-ratings">(<?php echo number_format_i18n( $plugin['num_ratings'] ); ?>)</span>
   594 					<span class="num-ratings" aria-hidden="true">(<?php echo number_format_i18n( $plugin['num_ratings'] ); ?>)</span>
   478 				</div>
   595 				</div>
   479 				<div class="column-updated">
   596 				<div class="column-updated">
   480 					<strong><?php _e( 'Last Updated:' ); ?></strong> <span title="<?php echo esc_attr( date_i18n( $date_format, $last_updated_timestamp ) ); ?>">
   597 					<strong><?php _e( 'Last Updated:' ); ?></strong> <?php printf( __( '%s ago' ), human_time_diff( $last_updated_timestamp ) ); ?>
   481 						<?php printf( __( '%s ago' ), human_time_diff( $last_updated_timestamp ) ); ?>
       
   482 					</span>
       
   483 				</div>
   598 				</div>
   484 				<div class="column-downloaded">
   599 				<div class="column-downloaded">
   485 					<?php
   600 					<?php
   486 					if ( $plugin['active_installs'] >= 1000000 ) {
   601 					if ( $plugin['active_installs'] >= 1000000 ) {
   487 						$active_installs_text = _x( '1+ Million', 'Active plugin installs' );
   602 						$active_installs_text = _x( '1+ Million', 'Active plugin installations' );
       
   603 					} elseif ( 0 == $plugin['active_installs'] ) {
       
   604 						$active_installs_text = _x( 'Less Than 10', 'Active plugin installations' );
   488 					} else {
   605 					} else {
   489 						$active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
   606 						$active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
   490 					}
   607 					}
   491 					printf( __( '%s Active Installs' ), $active_installs_text );
   608 					printf( __( '%s Active Installations' ), $active_installs_text );
   492 					?>
   609 					?>
   493 				</div>
   610 				</div>
   494 				<div class="column-compatibility">
   611 				<div class="column-compatibility">
   495 					<?php
   612 					<?php
   496 					if ( ! empty( $plugin['tested'] ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $plugin['tested'] ) ), $plugin['tested'], '>' ) ) {
   613 					$wp_version = get_bloginfo( 'version' );
       
   614 
       
   615 					if ( ! empty( $plugin['tested'] ) && version_compare( substr( $wp_version, 0, strlen( $plugin['tested'] ) ), $plugin['tested'], '>' ) ) {
   497 						echo '<span class="compatibility-untested">' . __( 'Untested with your version of WordPress' ) . '</span>';
   616 						echo '<span class="compatibility-untested">' . __( 'Untested with your version of WordPress' ) . '</span>';
   498 					} elseif ( ! empty( $plugin['requires'] ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $plugin['requires'] ) ), $plugin['requires'], '<' ) ) {
   617 					} elseif ( ! empty( $plugin['requires'] ) && version_compare( substr( $wp_version, 0, strlen( $plugin['requires'] ) ), $plugin['requires'], '<' ) ) {
   499 						echo '<span class="compatibility-incompatible">' . __( '<strong>Incompatible</strong> with your version of WordPress' ) . '</span>';
   618 						echo '<span class="compatibility-incompatible">' . __( '<strong>Incompatible</strong> with your version of WordPress' ) . '</span>';
   500 					} else {
   619 					} else {
   501 						echo '<span class="compatibility-compatible">' . __( '<strong>Compatible</strong> with your version of WordPress' ) . '</span>';
   620 						echo '<span class="compatibility-compatible">' . __( '<strong>Compatible</strong> with your version of WordPress' ) . '</span>';
   502 					}
   621 					}
   503 					?>
   622 					?>