Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
_register_remote_theme_patterns() WordPress Function
The register_remote_theme_patterns() function allows you to register a new remote theme pattern. This function takes two arguments: the first is the name of the new pattern, and the second is an array of settings for the new pattern. The name argument is required and must be a string. The array of settings is also required and must contain at least a 'url' key. The 'url' key should contain the URL of the remote theme's directory. Additional keys that can be included in the array of settings are 'preview_url' and 'type'. The 'preview_url' key should contain a URL to a preview image for the remote theme. The 'type' key can be used to specify the type of files that the remote theme contains. Valid values for this key are 'php', 'css', and 'js'. Once a new remote theme pattern has been registered, it can be used by calling the get_remote_theme() function. This function takes two arguments: the first is the name of the remote theme, and the second is an array of arguments. The only required argument for this function is the 'url' key, which should contain the URL of the remote theme's directory. Additional arguments that can be passed to this function include 'preview_url' and 'type'. These arguments will override the values set in the array of settings for the remote theme pattern.
_register_remote_theme_patterns() #
Registers patterns from Pattern Directory provided by a theme’s theme.json file.
Source
File: wp-includes/block-patterns.php
function _register_remote_theme_patterns() {
if ( ! get_theme_support( 'core-block-patterns' ) ) {
return;
}
/** This filter is documented in wp-includes/block-patterns.php */
if ( ! apply_filters( 'should_load_remote_block_patterns', true ) ) {
return;
}
if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
return;
}
$pattern_settings = WP_Theme_JSON_Resolver::get_theme_data()->get_patterns();
if ( empty( $pattern_settings ) ) {
return;
}
$request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
$request['slug'] = $pattern_settings;
$response = rest_do_request( $request );
if ( $response->is_error() ) {
return;
}
$patterns = $response->get_data();
$patterns_registry = WP_Block_Patterns_Registry::get_instance();
foreach ( $patterns as $pattern ) {
$pattern_name = sanitize_title( $pattern['title'] );
// Some patterns might be already registered as core patterns with the `core` prefix.
$is_registered = $patterns_registry->is_registered( $pattern_name ) || $patterns_registry->is_registered( "core/$pattern_name" );
if ( ! $is_registered ) {
register_block_pattern( $pattern_name, (array) $pattern );
}
}
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 6.0.0 | Introduced. |