Make WordPress Core


Ignore:
Timestamp:
10/03/2023 06:17:03 PM (14 months ago)
Author:
flixos90
Message:

Editor: Simplify return shape and logic of _wp_get_block_patterns().

Follow up to [56765].

Props spacedmonkey.
Fixes #59490.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme.php

    r56765 r56771  
    826826
    827827    /**
    828      * Clear block pattern cache.
     828     * Gets block pattern cache.
     829     *
     830     * @since 6.4.0
     831     *
     832     * @return array|false Returns an array of patterns if cache is found, otherwise false.
     833     */
     834    public function get_pattern_cache() {
     835        if ( ! $this->exists() ) {
     836            return false;
     837        }
     838        $pattern_data = get_transient( 'wp_theme_patterns_' . $this->stylesheet );
     839        if ( is_array( $pattern_data ) && $pattern_data['version'] === $this->get( 'Version' ) ) {
     840            return $pattern_data['patterns'];
     841        }
     842        return false;
     843    }
     844
     845    /**
     846     * Sets block pattern cache.
     847     *
     848     * @since 6.4.0
     849     *
     850     * @param array $patterns Block patterns data to set in cache.
     851     */
     852    public function set_pattern_cache( array $patterns ) {
     853        $pattern_data = array(
     854            'version'  => $this->get( 'Version' ),
     855            'patterns' => $patterns,
     856        );
     857        set_transient( 'wp_theme_patterns_' . $this->stylesheet, $pattern_data );
     858    }
     859
     860    /**
     861     * Clears block pattern cache.
    829862     *
    830863     * @since 6.4.0
Note: See TracChangeset for help on using the changeset viewer.