Changeset 56931
- Timestamp:
- 10/13/2023 04:44:09 PM (12 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-patterns.php
r56771 r56931 351 351 } 352 352 353 $file_path = $dirpath . $file; 354 355 if ( ! file_exists( $file_path ) ) { 356 _doing_it_wrong( 357 __FUNCTION__, 358 sprintf( 359 /* translators: %s: file name. */ 360 __( 'Could not register file "%s" as a block pattern as the file does not exist.' ), 361 $file 362 ), 363 '6.4.0' 364 ); 365 $theme->delete_pattern_cache(); 366 continue; 367 } 368 353 369 // The actual pattern content is the output of the file. 354 370 ob_start(); 355 include $ dirpath . $file;371 include $file_path; 356 372 $pattern_data['content'] = ob_get_clean(); 357 373 if ( ! $pattern_data['content'] ) { … … 409 425 $can_use_cached = ! wp_is_development_mode( 'theme' ); 410 426 411 if ( $can_use_cached ) {412 $pattern_data = $theme->get_pattern_cache();413 if ( is_array( $pattern_data )) {427 $pattern_data = $theme->get_pattern_cache(); 428 if ( is_array( $pattern_data ) ) { 429 if ( $can_use_cached ) { 414 430 return $pattern_data; 415 431 } 432 // If in development mode, clear pattern cache. 433 $theme->delete_pattern_cache(); 416 434 } 417 435 -
trunk/tests/phpunit/tests/blocks/wpGetBlockPatterns.php
r56771 r56931 19 19 * @param string $theme The theme's slug. 20 20 * @param array $expected The expected pattern data. 21 22 21 */ 23 22 public function test_should_return_block_patterns( $theme, $expected ) { … … 119 118 ); 120 119 } 120 121 /** 122 * Tests that _wp_get_block_patterns() clears existing transient when in theme development mode. 123 * 124 * @ticket 59591 125 */ 126 public function test_should_clear_existing_transient_when_in_development_mode() { 127 $theme = wp_get_theme( 'block-theme-patterns' ); 128 129 // Calling the function should set the cache. 130 _wp_get_block_patterns( $theme ); 131 $this->assertSameSets( 132 array( 133 'cta.php' => array( 134 'title' => 'Centered Call To Action', 135 'slug' => 'block-theme-patterns/cta', 136 'description' => '', 137 'categories' => array( 'call-to-action' ), 138 ), 139 ), 140 $theme->get_pattern_cache(), 141 'The transient for block theme patterns should be set' 142 ); 143 144 // Calling the function while in theme development mode should clear the cache. 145 $GLOBALS['_wp_tests_development_mode'] = 'theme'; 146 _wp_get_block_patterns( $theme ); 147 unset( $GLOBALS['_wp_tests_development_mode'] ); // Reset to not pollute other tests. 148 $this->assertFalse( 149 $theme->get_pattern_cache(), 150 'The transient for block theme patterns should have been cleared due to theme development mode' 151 ); 152 } 121 153 }
Note: See TracChangeset
for help on using the changeset viewer.