mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-02 16:20:05 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@53209 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user