diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:51:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:51:18 +0000 |
commit | 0e41b5d52fdc6af6442816b5f465c9db9f84e126 (patch) | |
tree | e139a90049b158d4eed892d1662ee7f5c358fa31 /wp-includes/class-wp-theme.php | |
parent | Adding upstream version 6.5.5+dfsg1. (diff) | |
download | wordpress-0e41b5d52fdc6af6442816b5f465c9db9f84e126.tar.xz wordpress-0e41b5d52fdc6af6442816b5f465c9db9f84e126.zip |
Adding upstream version 6.6.1+dfsg1.upstream/6.6.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wp-includes/class-wp-theme.php')
-rw-r--r-- | wp-includes/class-wp-theme.php | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index e6eeb8c..6db75e4 100644 --- a/wp-includes/class-wp-theme.php +++ b/wp-includes/class-wp-theme.php @@ -352,7 +352,7 @@ final class WP_Theme implements ArrayAccess { */ $default_theme_slug = array_search( $this->headers['Name'], self::$default_themes, true ); if ( $default_theme_slug ) { - if ( basename( $this->stylesheet ) != $default_theme_slug ) { + if ( basename( $this->stylesheet ) !== $default_theme_slug ) { $this->headers['Name'] .= '/' . $this->stylesheet; } } @@ -417,7 +417,10 @@ final class WP_Theme implements ArrayAccess { } // If we got our data from cache, we can assume that 'template' is pointing to the right place. - if ( ! is_array( $cache ) && $this->template != $this->stylesheet && ! file_exists( $this->theme_root . '/' . $this->template . '/index.php' ) ) { + if ( ! is_array( $cache ) + && $this->template !== $this->stylesheet + && ! file_exists( $this->theme_root . '/' . $this->template . '/index.php' ) + ) { /* * If we're in a directory of themes inside /themes, look for the parent nearby. * wp-content/themes/directory-of-themes/* @@ -425,7 +428,9 @@ final class WP_Theme implements ArrayAccess { $parent_dir = dirname( $this->stylesheet ); $directories = search_theme_directories(); - if ( '.' !== $parent_dir && file_exists( $this->theme_root . '/' . $parent_dir . '/' . $this->template . '/index.php' ) ) { + if ( '.' !== $parent_dir + && file_exists( $this->theme_root . '/' . $parent_dir . '/' . $this->template . '/index.php' ) + ) { $this->template = $parent_dir . '/' . $this->template; } elseif ( $directories && isset( $directories[ $this->template ] ) ) { /* @@ -460,9 +465,9 @@ final class WP_Theme implements ArrayAccess { } // Set the parent, if we're a child theme. - if ( $this->template != $this->stylesheet ) { + if ( $this->template !== $this->stylesheet ) { // If we are a parent, then there is a problem. Only two generations allowed! Cancel things out. - if ( $_child instanceof WP_Theme && $_child->template == $this->stylesheet ) { + if ( $_child instanceof WP_Theme && $_child->template === $this->stylesheet ) { $_child->parent = null; $_child->errors = new WP_Error( 'theme_parent_invalid', @@ -484,7 +489,7 @@ final class WP_Theme implements ArrayAccess { ) ); // The two themes actually reference each other with the Template header. - if ( $_child->stylesheet == $this->template ) { + if ( $_child->stylesheet === $this->template ) { $this->errors = new WP_Error( 'theme_parent_invalid', sprintf( @@ -1714,7 +1719,7 @@ final class WP_Theme implements ArrayAccess { return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id ); } - $current = get_current_blog_id() == $blog_id; + $current = get_current_blog_id() === $blog_id; if ( $current ) { $allowed_themes[ $blog_id ] = get_option( 'allowedthemes' ); @@ -1967,6 +1972,7 @@ final class WP_Theme implements ArrayAccess { * Gets block pattern cache. * * @since 6.4.0 + * @since 6.6.0 Uses transients to cache regardless of site environment. * * @return array|false Returns an array of patterns if cache is found, otherwise false. */ @@ -1974,7 +1980,9 @@ final class WP_Theme implements ArrayAccess { if ( ! $this->exists() ) { return false; } - $pattern_data = wp_cache_get( 'wp_theme_patterns_' . $this->stylesheet, 'theme_files' ); + + $pattern_data = get_site_transient( 'wp_theme_files_patterns-' . $this->cache_hash ); + if ( is_array( $pattern_data ) && $pattern_data['version'] === $this->get( 'Version' ) ) { return $pattern_data['patterns']; } @@ -1985,6 +1993,7 @@ final class WP_Theme implements ArrayAccess { * Sets block pattern cache. * * @since 6.4.0 + * @since 6.6.0 Uses transients to cache regardless of site environment. * * @param array $patterns Block patterns data to set in cache. */ @@ -1993,16 +2002,43 @@ final class WP_Theme implements ArrayAccess { 'version' => $this->get( 'Version' ), 'patterns' => $patterns, ); - wp_cache_set( 'wp_theme_patterns_' . $this->stylesheet, $pattern_data, 'theme_files' ); + + /** + * Filters the cache expiration time for theme files. + * + * @since 6.6.0 + * + * @param int $cache_expiration Cache expiration time in seconds. + * @param string $cache_type Type of cache being set. + */ + $cache_expiration = (int) apply_filters( 'wp_theme_files_cache_ttl', self::$cache_expiration, 'theme_block_patterns' ); + + // We don't want to cache patterns infinitely. + if ( $cache_expiration <= 0 ) { + _doing_it_wrong( + __METHOD__, + sprintf( + /* translators: %1$s: The filter name.*/ + __( 'The %1$s filter must return an integer value greater than 0.' ), + '<code>wp_theme_files_cache_ttl</code>' + ), + '6.6.0' + ); + + $cache_expiration = self::$cache_expiration; + } + + set_site_transient( 'wp_theme_files_patterns-' . $this->cache_hash, $pattern_data, $cache_expiration ); } /** * Clears block pattern cache. * * @since 6.4.0 + * @since 6.6.0 Uses transients to cache regardless of site environment. */ public function delete_pattern_cache() { - wp_cache_delete( 'wp_theme_patterns_' . $this->stylesheet, 'theme_files' ); + delete_site_transient( 'wp_theme_files_patterns-' . $this->cache_hash ); } /** |