From aceaf33edd7235483a19999df77ac0d675fecd84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helen=20Hou-Sand=C3=AD?= Date: Mon, 16 Nov 2020 22:31:06 +0000 Subject: [PATCH] Multisite: More consistency for `clean_dirsize_cache()`. Props SergeyBiryukov. Fixes #19879. Built from https://develop.svn.wordpress.org/trunk@49616 git-svn-id: http://core.svn.wordpress.org/trunk@49354 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/file.php | 2 +- wp-includes/functions.php | 25 +++++-------------------- wp-includes/post.php | 2 +- wp-includes/version.php | 2 +- 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 04dea32a20..993635e460 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -928,7 +928,7 @@ function _wp_handle_upload( &$file, $overrides, $time, $action ) { $url = $uploads['url'] . "/$filename"; if ( is_multisite() ) { - invalidate_dirsize_cache( $new_file ); + clean_dirsize_cache( $new_file ); } /** diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 58a098f916..ccf89a449d 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -2747,7 +2747,7 @@ function wp_upload_bits( $name, $deprecated, $bits, $time = null ) { $url = $upload['url'] . "/$filename"; if ( is_multisite() ) { - invalidate_dirsize_cache( $new_file ); + clean_dirsize_cache( $new_file ); } /** This filter is documented in wp-admin/includes/file.php */ @@ -7628,7 +7628,8 @@ function recurse_dirsize( $directory, $exclude = null, $max_execution_time = nul $size = 0; $directory = untrailingslashit( $directory ); - $cache_path = normalize_dirsize_cache_path( $directory ); + $cache_path = untrailingslashit( str_replace( ABSPATH, '', $directory ) ); + $save_cache = false; if ( ! isset( $directory_cache ) ) { @@ -7722,14 +7723,14 @@ function recurse_dirsize( $directory, $exclude = null, $max_execution_time = nul * * @param string $path Full path of a directory or file. */ -function invalidate_dirsize_cache( $path ) { +function clean_dirsize_cache( $path ) { $directory_cache = get_transient( 'dirsize_cache' ); if ( empty( $directory_cache ) ) { return; } - $cache_path = normalize_dirsize_cache_path( $path ); + $cache_path = untrailingslashit( str_replace( ABSPATH, '', $path ) ); unset( $directory_cache[ $cache_path ] ); while ( DIRECTORY_SEPARATOR !== $cache_path && '.' !== $cache_path && '..' !== $cache_path ) { @@ -7740,22 +7741,6 @@ function invalidate_dirsize_cache( $path ) { set_transient( 'dirsize_cache', $directory_cache ); } -/** - * Normalize dirsize cache path. - * - * Ensures array keys within the dirsize_cache transient follow the same format. - * - * @since 5.6.0 - * - * @param string $path - * @return string - */ -function normalize_dirsize_cache_path( $path ) { - $path = str_replace( ABSPATH, '', $path ); - - return untrailingslashit( $path ); -} - /** * Checks compatibility with the current WordPress version. * diff --git a/wp-includes/post.php b/wp-includes/post.php index 2e1afdbf4a..7db2c44899 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -5918,7 +5918,7 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { $file = get_attached_file( $post_id ); if ( is_multisite() ) { - invalidate_dirsize_cache( $file ); + clean_dirsize_cache( $file ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index eca4c03732..cfd87b872e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.6-beta4-49615'; +$wp_version = '5.6-beta4-49616'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.