Skip to content

Commit

Permalink
Pattern Directory: Add Core's should_load_remote_block_patterns fil…
Browse files Browse the repository at this point in the history
…ter.

The filter was added to Core during the process of syncing it with Gutenberg, but wasn't backported to Gutenberg until now.

See https://core.trac.wordpress.org/ticket/53246

Co-authored-by: Kelly Dwan <[email protected]>
  • Loading branch information
iandunn and ryelle committed Jul 13, 2021
1 parent 2e5733e commit 1bafaa4
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions lib/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,29 @@ function load_remote_patterns() {
return;
}

$request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
$core_keyword_id = 11; // 11 is the ID for "core".
$request->set_param( 'keyword', $core_keyword_id );
$response = rest_do_request( $request );
if ( $response->is_error() ) {
return;
}
$patterns = $response->get_data();
/**
* Filter to disable remote block patterns.
*
* @since 5.8.0
*
* @param bool $should_load_remote
*/
$should_load_remote = apply_filters( 'should_load_remote_block_patterns', true );

if ( $should_load_remote ) {
$request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
$core_keyword_id = 11; // 11 is the ID for "core".
$request->set_param( 'keyword', $core_keyword_id );
$response = rest_do_request( $request );
if ( $response->is_error() ) {
return;
}
$patterns = $response->get_data();

foreach ( $patterns as $settings ) {
$pattern_name = 'core/' . sanitize_title( $settings['title'] );
register_block_pattern( $pattern_name, (array) $settings );
foreach ( $patterns as $settings ) {
$pattern_name = 'core/' . sanitize_title( $settings['title'] );
register_block_pattern( $pattern_name, (array) $settings );
}
}
}

Expand Down

0 comments on commit 1bafaa4

Please sign in to comment.