$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 $pattern ) { $pattern['source'
] = 'pattern-directory/core';
$normalized_pattern =
wp_normalize_remote_block_pattern( $pattern );
$pattern_name = 'core/' .
sanitize_title( $normalized_pattern['title'
] );
register_block_pattern( $pattern_name,
$normalized_pattern );
} }}/**
* Register `Featured` (category) patterns from wordpress.org/patterns.
*
* @since 5.9.0
* @since 6.2.0 Normalized the pattern from the API (snake_case) to the
* format expected by `register_block_pattern()` (camelCase).
* @since 6.3.0 Add 'pattern-directory/featured' to the pattern's 'source'.
*/