Make WordPress Core


Ignore:
Timestamp:
10/13/2023 04:44:09 PM (8 months ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-patterns.php

    r56771 r56931  
    351351            }
    352352
     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
    353369            // The actual pattern content is the output of the file.
    354370            ob_start();
    355             include $dirpath . $file;
     371            include $file_path;
    356372            $pattern_data['content'] = ob_get_clean();
    357373            if ( ! $pattern_data['content'] ) {
     
    409425    $can_use_cached = ! wp_is_development_mode( 'theme' );
    410426
    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 ) {
    414430            return $pattern_data;
    415431        }
     432        // If in development mode, clear pattern cache.
     433        $theme->delete_pattern_cache();
    416434    }
    417435
Note: See TracChangeset for help on using the changeset viewer.