From 92d9e70f849c337c2fd51bbfb1b6028e5c47c305 Mon Sep 17 00:00:00 2001
From: Peter Wilson
Date: Thu, 3 Oct 2024 00:25:15 +0000
Subject: [PATCH] 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
---
wp-admin/includes/class-core-upgrader.php | 4 ++--
wp-admin/includes/class-plugin-installer-skin.php | 2 +-
wp-admin/includes/class-plugin-upgrader.php | 8 +++-----
wp-admin/includes/class-theme-installer-skin.php | 2 +-
wp-admin/includes/class-theme-upgrader.php | 9 +++------
wp-admin/includes/class-wp-automatic-updater.php | 4 ++--
wp-admin/includes/class-wp-debug-data.php | 2 +-
wp-admin/includes/class-wp-site-health.php | 2 +-
wp-admin/includes/dashboard.php | 4 ++--
wp-admin/includes/update-core.php | 10 +++++-----
wp-admin/update-core.php | 8 ++++----
wp-includes/block-template-utils.php | 4 +---
wp-includes/blocks/index.php | 4 +---
wp-includes/class-wpdb.php | 5 +++--
wp-includes/version.php | 2 +-
15 files changed, 31 insertions(+), 39 deletions(-)
diff --git a/wp-admin/includes/class-core-upgrader.php b/wp-admin/includes/class-core-upgrader.php
index 2655c27c3b..0629e0b8e1 100644
--- a/wp-admin/includes/class-core-upgrader.php
+++ b/wp-admin/includes/class-core-upgrader.php
@@ -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' );
diff --git a/wp-admin/includes/class-plugin-installer-skin.php b/wp-admin/includes/class-plugin-installer-skin.php
index d8e7e3e8cb..aa97833c59 100644
--- a/wp-admin/includes/class-plugin-installer-skin.php
+++ b/wp-admin/includes/class-plugin-installer-skin.php
@@ -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
);
diff --git a/wp-admin/includes/class-plugin-upgrader.php b/wp-admin/includes/class-plugin-upgrader.php
index 091cfebc18..7871546a09 100644
--- a/wp-admin/includes/class-plugin-upgrader.php
+++ b/wp-admin/includes/class-plugin-upgrader.php
@@ -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 ) ) {
diff --git a/wp-admin/includes/class-theme-installer-skin.php b/wp-admin/includes/class-theme-installer-skin.php
index 85f87977b2..035e26f608 100644
--- a/wp-admin/includes/class-theme-installer-skin.php
+++ b/wp-admin/includes/class-theme-installer-skin.php
@@ -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
);
diff --git a/wp-admin/includes/class-theme-upgrader.php b/wp-admin/includes/class-theme-upgrader.php
index 869bf64220..dc0729b0aa 100644
--- a/wp-admin/includes/class-theme-upgrader.php
+++ b/wp-admin/includes/class-theme-upgrader.php
@@ -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 ) ) {
diff --git a/wp-admin/includes/class-wp-automatic-updater.php b/wp-admin/includes/class-wp-automatic-updater.php
index c96bededd9..b497b8324d 100644
--- a/wp-admin/includes/class-wp-automatic-updater.php
+++ b/wp-admin/includes/class-wp-automatic-updater.php
@@ -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;
diff --git a/wp-admin/includes/class-wp-debug-data.php b/wp-admin/includes/class-wp-debug-data.php
index 47e9def7fd..9feb6a3bde 100644
--- a/wp-admin/includes/class-wp-debug-data.php
+++ b/wp-admin/includes/class-wp-debug-data.php
@@ -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 = '';
diff --git a/wp-admin/includes/class-wp-site-health.php b/wp-admin/includes/class-wp-site-health.php
index e39eca93e6..3f89fc0a38 100644
--- a/wp-admin/includes/class-wp-site-health.php
+++ b/wp-admin/includes/class-wp-site-health.php
@@ -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 ) ) {
diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php
index d988ee4e69..b198325f27 100644
--- a/wp-admin/includes/dashboard.php
+++ b/wp-admin/includes/dashboard.php
@@ -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() {
diff --git a/wp-admin/includes/update-core.php b/wp-admin/includes/update-core.php
index 0282946755..639faba224 100644
--- a/wp-admin/includes/update-core.php
+++ b/wp-admin/includes/update-core.php
@@ -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;
diff --git a/wp-admin/update-core.php b/wp-admin/update-core.php
index b41f7285dc..82525a2f5f 100644
--- a/wp-admin/update-core.php
+++ b/wp-admin/update-core.php
@@ -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–%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 '';
/* translators: Current version of WordPress. */
- printf( __( 'Current version: %s' ), get_bloginfo( 'version' ) );
+ printf( __( 'Current version: %s' ), esc_html( wp_get_wp_version() ) );
echo '
';
echo '';
diff --git a/wp-includes/block-template-utils.php b/wp-includes/block-template-utils.php
index 05012fbf22..f974f6efbd 100644
--- a/wp-includes/block-template-utils.php
+++ b/wp-includes/block-template-utils.php
@@ -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.' ) );
diff --git a/wp-includes/blocks/index.php b/wp-includes/blocks/index.php
index 0e4412ba6d..98615ea1ba 100644
--- a/wp-includes/blocks/index.php
+++ b/wp-includes/blocks/index.php
@@ -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;
diff --git a/wp-includes/class-wpdb.php b/wp-includes/class-wpdb.php
index 997df462a1..69b934ae38 100644
--- a/wp-includes/class-wpdb.php
+++ b/wp-includes/class-wpdb.php
@@ -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. */
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 48a8de2241..7999f7b0c0 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -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.