File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -537,8 +537,18 @@ function _get_block_template_file_content( $template_file_path ) {
537537 return file_get_contents ( $ template_file_path );
538538 }
539539
540- // Bypass cache while developing a theme.
540+ /*
541+ * Bypass cache while developing a theme.
542+ * If there is an existing cache, it should be deleted.
543+ * This ensures that no stale cache values can be served when temporarily
544+ * enabling "theme" development mode and then disabling it again.
545+ */
541546 if ( wp_is_development_mode ( 'theme ' ) ) {
547+ $ template_data = get_transient ( 'wp_theme_template_contents_ ' . $ theme ->get_stylesheet () );
548+ if ( false !== $ template_data ) {
549+ delete_transient ( 'wp_theme_template_contents_ ' . $ theme ->get_stylesheet () );
550+ }
551+
542552 return file_get_contents ( $ template_file_path );
543553 }
544554
Original file line number Diff line number Diff line change @@ -778,4 +778,36 @@ public function test_get_block_template_file_content_with_current_theme_file_and
778778 $ content = _get_block_template_file_content ( $ template_file );
779779 $ this ->assertSame ( file_get_contents ( $ template_file ), $ content );
780780 }
781+
782+ /**
783+ * Tests `_get_block_template_file_content()` while using 'theme' development mode clears the existing cache for the current theme.
784+ *
785+ * @ticket 59600
786+ *
787+ * @covers ::_get_block_template_file_content
788+ */
789+ public function test_get_block_template_file_content_with_theme_development_mode_clears_existing_cache () {
790+ global $ _wp_tests_development_mode ;
791+
792+ $ _wp_tests_development_mode = 'theme ' ;
793+
794+ switch_theme ( 'block-theme ' );
795+
796+ $ template_file = DIR_TESTDATA . '/themedir1/block-theme/parts/small-header.html ' ;
797+ set_transient (
798+ 'wp_theme_template_contents_block-theme ' ,
799+ array (
800+ 'version ' => '1.0.0 ' ,
801+ 'template_content ' => array (
802+ 'parts/small-header.html ' => '<div>Some content.</div> ' ,
803+ ),
804+ )
805+ );
806+
807+ // We don't care about the value here as it is already covered by the test above.
808+ _get_block_template_file_content ( $ template_file );
809+
810+ // Ensure the relevant transient was deleted.
811+ $ this ->assertFalse ( get_transient ( 'wp_theme_template_contents_block-theme ' ) );
812+ }
781813}
You can’t perform that action at this time.
0 commit comments