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. Built from https://develop.svn.wordpress.org/trunk@53209 git-svn-id: http://core.svn.wordpress.org/trunk@52798 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0559e94375
commit
09688edc45
|
@ -16,6 +16,14 @@
|
|||
*/
|
||||
class WP_REST_Block_Patterns_Controller extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Defines whether remote patterns should be loaded.
|
||||
*
|
||||
* @since 6.0.0
|
||||
* @var bool
|
||||
*/
|
||||
private $remote_patterns_loaded;
|
||||
|
||||
/**
|
||||
* Constructs the controller.
|
||||
*
|
||||
|
@ -81,10 +89,14 @@ class WP_REST_Block_Patterns_Controller extends WP_REST_Controller {
|
|||
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
// Load block patterns from w.org.
|
||||
_load_remote_block_patterns(); // Patterns with the `core` keyword.
|
||||
_load_remote_featured_patterns(); // Patterns in the `featured` category.
|
||||
_register_remote_theme_patterns(); // Patterns requested by current theme.
|
||||
if ( ! $this->remote_patterns_loaded ) {
|
||||
// Load block patterns from w.org.
|
||||
_load_remote_block_patterns(); // Patterns with the `core` keyword.
|
||||
_load_remote_featured_patterns(); // Patterns in the `featured` category.
|
||||
_register_remote_theme_patterns(); // Patterns requested by current theme.
|
||||
|
||||
$this->remote_patterns_loaded = true;
|
||||
}
|
||||
|
||||
$response = array();
|
||||
$patterns = WP_Block_Patterns_Registry::get_instance()->get_all_registered();
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.0-beta1-53208';
|
||||
$wp_version = '6.0-beta1-53209';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue