wp/wp-admin/includes/plugin-install.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
     9 /**
     9 /**
    10  * Retrieve plugin installer pages from WordPress Plugins API.
    10  * Retrieves plugin installer pages from the WordPress.org Plugins API.
    11  *
    11  *
    12  * It is possible for a plugin to override the Plugin API result with three
    12  * It is possible for a plugin to override the Plugin API result with three
    13  * filters. Assume this is for plugins, which can extend on the Plugin Info to
    13  * filters. Assume this is for plugins, which can extend on the Plugin Info to
    14  * offer more choices. This is very powerful and must be used with care, when
    14  * offer more choices. This is very powerful and must be used with care when
    15  * overriding the filters.
    15  * overriding the filters.
    16  *
    16  *
    17  * The first filter, 'plugins_api_args', is for the args and gives the action as
    17  * The first filter, {@see 'plugins_api_args'}, is for the args and gives the action
    18  * the second parameter. The hook for 'plugins_api_args' must ensure that an
    18  * as the second parameter. The hook for {@see 'plugins_api_args'} must ensure that
    19  * object is returned.
    19  * an object is returned.
    20  *
    20  *
    21  * The second filter, 'plugins_api', is the result that would be returned.
    21  * The second filter, {@see 'plugins_api'}, allows a plugin to override the WordPress.org
       
    22  * Plugin Installation API entirely. If `$action` is 'query_plugins' or 'plugin_information',
       
    23  * an object MUST be passed. If `$action` is 'hot_tags' or 'hot_categories', an array MUST
       
    24  * be passed.
       
    25  *
       
    26  * Finally, the third filter, {@see 'plugins_api_result'}, makes it possible to filter the
       
    27  * response object or array, depending on the `$action` type.
       
    28  *
       
    29  * Supported arguments per action:
       
    30  *
       
    31  * | Argument Name        | query_plugins | plugin_information | hot_tags | hot_categories |
       
    32  * | -------------------- | :-----------: | :----------------: | :------: | :------------: |
       
    33  * | `$slug`              | No            |  Yes               | No       | No             |
       
    34  * | `$per_page`          | Yes           |  No                | No       | No             |
       
    35  * | `$page`              | Yes           |  No                | No       | No             |
       
    36  * | `$number`            | No            |  No                | Yes      | Yes            |
       
    37  * | `$search`            | Yes           |  No                | No       | No             |
       
    38  * | `$tag`               | Yes           |  No                | No       | No             |
       
    39  * | `$author`            | Yes           |  No                | No       | No             |
       
    40  * | `$user`              | Yes           |  No                | No       | No             |
       
    41  * | `$browse`            | Yes           |  No                | No       | No             |
       
    42  * | `$locale`            | Yes           |  Yes               | No       | No             |
       
    43  * | `$installed_plugins` | Yes           |  No                | No       | No             |
       
    44  * | `$is_ssl`            | Yes           |  Yes               | No       | No             |
       
    45  * | `$fields`            | Yes           |  Yes               | No       | No             |
    22  *
    46  *
    23  * @since 2.7.0
    47  * @since 2.7.0
    24  *
    48  *
    25  * @param string $action
    49  * @param string       $action API action to perform: 'query_plugins', 'plugin_information',
    26  * @param array|object $args Optional. Arguments to serialize for the Plugin Info API.
    50  *                             'hot_tags' or 'hot_categories'.
    27  * @return object plugins_api response object on success, WP_Error on failure.
    51  * @param array|object $args   {
    28  */
    52  *     Optional. Array or object of arguments to serialize for the Plugin Info API.
    29 function plugins_api($action, $args = null) {
    53  *
       
    54  *     @type string  $slug              The plugin slug. Default empty.
       
    55  *     @type int     $per_page          Number of plugins per page. Default 24.
       
    56  *     @type int     $page              Number of current page. Default 1.
       
    57  *     @type int     $number            Number of tags or categories to be queried.
       
    58  *     @type string  $search            A search term. Default empty.
       
    59  *     @type string  $tag               Tag to filter plugins. Default empty.
       
    60  *     @type string  $author            Username of an plugin author to filter plugins. Default empty.
       
    61  *     @type string  $user              Username to query for their favorites. Default empty.
       
    62  *     @type string  $browse            Browse view: 'popular', 'new', 'beta', 'recommended'.
       
    63  *     @type string  $locale            Locale to provide context-sensitive results. Default is the value
       
    64  *                                      of get_locale().
       
    65  *     @type string  $installed_plugins Installed plugins to provide context-sensitive results.
       
    66  *     @type bool    $is_ssl            Whether links should be returned with https or not. Default false.
       
    67  *     @type array   $fields            {
       
    68  *         Array of fields which should or should not be returned.
       
    69  *
       
    70  *         @type bool $short_description Whether to return the plugin short description. Default true.
       
    71  *         @type bool $description       Whether to return the plugin full description. Default false.
       
    72  *         @type bool $sections          Whether to return the plugin readme sections: description, installation,
       
    73  *                                       FAQ, screenshots, other notes, and changelog. Default false.
       
    74  *         @type bool $tested            Whether to return the 'Compatible up to' value. Default true.
       
    75  *         @type bool $requires          Whether to return the required WordPress version. Default true.
       
    76  *         @type bool $rating            Whether to return the rating in percent and total number of ratings.
       
    77  *                                       Default true.
       
    78  *         @type bool $ratings           Whether to return the number of rating for each star (1-5). Default true.
       
    79  *         @type bool $downloaded        Whether to return the download count. Default true.
       
    80  *         @type bool $downloadlink      Whether to return the download link for the package. Default true.
       
    81  *         @type bool $last_updated      Whether to return the date of the last update. Default true.
       
    82  *         @type bool $added             Whether to return the date when the plugin was added to the wordpress.org
       
    83  *                                       repository. Default true.
       
    84  *         @type bool $tags              Whether to return the assigned tags. Default true.
       
    85  *         @type bool $compatibility     Whether to return the WordPress compatibility list. Default true.
       
    86  *         @type bool $homepage          Whether to return the plugin homepage link. Default true.
       
    87  *         @type bool $versions          Whether to return the list of all available versions. Default false.
       
    88  *         @type bool $donate_link       Whether to return the donation link. Default true.
       
    89  *         @type bool $reviews           Whether to return the plugin reviews. Default false.
       
    90  *         @type bool $banners           Whether to return the banner images links. Default false.
       
    91  *         @type bool $icons             Whether to return the icon links. Default false.
       
    92  *         @type bool $active_installs   Whether to return the number of active installations. Default false.
       
    93  *         @type bool $group             Whether to return the assigned group. Default false.
       
    94  *         @type bool $contributors      Whether to return the list of contributors. Default false.
       
    95  *     }
       
    96  * }
       
    97  * @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the
       
    98  *         {@link https://developer.wordpress.org/reference/functions/plugins_api/ function reference article}
       
    99  *         for more information on the make-up of possible return values depending on the value of `$action`.
       
   100  */
       
   101 function plugins_api( $action, $args = array() ) {
    30 
   102 
    31 	if ( is_array( $args ) ) {
   103 	if ( is_array( $args ) ) {
    32 		$args = (object) $args;
   104 		$args = (object) $args;
    33 	}
   105 	}
    34 
   106 
    35 	if ( ! isset( $args->per_page ) ) {
   107 	if ( ! isset( $args->per_page ) ) {
    36 		$args->per_page = 24;
   108 		$args->per_page = 24;
    37 	}
   109 	}
    38 
   110 
    39 	if ( ! isset( $args->locale ) ) {
   111 	if ( ! isset( $args->locale ) ) {
    40 		$args->locale = get_locale();
   112 		$args->locale = get_user_locale();
    41 	}
   113 	}
    42 
   114 
    43 	/**
   115 	/**
    44 	 * Override the Plugin Install API arguments.
   116 	 * Filters the WordPress.org Plugin Installation API arguments.
    45 	 *
   117 	 *
    46 	 * Please ensure that an object is returned.
   118 	 * Important: An object MUST be returned to this filter.
    47 	 *
   119 	 *
    48 	 * @since 2.7.0
   120 	 * @since 2.7.0
    49 	 *
   121 	 *
    50 	 * @param object $args   Plugin API arguments.
   122 	 * @param object $args   Plugin API arguments.
    51 	 * @param string $action The type of information being requested from the Plugin Install API.
   123 	 * @param string $action The type of information being requested from the Plugin Installation API.
    52 	 */
   124 	 */
    53 	$args = apply_filters( 'plugins_api_args', $args, $action );
   125 	$args = apply_filters( 'plugins_api_args', $args, $action );
    54 
   126 
    55 	/**
   127 	/**
    56 	 * Allows a plugin to override the WordPress.org Plugin Install API entirely.
   128 	 * Filters the response for the current WordPress.org Plugin Installation API request.
    57 	 *
   129 	 *
    58 	 * Please ensure that an object is returned.
   130 	 * Passing a non-false value will effectively short-circuit the WordPress.org API request.
       
   131 	 *
       
   132 	 * If `$action` is 'query_plugins' or 'plugin_information', an object MUST be passed.
       
   133 	 * If `$action` is 'hot_tags' or 'hot_categories', an array should be passed.
    59 	 *
   134 	 *
    60 	 * @since 2.7.0
   135 	 * @since 2.7.0
    61 	 *
   136 	 *
    62 	 * @param bool|object $result The result object. Default false.
   137 	 * @param false|object|array $result The result object or array. Default false.
    63 	 * @param string      $action The type of information being requested from the Plugin Install API.
   138 	 * @param string             $action The type of information being requested from the Plugin Installation API.
    64 	 * @param object      $args   Plugin API arguments.
   139 	 * @param object             $args   Plugin API arguments.
    65 	 */
   140 	 */
    66 	$res = apply_filters( 'plugins_api', false, $action, $args );
   141 	$res = apply_filters( 'plugins_api', false, $action, $args );
    67 
   142 
    68 	if ( false === $res ) {
   143 	if ( false === $res ) {
       
   144 		// include an unmodified $wp_version
       
   145 		include( ABSPATH . WPINC . '/version.php' );
       
   146 
    69 		$url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
   147 		$url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
    70 		if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
   148 		if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
    71 			$url = set_url_scheme( $url, 'https' );
   149 			$url = set_url_scheme( $url, 'https' );
    72 
   150 
    73 		$http_args = array(
   151 		$http_args = array(
    74 			'timeout' => 15,
   152 			'timeout' => 15,
       
   153 			'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
    75 			'body' => array(
   154 			'body' => array(
    76 				'action' => $action,
   155 				'action' => $action,
    77 				'request' => serialize( $args )
   156 				'request' => serialize( $args )
    78 			)
   157 			)
    79 		);
   158 		);
    80 		$request = wp_remote_post( $url, $http_args );
   159 		$request = wp_remote_post( $url, $http_args );
    81 
   160 
    82 		if ( $ssl && is_wp_error( $request ) ) {
   161 		if ( $ssl && is_wp_error( $request ) ) {
    83 			trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE );
   162 			trigger_error(
       
   163 				sprintf(
       
   164 					/* translators: %s: support forums URL */
       
   165 					__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
       
   166 					__( 'https://wordpress.org/support/' )
       
   167 				) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
       
   168 				headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
       
   169 			);
    84 			$request = wp_remote_post( $http_url, $http_args );
   170 			$request = wp_remote_post( $http_url, $http_args );
    85 		}
   171 		}
    86 
   172 
    87 		if ( is_wp_error($request) ) {
   173 		if ( is_wp_error($request) ) {
    88 			$res = new WP_Error('plugins_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), $request->get_error_message() );
   174 			$res = new WP_Error( 'plugins_api_failed',
       
   175 				sprintf(
       
   176 					/* translators: %s: support forums URL */
       
   177 					__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
       
   178 					__( 'https://wordpress.org/support/' )
       
   179 				),
       
   180 				$request->get_error_message()
       
   181 			);
    89 		} else {
   182 		} else {
    90 			$res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
   183 			$res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
    91 			if ( ! is_object( $res ) && ! is_array( $res ) )
   184 			if ( ! is_object( $res ) && ! is_array( $res ) ) {
    92 				$res = new WP_Error('plugins_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), wp_remote_retrieve_body( $request ) );
   185 				$res = new WP_Error( 'plugins_api_failed',
       
   186 					sprintf(
       
   187 						/* translators: %s: support forums URL */
       
   188 						__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
       
   189 						__( 'https://wordpress.org/support/' )
       
   190 					),
       
   191 					wp_remote_retrieve_body( $request )
       
   192 				);
       
   193 			}
    93 		}
   194 		}
    94 	} elseif ( !is_wp_error($res) ) {
   195 	} elseif ( !is_wp_error($res) ) {
    95 		$res->external = true;
   196 		$res->external = true;
    96 	}
   197 	}
    97 
   198 
    98 	/**
   199 	/**
    99 	 * Filter the Plugin Install API response results.
   200 	 * Filters the Plugin Installation API response results.
   100 	 *
   201 	 *
   101 	 * @since 2.7.0
   202 	 * @since 2.7.0
   102 	 *
   203 	 *
   103 	 * @param object|WP_Error $res    Response object or WP_Error.
   204 	 * @param object|WP_Error $res    Response object or WP_Error.
   104 	 * @param string          $action The type of information being requested from the Plugin Install API.
   205 	 * @param string          $action The type of information being requested from the Plugin Installation API.
   105 	 * @param object          $args   Plugin API arguments.
   206 	 * @param object          $args   Plugin API arguments.
   106 	 */
   207 	 */
   107 	return apply_filters( 'plugins_api_result', $res, $action, $args );
   208 	return apply_filters( 'plugins_api_result', $res, $action, $args );
   108 }
   209 }
   109 
   210 
   128 	set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS );
   229 	set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS );
   129 
   230 
   130 	return $tags;
   231 	return $tags;
   131 }
   232 }
   132 
   233 
       
   234 /**
       
   235  * @since 2.7.0
       
   236  */
   133 function install_dashboard() {
   237 function install_dashboard() {
   134 	?>
   238 	?>
   135 	<p><?php printf( __( 'Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the <a href="%1$s">WordPress Plugin Directory</a> or upload a plugin in .zip format via <a href="%2$s">this page</a>.' ), 'https://wordpress.org/plugins/', self_admin_url( 'plugin-install.php?tab=upload' ) ); ?></p>
   239 	<p><?php printf( __( 'Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the <a href="%1$s">WordPress Plugin Directory</a> or upload a plugin in .zip format by clicking the button at the top of this page.' ), __( 'https://wordpress.org/plugins/' ) ); ?></p>
   136 
   240 
   137 	<?php display_plugins_table(); ?>
   241 	<?php display_plugins_table(); ?>
   138 
   242 
   139 	<h3><?php _e( 'Popular tags' ) ?></h3>
   243 	<div class="plugins-popular-tags-wrapper">
       
   244 	<h2><?php _e( 'Popular tags' ) ?></h2>
   140 	<p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ) ?></p>
   245 	<p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ) ?></p>
   141 	<?php
   246 	<?php
   142 
   247 
   143 	$api_tags = install_popular_tags();
   248 	$api_tags = install_popular_tags();
   144 
   249 
   146 	if ( is_wp_error($api_tags) ) {
   251 	if ( is_wp_error($api_tags) ) {
   147 		echo $api_tags->get_error_message();
   252 		echo $api_tags->get_error_message();
   148 	} else {
   253 	} else {
   149 		//Set up the tags in a way which can be interpreted by wp_generate_tag_cloud()
   254 		//Set up the tags in a way which can be interpreted by wp_generate_tag_cloud()
   150 		$tags = array();
   255 		$tags = array();
   151 		foreach ( (array)$api_tags as $tag )
   256 		foreach ( (array) $api_tags as $tag ) {
   152 			$tags[ $tag['name'] ] = (object) array(
   257 			$url = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) );
   153 									'link' => esc_url( self_admin_url('plugin-install.php?tab=search&type=tag&s=' . urlencode($tag['name'])) ),
   258 			$data = array(
   154 									'name' => $tag['name'],
   259 				'link' => esc_url( $url ),
   155 									'id' => sanitize_title_with_dashes($tag['name']),
   260 				'name' => $tag['name'],
   156 									'count' => $tag['count'] );
   261 				'slug' => $tag['slug'],
       
   262 				'id' => sanitize_title_with_dashes( $tag['name'] ),
       
   263 				'count' => $tag['count']
       
   264 			);
       
   265 			$tags[ $tag['name'] ] = (object) $data;
       
   266 		}
   157 		echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%s plugin'), 'multiple_text' => __('%s plugins') ) );
   267 		echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%s plugin'), 'multiple_text' => __('%s plugins') ) );
   158 	}
   268 	}
   159 	echo '</p><br class="clear" />';
   269 	echo '</p><br class="clear" /></div>';
   160 }
   270 }
   161 add_action( 'install_plugins_featured', 'install_dashboard' );
   271 
   162 
   272 /**
   163 /**
   273  * Displays a search form for searching plugins.
   164  * Display search form for searching plugins.
       
   165  *
   274  *
   166  * @since 2.7.0
   275  * @since 2.7.0
   167  */
   276  * @since 4.6.0 The `$type_selector` parameter was deprecated.
   168 function install_search_form( $type_selector = true ) {
   277  *
   169 	$type = isset($_REQUEST['type']) ? wp_unslash( $_REQUEST['type'] ) : 'term';
   278  * @param bool $deprecated Not used.
   170 	$term = isset($_REQUEST['s']) ? wp_unslash( $_REQUEST['s'] ) : '';
   279  */
   171 	$input_attrs = '';
   280 function install_search_form( $deprecated = true ) {
   172 	$button_type = 'button screen-reader-text';
   281 	$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
   173 
   282 	$term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
   174 	// assume no $type_selector means it's a simplified search form
       
   175 	if ( ! $type_selector ) {
       
   176 		$input_attrs = 'class="wp-filter-search" placeholder="' . esc_attr__( 'Search Plugins' ) . '" ';
       
   177 	}
       
   178 
       
   179 	?><form class="search-form search-plugins" method="get">
   283 	?><form class="search-form search-plugins" method="get">
   180 		<input type="hidden" name="tab" value="search" />
   284 		<input type="hidden" name="tab" value="search" />
   181 		<?php if ( $type_selector ) : ?>
   285 		<label class="screen-reader-text" for="typeselector"><?php _e( 'Search plugins by:' ); ?></label>
   182 		<select name="type" id="typeselector">
   286 		<select name="type" id="typeselector">
   183 			<option value="term"<?php selected('term', $type) ?>><?php _e('Keyword'); ?></option>
   287 			<option value="term"<?php selected( 'term', $type ); ?>><?php _e( 'Keyword' ); ?></option>
   184 			<option value="author"<?php selected('author', $type) ?>><?php _e('Author'); ?></option>
   288 			<option value="author"<?php selected( 'author', $type ); ?>><?php _e( 'Author' ); ?></option>
   185 			<option value="tag"<?php selected('tag', $type) ?>><?php _ex('Tag', 'Plugin Installer'); ?></option>
   289 			<option value="tag"<?php selected( 'tag', $type ); ?>><?php _ex( 'Tag', 'Plugin Installer' ); ?></option>
   186 		</select>
   290 		</select>
   187 		<?php endif; ?>
   291 		<label><span class="screen-reader-text"><?php _e( 'Search Plugins' ); ?></span>
   188 		<label><span class="screen-reader-text"><?php _e('Search Plugins'); ?></span>
   292 			<input type="search" name="s" value="<?php echo esc_attr( $term ) ?>" class="wp-filter-search" placeholder="<?php esc_attr_e( 'Search plugins...' ); ?>" />
   189 			<input type="search" name="s" value="<?php echo esc_attr($term) ?>" <?php echo $input_attrs; ?>/>
       
   190 		</label>
   293 		</label>
   191 		<?php submit_button( __( 'Search Plugins' ), $button_type, false, false, array( 'id' => 'search-submit' ) ); ?>
   294 		<?php submit_button( __( 'Search Plugins' ), 'hide-if-js', false, false, array( 'id' => 'search-submit' ) ); ?>
   192 	</form><?php
   295 	</form><?php
   193 }
   296 }
   194 
   297 
   195 /**
   298 /**
   196  * Upload from zip
   299  * Upload from zip
   199 function install_plugins_upload() {
   302 function install_plugins_upload() {
   200 ?>
   303 ?>
   201 <div class="upload-plugin">
   304 <div class="upload-plugin">
   202 	<p class="install-help"><?php _e('If you have a plugin in a .zip format, you may install it by uploading it here.'); ?></p>
   305 	<p class="install-help"><?php _e('If you have a plugin in a .zip format, you may install it by uploading it here.'); ?></p>
   203 	<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url('update.php?action=upload-plugin'); ?>">
   306 	<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url('update.php?action=upload-plugin'); ?>">
   204 		<?php wp_nonce_field( 'plugin-upload'); ?>
   307 		<?php wp_nonce_field( 'plugin-upload' ); ?>
   205 		<label class="screen-reader-text" for="pluginzip"><?php _e('Plugin zip file'); ?></label>
   308 		<label class="screen-reader-text" for="pluginzip"><?php _e( 'Plugin zip file' ); ?></label>
   206 		<input type="file" id="pluginzip" name="pluginzip" />
   309 		<input type="file" id="pluginzip" name="pluginzip" />
   207 		<?php submit_button( __( 'Install Now' ), 'button', 'install-plugin-submit', false ); ?>
   310 		<?php submit_button( __( 'Install Now' ), '', 'install-plugin-submit', false ); ?>
   208 	</form>
   311 	</form>
   209 </div>
   312 </div>
   210 <?php
   313 <?php
   211 }
   314 }
   212 add_action('install_plugins_upload', 'install_plugins_upload' );
       
   213 
   315 
   214 /**
   316 /**
   215  * Show a username form for the favorites page
   317  * Show a username form for the favorites page
   216  * @since 3.5.0
   318  * @since 3.5.0
   217  *
   319  *
   218  */
   320  */
   219 function install_plugins_favorites_form() {
   321 function install_plugins_favorites_form() {
   220 	$user = ! empty( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
   322 	$user   = get_user_option( 'wporg_favorites' );
       
   323 	$action = 'save_wporg_username_' . get_current_user_id();
   221 	?>
   324 	?>
   222 	<p class="install-help"><?php _e( 'If you have marked plugins as favorites on WordPress.org, you can browse them here.' ); ?></p>
   325 	<p class="install-help"><?php _e( 'If you have marked plugins as favorites on WordPress.org, you can browse them here.' ); ?></p>
   223 	<form method="get">
   326 	<form method="get">
   224 		<input type="hidden" name="tab" value="favorites" />
   327 		<input type="hidden" name="tab" value="favorites" />
   225 		<p>
   328 		<p>
   226 			<label for="user"><?php _e( 'Your WordPress.org username:' ); ?></label>
   329 			<label for="user"><?php _e( 'Your WordPress.org username:' ); ?></label>
   227 			<input type="search" id="user" name="user" value="<?php echo esc_attr( $user ); ?>" />
   330 			<input type="search" id="user" name="user" value="<?php echo esc_attr( $user ); ?>" />
   228 			<input type="submit" class="button" value="<?php esc_attr_e( 'Get Favorites' ); ?>" />
   331 			<input type="submit" class="button" value="<?php esc_attr_e( 'Get Favorites' ); ?>" />
       
   332 			<input type="hidden" id="wporg-username-nonce" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( $action ) ); ?>" />
   229 		</p>
   333 		</p>
   230 	</form>
   334 	</form>
   231 	<?php
   335 	<?php
   232 }
   336 }
   233 
   337 
   234 /**
   338 /**
   235  * Display plugin content based on plugin list.
   339  * Display plugin content based on plugin list.
   236  *
   340  *
   237  * @since 2.7.0
   341  * @since 2.7.0
       
   342  *
       
   343  * @global WP_List_Table $wp_list_table
   238  */
   344  */
   239 function display_plugins_table() {
   345 function display_plugins_table() {
   240 	global $wp_list_table;
   346 	global $wp_list_table;
   241 
   347 
   242 	switch ( current_filter() ) {
   348 	switch ( current_filter() ) {
   246 			}
   352 			}
   247 			break;
   353 			break;
   248 		case 'install_plugins_recommended' :
   354 		case 'install_plugins_recommended' :
   249 			echo '<p>' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '</p>';
   355 			echo '<p>' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '</p>';
   250 			break;
   356 			break;
       
   357 		case 'install_plugins_beta' :
       
   358 			printf(
       
   359 				'<p>' . __( 'You are using a development version of WordPress. These feature plugins are also under development. <a href="%s">Learn more</a>.' ) . '</p>',
       
   360 				'https://make.wordpress.org/core/handbook/about/release-cycle/features-as-plugins/'
       
   361 			);
       
   362 			break;
   251 	}
   363 	}
   252 
   364 
   253 	?>
   365 	?>
   254 	<form id="plugin-filter" method="post">
   366 	<form id="plugin-filter" method="post">
   255 		<?php $wp_list_table->display(); ?>
   367 		<?php $wp_list_table->display(); ?>
   256 	</form>
   368 	</form>
   257 	<?php
   369 	<?php
   258 }
   370 }
   259 add_action( 'install_plugins_search',      'display_plugins_table' );
       
   260 add_action( 'install_plugins_popular',     'display_plugins_table' );
       
   261 add_action( 'install_plugins_recommended', 'display_plugins_table' );
       
   262 add_action( 'install_plugins_new',         'display_plugins_table' );
       
   263 add_action( 'install_plugins_beta',        'display_plugins_table' );
       
   264 add_action( 'install_plugins_favorites',   'display_plugins_table' );
       
   265 
   371 
   266 /**
   372 /**
   267  * Determine the status we can perform on a plugin.
   373  * Determine the status we can perform on a plugin.
   268  *
   374  *
   269  * @since 3.0.0
   375  * @since 3.0.0
       
   376  *
       
   377  * @param  array|object $api  Data about the plugin retrieved from the API.
       
   378  * @param  bool         $loop Optional. Disable further loops. Default false.
       
   379  * @return array {
       
   380  *     Plugin installation status data.
       
   381  *
       
   382  *     @type string $status  Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'.
       
   383  *     @type string $url     Plugin installation URL.
       
   384  *     @type string $version The most recent version of the plugin.
       
   385  *     @type string $file    Plugin filename relative to the plugins directory.
       
   386  * }
   270  */
   387  */
   271 function install_plugin_install_status($api, $loop = false) {
   388 function install_plugin_install_status($api, $loop = false) {
   272 	// This function is called recursively, $loop prevents further loops.
   389 	// This function is called recursively, $loop prevents further loops.
   273 	if ( is_array($api) )
   390 	if ( is_array($api) )
   274 		$api = (object) $api;
   391 		$api = (object) $api;
   335 
   452 
   336 /**
   453 /**
   337  * Display plugin information in dialog box form.
   454  * Display plugin information in dialog box form.
   338  *
   455  *
   339  * @since 2.7.0
   456  * @since 2.7.0
       
   457  *
       
   458  * @global string $tab
   340  */
   459  */
   341 function install_plugin_information() {
   460 function install_plugin_information() {
   342 	global $tab;
   461 	global $tab;
   343 
   462 
   344 	if ( empty( $_REQUEST['plugin'] ) ) {
   463 	if ( empty( $_REQUEST['plugin'] ) ) {
   363 	$plugins_allowedtags = array(
   482 	$plugins_allowedtags = array(
   364 		'a' => array( 'href' => array(), 'title' => array(), 'target' => array() ),
   483 		'a' => array( 'href' => array(), 'title' => array(), 'target' => array() ),
   365 		'abbr' => array( 'title' => array() ), 'acronym' => array( 'title' => array() ),
   484 		'abbr' => array( 'title' => array() ), 'acronym' => array( 'title' => array() ),
   366 		'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
   485 		'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
   367 		'div' => array( 'class' => array() ), 'span' => array( 'class' => array() ),
   486 		'div' => array( 'class' => array() ), 'span' => array( 'class' => array() ),
   368 		'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
   487 		'p' => array(), 'br' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
   369 		'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
   488 		'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
   370 		'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() )
   489 		'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
       
   490 		'blockquote' => array( 'cite' => true ),
   371 	);
   491 	);
   372 
   492 
   373 	$plugins_section_titles = array(
   493 	$plugins_section_titles = array(
   374 		'description'  => _x( 'Description',  'Plugin installer section title' ),
   494 		'description'  => _x( 'Description',  'Plugin installer section title' ),
   375 		'installation' => _x( 'Installation', 'Plugin installer section title' ),
   495 		'installation' => _x( 'Installation', 'Plugin installer section title' ),
   397 	if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
   517 	if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
   398 		$section_titles = array_keys( (array) $api->sections );
   518 		$section_titles = array_keys( (array) $api->sections );
   399 		$section = reset( $section_titles );
   519 		$section = reset( $section_titles );
   400 	}
   520 	}
   401 
   521 
   402 	iframe_header( __( 'Plugin Install' ) );
   522 	iframe_header( __( 'Plugin Installation' ) );
   403 
   523 
   404 	$_with_banner = '';
   524 	$_with_banner = '';
   405 
   525 
   406 	if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
   526 	if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
   407 		$_with_banner = 'with-banner';
   527 		$_with_banner = 'with-banner';
   443 		echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
   563 		echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
   444 	}
   564 	}
   445 
   565 
   446 	echo "</div>\n";
   566 	echo "</div>\n";
   447 
   567 
   448 	$date_format = __( 'M j, Y @ H:i' );
       
   449 	$last_updated_timestamp = strtotime( $api->last_updated );
       
   450 	?>
   568 	?>
   451 	<div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
   569 <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
   452 	<div class="fyi">
   570 	<div class="fyi">
   453 		<ul>
   571 		<ul>
   454 		<?php if ( ! empty( $api->version ) ) { ?>
   572 			<?php if ( ! empty( $api->version ) ) { ?>
   455 			<li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
   573 				<li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
   456 		<?php } if ( ! empty( $api->author ) ) { ?>
   574 			<?php } if ( ! empty( $api->author ) ) { ?>
   457 			<li><strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?></li>
   575 				<li><strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?></li>
   458 		<?php } if ( ! empty( $api->last_updated ) ) { ?>
   576 			<?php } if ( ! empty( $api->last_updated ) ) { ?>
   459 			<li><strong><?php _e( 'Last Updated:' ); ?></strong> <span title="<?php echo esc_attr( date_i18n( $date_format, $last_updated_timestamp ) ); ?>">
   577 				<li><strong><?php _e( 'Last Updated:' ); ?></strong>
   460 				<?php printf( __( '%s ago' ), human_time_diff( $last_updated_timestamp ) ); ?>
   578 					<?php
   461 			</span></li>
   579 					/* translators: %s: Time since the last update */
   462 		<?php } if ( ! empty( $api->requires ) ) { ?>
   580 					printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) );
   463 			<li><strong><?php _e( 'Requires WordPress Version:' ); ?></strong> <?php printf( __( '%s or higher' ), $api->requires ); ?></li>
   581 					?>
   464 		<?php } if ( ! empty( $api->tested ) ) { ?>
   582 				</li>
   465 			<li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li>
   583 			<?php } if ( ! empty( $api->requires ) ) { ?>
   466 		<?php } if ( ! empty( $api->active_installs ) ) { ?>
   584 				<li>
   467 			<li><strong><?php _e( 'Active Installs:' ); ?></strong> <?php
   585 					<strong><?php _e( 'Requires WordPress Version:' ); ?></strong>
   468 				if ( $api->active_installs >= 1000000 ) {
   586 					<?php
   469 					_ex( '1+ Million', 'Active plugin installs' );
   587 					/* translators: %s: version number */
   470 				} else {
   588 					printf( __( '%s or higher' ), $api->requires );
   471 					echo number_format_i18n( $api->active_installs ) . '+';
   589 					?>
   472 				}
   590 				</li>
   473 			?></li>
   591 			<?php } if ( ! empty( $api->tested ) ) { ?>
   474 		<?php } if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?>
   592 				<li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li>
   475 			<li><a target="_blank" href="https://wordpress.org/plugins/<?php echo $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a></li>
   593 			<?php } if ( ! empty( $api->requires_php ) ) { ?>
   476 		<?php } if ( ! empty( $api->homepage ) ) { ?>
   594 				<li>
   477 			<li><a target="_blank" href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage &#187;' ); ?></a></li>
   595 					<strong><?php _e( 'Requires PHP Version:' ); ?></strong>
   478 		<?php } if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { ?>
   596 					<?php
   479 			<li><a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a></li>
   597 					/* translators: %s: version number */
   480 		<?php } ?>
   598 					printf( __( '%s or higher' ), $api->requires_php );
       
   599 					?>
       
   600 				</li>
       
   601 			<?php } if ( isset( $api->active_installs ) ) { ?>
       
   602 				<li><strong><?php _e( 'Active Installations:' ); ?></strong> <?php
       
   603 					if ( $api->active_installs >= 1000000 ) {
       
   604 						_ex( '1+ Million', 'Active plugin installations' );
       
   605 					} elseif ( 0 == $api->active_installs ) {
       
   606 						_ex( 'Less Than 10', 'Active plugin installations' );
       
   607 					} else {
       
   608 						echo number_format_i18n( $api->active_installs ) . '+';
       
   609 					}
       
   610 					?></li>
       
   611 			<?php } if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?>
       
   612 				<li><a target="_blank" href="<?php echo __( 'https://wordpress.org/plugins/' ) . $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a></li>
       
   613 			<?php } if ( ! empty( $api->homepage ) ) { ?>
       
   614 				<li><a target="_blank" href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage &#187;' ); ?></a></li>
       
   615 			<?php } if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { ?>
       
   616 				<li><a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a></li>
       
   617 			<?php } ?>
   481 		</ul>
   618 		</ul>
   482 		<?php if ( ! empty( $api->rating ) ) { ?>
   619 		<?php if ( ! empty( $api->rating ) ) { ?>
   483 		<h3><?php _e( 'Average Rating' ); ?></h3>
   620 			<h3><?php _e( 'Average Rating' ); ?></h3>
   484 		<?php wp_star_rating( array( 'rating' => $api->rating, 'type' => 'percent', 'number' => $api->num_ratings ) ); ?>
   621 			<?php wp_star_rating( array( 'rating' => $api->rating, 'type' => 'percent', 'number' => $api->num_ratings ) ); ?>
   485 		<small><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></small>
   622 			<p aria-hidden="true" class="fyi-description"><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></p>
   486 		<?php }
   623 		<?php }
   487 
   624 
   488 		if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
   625 		if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) { ?>
   489 			foreach( $api->ratings as $key => $ratecount ) {
   626 			<h3><?php _e( 'Reviews' ); ?></h3>
       
   627 			<p class="fyi-description"><?php _e( 'Read all reviews on WordPress.org or write your own!' ); ?></p>
       
   628 			<?php
       
   629 			foreach ( $api->ratings as $key => $ratecount ) {
   490 				// Avoid div-by-zero.
   630 				// Avoid div-by-zero.
   491 				$_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
   631 				$_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
       
   632 				/* translators: 1: number of stars (used to determine singular/plural), 2: number of reviews */
       
   633 				$aria_label = esc_attr( sprintf( _n( 'Reviews with %1$d star: %2$s. Opens in a new window.', 'Reviews with %1$d stars: %2$s. Opens in a new window.', $key ),
       
   634 					$key,
       
   635 					number_format_i18n( $ratecount )
       
   636 				) );
   492 				?>
   637 				?>
   493 				<div class="counter-container">
   638 				<div class="counter-container">
   494 					<span class="counter-label"><a href="https://wordpress.org/support/view/plugin-reviews/<?php echo $api->slug; ?>?filter=<?php echo $key; ?>"
   639 						<span class="counter-label"><a href="https://wordpress.org/support/plugin/<?php echo $api->slug; ?>/reviews/?filter=<?php echo $key; ?>"
   495 						target="_blank"
   640 						                               target="_blank" aria-label="<?php echo $aria_label; ?>"><?php printf( _n( '%d star', '%d stars', $key ), $key ); ?></a></span>
   496 						title="<?php echo esc_attr( sprintf( _n( 'Click to see reviews that provided a rating of %d star', 'Click to see reviews that provided a rating of %d stars', $key ), $key ) ); ?>"><?php printf( _n( '%d star', '%d stars', $key ), $key ); ?></a></span>
   641 						<span class="counter-back">
   497 					<span class="counter-back">
   642 							<span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
   498 						<span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
   643 						</span>
   499 					</span>
   644 					<span class="counter-count" aria-hidden="true"><?php echo number_format_i18n( $ratecount ); ?></span>
   500 					<span class="counter-count"><?php echo number_format_i18n( $ratecount ); ?></span>
       
   501 				</div>
   645 				</div>
   502 				<?php
   646 				<?php
   503 			}
   647 			}
   504 		}
   648 		}
   505 		if ( ! empty( $api->contributors ) ) { ?>
   649 		if ( ! empty( $api->contributors ) ) { ?>
   513 					if ( empty( $contrib_username ) ) {
   657 					if ( empty( $contrib_username ) ) {
   514 						$contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
   658 						$contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
   515 					}
   659 					}
   516 					$contrib_username = sanitize_user( $contrib_username );
   660 					$contrib_username = sanitize_user( $contrib_username );
   517 					if ( empty( $contrib_profile ) ) {
   661 					if ( empty( $contrib_profile ) ) {
   518 						echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</li>";
   662 						echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' alt='' />{$contrib_username}</li>";
   519 					} else {
   663 					} else {
   520 						echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</a></li>";
   664 						echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' alt='' />{$contrib_username}</a></li>";
   521 					}
   665 					}
   522 				}
   666 				}
   523 				?>
   667 				?>
   524 			</ul>
   668 			</ul>
   525 			<?php if ( ! empty( $api->donate_link ) ) { ?>
   669 			<?php if ( ! empty( $api->donate_link ) ) { ?>
   527 			<?php } ?>
   671 			<?php } ?>
   528 		<?php } ?>
   672 		<?php } ?>
   529 	</div>
   673 	</div>
   530 	<div id="section-holder" class="wrap">
   674 	<div id="section-holder" class="wrap">
   531 	<?php
   675 	<?php
   532 		if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
   676 	$wp_version = get_bloginfo( 'version' );
   533 			echo '<div class="notice notice-warning"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>';
   677 
   534 		} elseif ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
   678 	if ( ! empty( $api->tested ) && version_compare( substr( $wp_version, 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
   535 			echo '<div class="notice notice-warning"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.') . '</p></div>';
   679 		echo '<div class="notice notice-warning notice-alt"><p>' . __( '<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.' ) . '</p></div>';
   536 		}
   680 	} elseif ( ! empty( $api->requires ) && version_compare( substr( $wp_version, 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
   537 
   681 		echo '<div class="notice notice-warning notice-alt"><p>' . __( '<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.' ) . '</p></div>';
   538 		foreach ( (array) $api->sections as $section_name => $content ) {
   682 	}
   539 			$content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
   683 
   540 			$content = links_add_target( $content, '_blank' );
   684 	foreach ( (array) $api->sections as $section_name => $content ) {
   541 
   685 		$content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
   542 			$san_section = esc_attr( $section_name );
   686 		$content = links_add_target( $content, '_blank' );
   543 
   687 
   544 			$display = ( $section_name === $section ) ? 'block' : 'none';
   688 		$san_section = esc_attr( $section_name );
   545 
   689 
   546 			echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
   690 		$display = ( $section_name === $section ) ? 'block' : 'none';
   547 			echo $content;
   691 
   548 			echo "\t</div>\n";
   692 		echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
   549 		}
   693 		echo $content;
       
   694 		echo "\t</div>\n";
       
   695 	}
   550 	echo "</div>\n";
   696 	echo "</div>\n";
   551 	echo "</div>\n";
   697 	echo "</div>\n";
   552 	echo "</div>\n"; // #plugin-information-scrollable
   698 	echo "</div>\n"; // #plugin-information-scrollable
   553 	echo "<div id='$tab-footer'>\n";
   699 	echo "<div id='$tab-footer'>\n";
   554 	if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
   700 	if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
   555 		$status = install_plugin_install_status( $api );
   701 		$status = install_plugin_install_status( $api );
   556 		switch ( $status['status'] ) {
   702 		switch ( $status['status'] ) {
   557 			case 'install':
   703 			case 'install':
   558 				if ( $status['url'] ) {
   704 				if ( $status['url'] ) {
   559 					echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
   705 					echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_install_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
   560 				}
   706 				}
   561 				break;
   707 				break;
   562 			case 'update_available':
   708 			case 'update_available':
   563 				if ( $status['url'] ) {
   709 				if ( $status['url'] ) {
   564 					echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) .'</a>';
   710 					echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) .'</a>';
   565 				}
   711 				}
   566 				break;
   712 				break;
   567 			case 'newer_installed':
   713 			case 'newer_installed':
       
   714 				/* translators: %s: Plugin version */
   568 				echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed'), $status['version'] ) . '</a>';
   715 				echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed'), $status['version'] ) . '</a>';
   569 				break;
   716 				break;
   570 			case 'latest_installed':
   717 			case 'latest_installed':
   571 				echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>';
   718 				echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>';
   572 				break;
   719 				break;
   575 	echo "</div>\n";
   722 	echo "</div>\n";
   576 
   723 
   577 	iframe_footer();
   724 	iframe_footer();
   578 	exit;
   725 	exit;
   579 }
   726 }
   580 add_action('install_plugins_pre_plugin-information', 'install_plugin_information');