From 0ade48d1e24fe2f41613877bb8e281917f282c1b Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 13 Oct 2023 16:46:25 +0000 Subject: [PATCH] Themes: Clear existing pattern cache when in theme development mode and prevent PHP warning due to missing file. Follow up to [56765]. Props spacedmonkey, afercia, jrf, flixos90. Fixes #59591. See #59490. Built from https://develop.svn.wordpress.org/trunk@56931 git-svn-id: http://core.svn.wordpress.org/trunk@56442 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-patterns.php | 26 ++++++++++++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/wp-includes/block-patterns.php b/wp-includes/block-patterns.php index dd70d2b589..a1a7a67d81 100644 --- a/wp-includes/block-patterns.php +++ b/wp-includes/block-patterns.php @@ -350,9 +350,25 @@ function _register_theme_block_patterns() { continue; } + $file_path = $dirpath . $file; + + if ( ! file_exists( $file_path ) ) { + _doing_it_wrong( + __FUNCTION__, + sprintf( + /* translators: %s: file name. */ + __( 'Could not register file "%s" as a block pattern as the file does not exist.' ), + $file + ), + '6.4.0' + ); + $theme->delete_pattern_cache(); + continue; + } + // The actual pattern content is the output of the file. ob_start(); - include $dirpath . $file; + include $file_path; $pattern_data['content'] = ob_get_clean(); if ( ! $pattern_data['content'] ) { continue; @@ -408,11 +424,13 @@ add_action( 'init', '_register_theme_block_patterns' ); function _wp_get_block_patterns( WP_Theme $theme ) { $can_use_cached = ! wp_is_development_mode( 'theme' ); - if ( $can_use_cached ) { - $pattern_data = $theme->get_pattern_cache(); - if ( is_array( $pattern_data ) ) { + $pattern_data = $theme->get_pattern_cache(); + if ( is_array( $pattern_data ) ) { + if ( $can_use_cached ) { return $pattern_data; } + // If in development mode, clear pattern cache. + $theme->delete_pattern_cache(); } $dirpath = $theme->get_stylesheet_directory() . '/patterns/'; diff --git a/wp-includes/version.php b/wp-includes/version.php index f8222f9434..92596d3dc9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-beta4-56930'; +$wp_version = '6.4-beta4-56931'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.