Make WordPress Core

Changeset 53209


Ignore:
Timestamp:
04/19/2022 09:26:20 AM (23 months ago)
Author:
gziolo
Message:

REST API: Don't load remote patterns twice in the controller

This PR aims to fix an issue with fetching remote patterns multiple times inside the WP_REST_Block_Patterns_Controller::get_items method.

Follow-up [53152].

Props antonvlasenko.
See #55567.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php

    r53171 r53209  
    1616 */
    1717class WP_REST_Block_Patterns_Controller extends WP_REST_Controller {
     18
     19    /**
     20     * Defines whether remote patterns should be loaded.
     21     *
     22     * @since 6.0.0
     23     * @var bool
     24     */
     25    private $remote_patterns_loaded;
    1826
    1927    /**
     
    8290     */
    8391    public function get_items( $request ) {
    84         // Load block patterns from w.org.
    85         _load_remote_block_patterns(); // Patterns with the `core` keyword.
    86         _load_remote_featured_patterns(); // Patterns in the `featured` category.
    87         _register_remote_theme_patterns(); // Patterns requested by current theme.
     92        if ( ! $this->remote_patterns_loaded ) {
     93            // Load block patterns from w.org.
     94            _load_remote_block_patterns(); // Patterns with the `core` keyword.
     95            _load_remote_featured_patterns(); // Patterns in the `featured` category.
     96            _register_remote_theme_patterns(); // Patterns requested by current theme.
     97
     98            $this->remote_patterns_loaded = true;
     99        }
    88100
    89101        $response = array();
Note: See TracChangeset for help on using the changeset viewer.