From fe96ac4e95134827303cb69df39e0636f7a417ed Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Wed, 14 Mar 2012 22:49:36 +0000 Subject: [PATCH] Hash WP_Theme cache keys to ensure long file paths don't overflow in object backends. see #20103. git-svn-id: https://develop.svn.wordpress.org/trunk@20176 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/class-wp-theme.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index 75d029d805..4e020d28a4 100644 --- a/wp-includes/class-wp-theme.php +++ b/wp-includes/class-wp-theme.php @@ -128,6 +128,14 @@ final class WP_Theme implements ArrayAccess { */ private $textdomain_loaded; + /** + * Stores an md5 hash of the theme root, to function as the cache key. + * + * @access private + * @var string + */ + private $cache_hash; + /** * Flag for whether the themes cache bucket should be persistently cached. * @@ -171,6 +179,7 @@ final class WP_Theme implements ArrayAccess { $this->theme_root = $theme_root; $this->stylesheet = $theme_dir; + $this->cache_hash = md5( $this->theme_root . '/' . $this->stylesheet ); $theme_file = $this->stylesheet . '/style.css'; $cache = $this->cache_get( 'theme' ); @@ -440,7 +449,7 @@ final class WP_Theme implements ArrayAccess { * @return bool Return value from wp_cache_add() */ private function cache_add( $key, $data ) { - return wp_cache_add( $key . '-' . $this->theme_root . '/' . $this->stylesheet, $data, 'themes', self::$cache_expiration ); + return wp_cache_add( $key . '-' . $this->cache_hash, $data, 'themes', self::$cache_expiration ); } /** @@ -455,7 +464,7 @@ final class WP_Theme implements ArrayAccess { * @return mixed Retrieved data */ private function cache_get( $key ) { - return wp_cache_get( $key . '-' . $this->theme_root . '/' . $this->stylesheet, 'themes' ); + return wp_cache_get( $key . '-' . $this->cache_hash, 'themes' ); } /** @@ -466,7 +475,7 @@ final class WP_Theme implements ArrayAccess { */ public function cache_delete() { foreach ( array( 'theme', 'screenshot', 'screenshot_count', 'files', 'headers' ) as $key ) - wp_cache_delete( $key . '-' . $this->theme_root . '/' . $this->stylesheet, 'themes' ); + wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' ); } /**