From 883d9b673185e9f0b40ac9929a59f4725af379d9 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov <sergeybiryukov@git.wordpress.org> Date: Mon, 29 Jul 2024 15:00:44 +0000 Subject: [PATCH] General: Memoize the return value in `wp_get_wp_version()`. This aims to optimize performance by saving the return value to a static variable, so that the `version.php` file is not unnecessarily required on each function call. Follow-up to [58813]. Props Cybr, debarghyabanerjee, mukesh27. Fixes #61782. See #61627. git-svn-id: https://develop.svn.wordpress.org/trunk@58827 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index a884303893..136012dd07 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -8819,7 +8819,11 @@ function clean_dirsize_cache( $path ) { * @return string The current WordPress version. */ function wp_get_wp_version() { - require ABSPATH . WPINC . '/version.php'; + static $wp_version; + + if ( ! isset( $wp_version ) ) { + require ABSPATH . WPINC . '/version.php'; + } return $wp_version; }