diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/includes/plugin-install.php --- a/wp/wp-admin/includes/plugin-install.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-admin/includes/plugin-install.php Tue Dec 15 13:49:49 2020 +0100 @@ -73,6 +73,7 @@ * FAQ, screenshots, other notes, and changelog. Default false. * @type bool $tested Whether to return the 'Compatible up to' value. Default true. * @type bool $requires Whether to return the required WordPress version. Default true. + * @type bool $requires_php Whether to return the required PHP version. Default true. * @type bool $rating Whether to return the rating in percent and total number of ratings. * Default true. * @type bool $ratings Whether to return the number of rating for each star (1-5). Default true. @@ -99,14 +100,14 @@ * for more information on the make-up of possible return values depending on the value of `$action`. */ function plugins_api( $action, $args = array() ) { - // include an unmodified $wp_version - include( ABSPATH . WPINC . '/version.php' ); + // Include an unmodified $wp_version. + require ABSPATH . WPINC . '/version.php'; if ( is_array( $args ) ) { $args = (object) $args; } - if ( 'query_plugins' == $action ) { + if ( 'query_plugins' === $action ) { if ( ! isset( $args->per_page ) ) { $args->per_page = 24; } @@ -117,7 +118,7 @@ } if ( ! isset( $args->wp_version ) ) { - $args->wp_version = substr( $wp_version, 0, 3 ); // X.y + $args->wp_version = substr( $wp_version, 0, 3 ); // x.y } /** @@ -160,7 +161,8 @@ ); $http_url = $url; - if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { + $ssl = wp_http_supports( array( 'ssl' ) ); + if ( $ssl ) { $url = set_url_scheme( $url, 'https' ); } @@ -171,14 +173,17 @@ $request = wp_remote_get( $url, $http_args ); if ( $ssl && is_wp_error( $request ) ) { - trigger_error( - sprintf( - /* translators: %s: support forums URL */ - __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ), - __( 'https://wordpress.org/support/' ) - ) . ' ' . __( '(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 - ); + if ( ! wp_is_json_request() ) { + trigger_error( + sprintf( + /* translators: %s: Support forums URL. */ + __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ), + __( 'https://wordpress.org/support/forums/' ) + ) . ' ' . __( '(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 + ); + } + $request = wp_remote_get( $http_url, $http_args ); } @@ -186,9 +191,9 @@ $res = new WP_Error( 'plugins_api_failed', sprintf( - /* translators: %s: support forums URL */ + /* translators: %s: Support forums URL. */ __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ), - __( 'https://wordpress.org/support/' ) + __( 'https://wordpress.org/support/forums/' ) ), $request->get_error_message() ); @@ -201,9 +206,9 @@ $res = new WP_Error( 'plugins_api_failed', sprintf( - /* translators: %s: support forums URL */ + /* translators: %s: Support forums URL. */ __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ), - __( 'https://wordpress.org/support/' ) + __( 'https://wordpress.org/support/forums/' ) ), wp_remote_retrieve_body( $request ) ); @@ -238,8 +243,9 @@ * @return array */ function install_popular_tags( $args = array() ) { - $key = md5( serialize( $args ) ); - if ( false !== ( $tags = get_site_transient( 'poptags_' . $key ) ) ) { + $key = md5( serialize( $args ) ); + $tags = get_site_transient( 'poptags_' . $key ); + if ( false !== $tags ) { return $tags; } @@ -259,7 +265,15 @@ */ function install_dashboard() { ?> -

WordPress Plugin Directory or upload a plugin in .zip format by clicking the button at the top of this page.' ), __( 'https://wordpress.org/plugins/' ) ); ?>

+

+ WordPress Plugin Directory or upload a plugin in .zip format by clicking the button at the top of this page.' ), + __( 'https://wordpress.org/plugins/' ) + ); + ?> +

@@ -274,7 +288,7 @@ if ( is_wp_error( $api_tags ) ) { echo $api_tags->get_error_message(); } else { - //Set up the tags in a way which can be interpreted by wp_generate_tag_cloud() + // Set up the tags in a way which can be interpreted by wp_generate_tag_cloud(). $tags = array(); foreach ( (array) $api_tags as $tag ) { $url = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) ); @@ -290,7 +304,9 @@ echo wp_generate_tag_cloud( $tags, array( + /* translators: %s: Number of plugins. */ 'single_text' => __( '%s plugin' ), + /* translators: %s: Number of plugins. */ 'multiple_text' => __( '%s plugins' ), ) ); @@ -318,9 +334,8 @@ - + + 'search-submit' ) ); ?>
-

+

- +
@@ -354,7 +369,7 @@ $user = get_user_option( 'wporg_favorites' ); $action = 'save_wporg_username_' . get_current_user_id(); ?> -

+

@@ -388,6 +403,7 @@ break; case 'install_plugins_beta': printf( + /* translators: %s: URL to "Features as Plugins" page. */ '

' . __( 'You are using a development version of WordPress. These feature plugins are also under development. Learn more.' ) . '

', 'https://make.wordpress.org/core/handbook/about/release-cycle/features-as-plugins/' ); @@ -406,8 +422,8 @@ * * @since 3.0.0 * - * @param array|object $api Data about the plugin retrieved from the API. - * @param bool $loop Optional. Disable further loops. Default false. + * @param array|object $api Data about the plugin retrieved from the API. + * @param bool $loop Optional. Disable further loops. Default false. * @return array { * Plugin installation status data. * @@ -423,7 +439,7 @@ $api = (object) $api; } - // Default to a "new" plugin + // Default to a "new" plugin. $status = 'install'; $url = false; $update_file = false; @@ -448,7 +464,7 @@ } } - if ( 'install' == $status ) { + if ( 'install' === $status ) { if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { $installed_plugin = get_plugins( '/' . $api->slug ); if ( empty( $installed_plugin ) ) { @@ -456,8 +472,11 @@ $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); } } else { - $key = array_keys( $installed_plugin ); - $key = reset( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers + $key = array_keys( $installed_plugin ); + // Use the first plugin regardless of the name. + // Could have issues for multiple plugins in one directory if they share different version numbers. + $key = reset( $key ); + $update_file = $api->slug . '/' . $key; if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) { $status = 'latest_installed'; @@ -465,7 +484,7 @@ $status = 'newer_installed'; $version = $installed_plugin[ $key ]['Version']; } else { - //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh + // If the above update check failed, then that probably means that the update checker has out-of-date information, force a refresh. if ( ! $loop ) { delete_site_transient( 'update_plugins' ); wp_update_plugins(); @@ -474,7 +493,7 @@ } } } else { - // "install" & no directory with that slug + // "install" & no directory with that slug. if ( current_user_can( 'install_plugins' ) ) { $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); } @@ -556,7 +575,7 @@ 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ), ); - // Sanitize HTML + // Sanitize HTML. foreach ( (array) $api->sections as $section_name => $content ) { $api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags ); } @@ -569,7 +588,8 @@ $_tab = esc_attr( $tab ); - $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English. + // Default to the Description tab, Do not translate, API returns English. + $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) { $section_titles = array_keys( (array) $api->sections ); $section = reset( $section_titles ); @@ -637,7 +657,7 @@ last_updated ) ) { ?>
  • last_updated ) ) ); ?>
  • @@ -645,7 +665,7 @@
  • requires ); ?>
  • @@ -655,7 +675,7 @@
  • requires_php ); ?>
  • @@ -665,6 +685,7 @@ if ( $api->active_installs >= 1000000 ) { $active_installs_millions = floor( $api->active_installs / 1000000 ); printf( + /* translators: %s: Number of millions. */ _nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ), number_format_i18n( $active_installs_millions ) ); @@ -694,7 +715,15 @@ ) ); ?> - + ratings as $key => $ratecount ) { // Avoid div-by-zero. - $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0; - /* translators: 1: number of stars (used to determine singular/plural), 2: number of reviews */ + $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0; $aria_label = esc_attr( sprintf( - _n( 'Reviews with %1$d star: %2$s. Opens in a new tab.', 'Reviews with %1$d stars: %2$s. Opens in a new tab.', $key ), + /* translators: 1: Number of stars (used to determine singular/plural), 2: Number of reviews. */ + _n( + 'Reviews with %1$d star: %2$s. Opens in a new tab.', + 'Reviews with %1$d stars: %2$s. Opens in a new tab.', + $key + ), $key, number_format_i18n( $ratecount ) ) @@ -717,8 +750,15 @@ ?>
    - + %s', + "https://wordpress.org/support/plugin/{$api->slug}/reviews/?filter={$key}", + $aria_label, + /* translators: %s: Number of stars. */ + sprintf( _n( '%d star', '%d stars', $key ), $key ) + ); + ?> @@ -766,7 +806,7 @@ _e( 'Error: This plugin requires a newer version of PHP.' ); if ( current_user_can( 'update_php' ) ) { printf( - /* translators: %s: "Update PHP" page URL */ + /* translators: %s: URL to Update PHP page. */ ' ' . __( 'Click here to learn more about updating PHP.' ), esc_url( wp_get_update_php_url() ) ); @@ -787,7 +827,7 @@ _e( 'Error: This plugin requires a newer version of WordPress.' ); if ( current_user_can( 'update_core' ) ) { printf( - /* translators: %s: "Update WordPress" screen URL */ + /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( 'Click here to update WordPress.' ), self_admin_url( 'update-core.php' ) ); @@ -839,7 +879,7 @@ } break; case 'newer_installed': - /* translators: %s: Plugin version */ + /* translators: %s: Plugin version. */ echo '' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . ''; break; case 'latest_installed':