Skip to content

Commit

Permalink
Moving get_items() method from Gutenberg_REST_Block_Patterns_Controll…
Browse files Browse the repository at this point in the history
…er_6_2 to Gutenberg_REST_Block_Patterns_Controller_6_3 because the following methods were updated in 6.3:

- gutenberg_load_remote_block_patterns
- gutenberg_load_remote_featured_patterns
- gutenberg_register_remote_theme_patterns
  • Loading branch information
ramonjd committed Aug 14, 2023
1 parent bcc6456 commit f4696fe
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,33 @@ public function get_item_schema() {

return $this->add_additional_fields_schema( $this->schema );
}

/**
* Retrieves all block patterns.
*
* @since 6.0.0
* @since 6.2.0 Added migration for old core pattern categories to the new ones.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_items( $request ) {
if ( ! $this->remote_patterns_loaded ) {
// Load block patterns from w.org.
gutenberg_load_remote_block_patterns(); // Patterns with the `core` keyword.
gutenberg_load_remote_featured_patterns(); // Patterns in the `featured` category.
gutenberg_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();
foreach ( $patterns as $pattern ) {
$migrated_pattern = $this->migrate_pattern_categories( $pattern );
$prepared_pattern = $this->prepare_item_for_response( $migrated_pattern, $request );
$response[] = $this->prepare_response_for_collection( $prepared_pattern );
}
return rest_ensure_response( $response );
}
}

0 comments on commit f4696fe

Please sign in to comment.