_register_remote_theme_patterns()
- Since
- 6.0.0, 6.2.0, 6.3.0
- Source
wp-includes/block-patterns.php:369
theme.json file.Compatibility
- WordPress
- since 6.3.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Performance profile
How much work a call to _register_remote_theme_patterns() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 6–37
- Plugin surface
- 1 hook
- Called by
- 1
Touches nothing outside its own arguments.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 69.
Third-party callbacks on 'should_load_remote_block_patterns' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, cache, serialize, transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _register_remote_theme_patterns() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!apply_filters() | 6 | apply_filters() |
apply_filters() && !wp_theme_has_theme_json() | 9 | apply_filters(), wp_theme_has_theme_json() |
apply_filters() && wp_theme_has_theme_json() && empty($pattern_settings) | 14 | apply_filters(), wp_theme_has_theme_json(), wp_get_theme_directory_pattern_slugs() |
apply_filters() && wp_theme_has_theme_json() && !empty($pattern_settings) && ->is_error() | 28 | apply_filters(), wp_theme_has_theme_json(), wp_get_theme_directory_pattern_slugs(), rest_do_request(), ->is_error() |
apply_filters() && wp_theme_has_theme_json() && !empty($pattern_settings) && !->is_error() | 36–37 | apply_filters(), wp_theme_has_theme_json(), wp_get_theme_directory_pattern_slugs(), rest_do_request(), ->is_error(), ->get_data(), ::WP_Block_Patterns_Registry() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 69 instructions, 6–37 executed per call, 8 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while _register_remote_theme_patterns() runs, in this order:
- apply_filters( should_load_remote_block_patterns )filterline 371 (+2 into the body)
Filter to disable remote block patterns.
Uses · 9
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_theme_has_theme_json()Checks whether a theme or its parent has a theme.json file.
- wp_get_theme_directory_pattern_slugs()Returns the current theme's wanted patterns (slugs) to be registered from Pattern Directory.
- rest_do_request()Do a REST request.
- wp_normalize_remote_block_pattern()Normalize the pattern properties to camelCase.
- sanitize_title()Sanitizes a string into a slug, which can be used in URLs or HTML attributes.
- register_block_pattern()Registers a new block pattern.
- WP_REST_Request::__construct()Constructor.
- WP_Block_Patterns_Registry::get_instance()Utility method to retrieve the main instance of the class.
Used by · 1
- WP_REST_Block_Patterns_Controller::get_items()Retrieves all block patterns.
Source code
function _register_remote_theme_patterns() { /** This filter is documented in wp-includes/block-patterns.php */ if ( ! apply_filters( 'should_load_remote_block_patterns', true ) ) { return; } if ( ! wp_theme_has_theme_json() ) { return; } $pattern_settings = wp_get_theme_directory_pattern_slugs(); 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['source'] = 'pattern-directory/theme'; $normalized_pattern = wp_normalize_remote_block_pattern( $pattern ); $pattern_name = sanitize_title( $normalized_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, $normalized_pattern ); } }}Changelog
Introduced in 6.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
register_block_pattern() (camelCase).from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/block-patterns.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.