General: Expand use of wp_get_wp_version().

Expands the use of `wp_get_wp_version()` to get an unmodified value of the current WordPress version in various locations in which it would be unhelpful if a plugin has modified the global `$wp_version`.

This includes:

* Theme and plugin compatibility tests
* During the upgrade process of WP Core
* Debug and site health data reports of the current version
* Version number display in the dashboard
* Block theme export and caching utilities
* The `WPDB` class

Props peterwilsoncc, hellofromtonya.
See #61627.



Built from https://develop.svn.wordpress.org/trunk@59159


git-svn-id: http://core.svn.wordpress.org/trunk@58554 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2024-10-03 00:25:15 +00:00
parent 49ed36d717
commit 92d9e70f84
15 changed files with 31 additions and 39 deletions

View File

@ -391,13 +391,13 @@ class Core_Upgrader extends WP_Upgrader {
*
* @since 3.7.0
*
* @global string $wp_version The WordPress version string.
* @global string $wp_local_package Locale code of the package.
*
* @return bool True if the checksums match, otherwise false.
*/
public function check_files() {
global $wp_version, $wp_local_package;
global $wp_local_package;
$wp_version = wp_get_wp_version();
$checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );

View File

@ -284,7 +284,7 @@ class Plugin_Installer_Skin extends WP_Upgrader_Skin {
$error = sprintf(
/* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */
__( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ),
get_bloginfo( 'version' ),
esc_html( wp_get_wp_version() ),
$requires_wp
);

View File

@ -274,8 +274,6 @@ class Plugin_Upgrader extends WP_Upgrader {
* @since 2.8.0
* @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
*
* @global string $wp_version The WordPress version string.
*
* @param string[] $plugins Array of paths to plugin files relative to the plugins directory.
* @param array $args {
* Optional. Other arguments for upgrading several plugins at once.
@ -285,7 +283,7 @@ class Plugin_Upgrader extends WP_Upgrader {
* @return array|false An array of results indexed by plugin file, or false if unable to connect to the filesystem.
*/
public function bulk_upgrade( $plugins, $args = array() ) {
global $wp_version;
$wp_version = wp_get_wp_version();
$defaults = array(
'clear_update_cache' => true,
@ -457,14 +455,14 @@ class Plugin_Upgrader extends WP_Upgrader {
* @since 3.3.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
* @global string $wp_version The WordPress version string.
*
* @param string $source The path to the downloaded package source.
* @return string|WP_Error The source as passed, or a WP_Error object on failure.
*/
public function check_package( $source ) {
global $wp_filesystem, $wp_version;
global $wp_filesystem;
$wp_version = wp_get_wp_version();
$this->new_plugin_data = array();
if ( is_wp_error( $source ) ) {

View File

@ -319,7 +319,7 @@ class Theme_Installer_Skin extends WP_Upgrader_Skin {
$error = sprintf(
/* translators: 1: Current WordPress version, 2: Version required by the uploaded theme. */
__( 'Your WordPress version is %1$s, however the uploaded theme requires %2$s.' ),
get_bloginfo( 'version' ),
esc_html( wp_get_wp_version() ),
$requires_wp
);

View File

@ -371,8 +371,6 @@ class Theme_Upgrader extends WP_Upgrader {
* @since 3.0.0
* @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
*
* @global string $wp_version The WordPress version string.
*
* @param string[] $themes Array of the theme slugs.
* @param array $args {
* Optional. Other arguments for upgrading several themes at once. Default empty array.
@ -383,8 +381,7 @@ class Theme_Upgrader extends WP_Upgrader {
* @return array[]|false An array of results, or false if unable to connect to the filesystem.
*/
public function bulk_upgrade( $themes, $args = array() ) {
global $wp_version;
$wp_version = wp_get_wp_version();
$defaults = array(
'clear_update_cache' => true,
);
@ -558,14 +555,14 @@ class Theme_Upgrader extends WP_Upgrader {
* @since 3.3.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
* @global string $wp_version The WordPress version string.
*
* @param string $source The path to the downloaded package source.
* @return string|WP_Error The source as passed, or a WP_Error object on failure.
*/
public function check_package( $source ) {
global $wp_filesystem, $wp_version;
global $wp_filesystem;
$wp_version = wp_get_wp_version();
$this->new_theme_data = array();
if ( is_wp_error( $source ) ) {

View File

@ -752,7 +752,7 @@ class WP_Automatic_Updater {
// Send debugging email to admin for all development installations.
if ( ! empty( $this->update_results ) ) {
$development_version = str_contains( get_bloginfo( 'version' ), '-' );
$development_version = str_contains( wp_get_wp_version(), '-' );
/**
* Filters whether to send a debugging email for each automatic background update.
@ -795,7 +795,7 @@ class WP_Automatic_Updater {
* @param object $update_result The result of the core update. Includes the update offer and result.
*/
protected function after_core_update( $update_result ) {
$wp_version = get_bloginfo( 'version' );
$wp_version = wp_get_wp_version();
$core_update = $update_result->item;
$result = $update_result->result;

View File

@ -46,7 +46,7 @@ class WP_Debug_Data {
$blog_public = get_option( 'blog_public' );
$default_comment_status = get_option( 'default_comment_status' );
$environment_type = wp_get_environment_type();
$core_version = get_bloginfo( 'version' );
$core_version = wp_get_wp_version();
$core_updates = get_core_updates();
$core_update_needed = '';

View File

@ -264,7 +264,7 @@ class WP_Site_Health {
'test' => 'wordpress_version',
);
$core_current_version = get_bloginfo( 'version' );
$core_current_version = wp_get_wp_version();
$core_updates = get_core_updates();
if ( ! is_array( $core_updates ) ) {

View File

@ -2056,7 +2056,7 @@ function wp_dashboard_empty() {}
* @since 5.9.0 Send users to the Site Editor if the active theme is block-based.
*/
function wp_welcome_panel() {
list( $display_version ) = explode( '-', get_bloginfo( 'version' ) );
list( $display_version ) = explode( '-', wp_get_wp_version() );
$can_customize = current_user_can( 'customize' );
$is_block_theme = wp_is_block_theme();
?>
@ -2070,7 +2070,7 @@ function wp_welcome_panel() {
<a href="<?php echo esc_url( admin_url( 'about.php' ) ); ?>">
<?php
/* translators: %s: Current WordPress version. */
printf( __( 'Learn more about the %s version.' ), $display_version );
printf( __( 'Learn more about the %s version.' ), esc_html( $display_version ) );
?>
</a>
</p>

View File

@ -1539,12 +1539,12 @@ function update_core( $from, $to ) {
*
* @global array $_old_requests_files Requests files to be preloaded.
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
* @global string $wp_version The WordPress version string.
*
* @param string $to Path to old WordPress installation.
*/
function _preload_old_requests_classes_and_interfaces( $to ) {
global $_old_requests_files, $wp_filesystem, $wp_version;
global $_old_requests_files, $wp_filesystem;
$wp_version = wp_get_wp_version();
/*
* Requests was introduced in WordPress 4.6.
@ -1587,14 +1587,14 @@ function _preload_old_requests_classes_and_interfaces( $to ) {
*
* @since 3.3.0
*
* @global string $wp_version The WordPress version string.
* @global string $pagenow The filename of the current screen.
* @global string $pagenow The filename of the current screen.
* @global string $action
*
* @param string $new_version
*/
function _redirect_to_about_wordpress( $new_version ) {
global $wp_version, $pagenow, $action;
global $pagenow, $action;
$wp_version = wp_get_wp_version();
if ( version_compare( $wp_version, '3.4-RC1', '>=' ) ) {
return;

View File

@ -37,7 +37,7 @@ function list_core_update( $update ) {
global $wp_local_package, $wpdb;
static $first_pass = true;
$wp_version = get_bloginfo( 'version' );
$wp_version = wp_get_wp_version();
$version_string = sprintf( '%s&ndash;%s', $update->current, get_locale() );
if ( 'en_US' === $update->locale && 'en_US' === get_locale() ) {
@ -393,7 +393,7 @@ function core_auto_updates_settings() {
);
if ( $upgrade_major ) {
$wp_version = get_bloginfo( 'version' );
$wp_version = wp_get_wp_version();
$updates = get_core_updates();
if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
@ -460,7 +460,7 @@ function core_auto_updates_settings() {
* @since 2.9.0
*/
function list_plugin_updates() {
$wp_version = get_bloginfo( 'version' );
$wp_version = wp_get_wp_version();
$cur_wp_version = preg_replace( '/-.*$/', '', $wp_version );
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
@ -1101,7 +1101,7 @@ if ( 'upgrade-core' === $action ) {
echo '<h2 class="wp-current-version">';
/* translators: Current version of WordPress. */
printf( __( 'Current version: %s' ), get_bloginfo( 'version' ) );
printf( __( 'Current version: %s' ), esc_html( wp_get_wp_version() ) );
echo '</h2>';
echo '<p class="update-last-checked">';

View File

@ -1404,12 +1404,10 @@ function wp_is_theme_directory_ignored( $path ) {
* @since 5.9.0
* @since 6.0.0 Adds the whole theme to the export archive.
*
* @global string $wp_version The WordPress version string.
*
* @return WP_Error|string Path of the ZIP file or error on failure.
*/
function wp_generate_block_templates_export_file() {
global $wp_version;
$wp_version = wp_get_wp_version();
if ( ! class_exists( 'ZipArchive' ) ) {
return new WP_Error( 'missing_zip_package', __( 'Zip Export not supported.' ) );

View File

@ -25,11 +25,9 @@ require BLOCKS_PATH . 'require-dynamic-blocks.php';
* avoids unnecessary logic and filesystem lookups in the other function.
*
* @since 6.3.0
*
* @global string $wp_version The WordPress version string.
*/
function register_core_block_style_handles() {
global $wp_version;
$wp_version = wp_get_wp_version();
if ( ! wp_should_load_separate_core_block_assets() ) {
return;

View File

@ -3983,12 +3983,13 @@ class wpdb {
*
* @since 2.5.0
*
* @global string $wp_version The WordPress version string.
* @global string $required_mysql_version The required MySQL version string.
* @return void|WP_Error
*/
public function check_database_version() {
global $wp_version, $required_mysql_version;
global $required_mysql_version;
$wp_version = wp_get_wp_version();
// Make sure the server has the required MySQL version.
if ( version_compare( $this->db_version(), $required_mysql_version, '<' ) ) {
/* translators: 1: WordPress version number, 2: Minimum required MySQL version number. */

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.7-beta1-59158';
$wp_version = '6.7-beta1-59159';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.