_load_remote_featured_patterns()
- Since
- 5.9.0, 6.2.0, 6.3.0
- Source
wp-includes/block-patterns.php:328
Featured (category) patterns from wordpress.org/patterns.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 _load_remote_featured_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
- 11–38
- 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 68.
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, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _load_remote_featured_patterns() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 11–12 | get_theme_support(), apply_filters() |
->is_error() | 29 | get_theme_support(), apply_filters(), ->set_param(), rest_do_request(), ->is_error() |
!->is_error() | 37–38 | get_theme_support(), apply_filters(), ->set_param(), 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: 68 instructions, 11–38 executed per call, 7 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 _load_remote_featured_patterns() runs, in this order:
- apply_filters( should_load_remote_block_patterns )filterline 332 (+4 into the body)
Filter to disable remote block patterns.
Uses · 8
- get_theme_support()Gets the theme support arguments passed when registering that support.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- 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 _load_remote_featured_patterns() { $supports_core_patterns = get_theme_support( 'core-block-patterns' ); /** This filter is documented in wp-includes/block-patterns.php */ $should_load_remote = apply_filters( 'should_load_remote_block_patterns', true ); if ( ! $should_load_remote || ! $supports_core_patterns ) { return; } $request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' ); $featured_cat_id = 26; // This is the `Featured` category id from pattern directory. $request->set_param( 'category', $featured_cat_id ); $response = rest_do_request( $request ); if ( $response->is_error() ) { return; } $patterns = $response->get_data(); $registry = WP_Block_Patterns_Registry::get_instance(); foreach ( $patterns as $pattern ) { $pattern['source'] = 'pattern-directory/featured'; $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 = $registry->is_registered( $pattern_name ) || $registry->is_registered( "core/$pattern_name" ); if ( ! $is_registered ) { register_block_pattern( $pattern_name, $normalized_pattern ); } }}Changelog
Introduced in 5.9.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.