Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moving get_items() method from Gutenberg_REST_Block_Patterns_Controll…
…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 Sep 1, 2023
commit 6c9011f03267f6fb37031d86afa2678f9add74ea
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.

Copy link
Member Author

@ramonjd ramonjd Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the get_items() method from Gutenberg_REST_Block_Patterns_Controller_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

The consequence is that Gutenberg plugin users who are running WordPress 6.2 will get the benefit of these 6.3 changes.

Does that sound legit @aaronrobertshaw ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's sounds right, yes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking 🙇🏻

$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 );
}
}