WP_URL_Pattern_Prefixer::get_default_contexts(): array<string,
- Since
- 6.8.0
- Source
wp-includes/class-wp-url-pattern-prefixer.php:111
Compatibility
- WordPress
- since 6.8.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 4 of the 5 tracked releases, added in 6.8.0, and compiles on PHP 7.4 through 8.6-dev.
Return value
array<string,- string> Map of
$context_string => $base_pathpairs.
Performance profile
How much work a call to WP_URL_Pattern_Prefixer::get_default_contexts() 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
- Trivial
- Scaling
- Constant
- Instructions
- 105
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 105.
Nothing here hands control to plugin code.
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()one call below WP_URL_Pattern_Prefixer::get_default_contexts()
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 · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_URL_Pattern_Prefixer::get_default_contexts() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 105 | home_url(), wp_parse_url(), trailingslashit(), ::escape_pattern_string(), site_url(), wp_parse_url(), trailingslashit(), ::escape_pattern_string(), wp_upload_dir(), wp_parse_url(), trailingslashit(), ::escape_pattern_string(), content_url(), wp_parse_url(), trailingslashit(), ::escape_pattern_string(), plugins_url(), wp_parse_url(), trailingslashit(), ::escape_pattern_string(), get_stylesheet_directory_uri(), wp_parse_url(), trailingslashit(), ::escape_pattern_string(), get_template_directory_uri(), wp_parse_url(), trailingslashit(), ::escape_pattern_string() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 105 | 105 | 0 | |
| 8.5 | 105 | 105 | 0 | |
| 8.4 | 105 | 105 | 0 | |
| 8.3 | 105 | 105 | 0 | |
| 8.2 | 105 | 105 | 0 | |
| 8.1 | 105 | 105 | 0 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 106 | 106 | 0 |
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.
Uses · 10
- trailingslashit()Appends a trailing slash.
- wp_parse_url()A wrapper for PHP's parse_url() function that handles consistency in the return values across PHP versions.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- site_url()Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
- wp_upload_dir()Returns an array containing the current upload directory's path and URL.
- content_url()Retrieves the URL to the content directory.
- plugins_url()Retrieves a URL within the plugins or mu-plugins directory.
- get_stylesheet_directory_uri()Retrieves stylesheet directory URI for the active theme.
- get_template_directory_uri()Retrieves template directory URI for the active theme.
- WP_URL_Pattern_Prefixer::escape_pattern_string()Escapes a string for use in a URL pattern component.
Used by · 1
- WP_URL_Pattern_Prefixer::__construct()Constructor.
Source code
public static function get_default_contexts(): array { return array( 'home' => self::escape_pattern_string( trailingslashit( (string) wp_parse_url( home_url( '/' ), PHP_URL_PATH ) ) ), 'site' => self::escape_pattern_string( trailingslashit( (string) wp_parse_url( site_url( '/' ), PHP_URL_PATH ) ) ), 'uploads' => self::escape_pattern_string( trailingslashit( (string) wp_parse_url( wp_upload_dir( null, false )['baseurl'], PHP_URL_PATH ) ) ), 'content' => self::escape_pattern_string( trailingslashit( (string) wp_parse_url( content_url(), PHP_URL_PATH ) ) ), 'plugins' => self::escape_pattern_string( trailingslashit( (string) wp_parse_url( plugins_url(), PHP_URL_PATH ) ) ), 'template' => self::escape_pattern_string( trailingslashit( (string) wp_parse_url( get_stylesheet_directory_uri(), PHP_URL_PATH ) ) ), 'stylesheet' => self::escape_pattern_string( trailingslashit( (string) wp_parse_url( get_template_directory_uri(), PHP_URL_PATH ) ) ), ); }Changelog
Introduced in 6.8.0. Unchanged from 6.8.8 through 7.1.0.
Signature, return type and hooks compared across 4 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-url-pattern-prefixer.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.