Skip to content

Commit

Permalink
General: Memoize the return value in wp_get_wp_version().
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SergeyBiryukov committed Jul 29, 2024
1 parent 3977e62 commit 883d9b6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 883d9b6

Please sign in to comment.