WP_Rewrite::init()
- Since
- 1.5.0
- Source
wp-includes/class-wp-rewrite.php:1919
Description
The 'use_verbose_page_rules' object property will be set to true if the permalink structure begins with one of the following: '%postname%', '%category%', '%tag%', or '%author%'.
Compatibility
- WordPress
- since 1.5.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 WP_Rewrite::init() 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
- Moderate
- Scaling
- Constant
- Instructions
- 42–46
- Plugin surface
- None
- Called by
- 4
Reads stored settings via get_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 49.
Nothing here hands control to plugin code.
4 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()one call below WP_Rewrite::init() - cacheobject cache
wp_cache_get()one call below WP_Rewrite::init() - serializeserialisation
maybe_unserialize()one call below WP_Rewrite::init()
Further down the call graph this can also reach 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 · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Rewrite::init() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 42–46 | get_option(), ->using_index_permalinks(), str_ends_with() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 49 | 42–46 | 2 | |
| 8.5 | 49 | 42–46 | 2 | |
| 8.4 | 49 | 42–46 | 2 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 58 | 51–55 | 2 | |
| 8.2 | 58 | 51–55 | 2 | |
| 8.1 | 58 | 51–55 | 2 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 59 | 52–56 | 2 |
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 · 3
- get_option()Retrieves an option value based on an option name.
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
- WP_Rewrite::using_index_permalinks()Determines whether permalinks are being used and rewrite module is not enabled.
Used by · 4
- WP_Rewrite::__construct()Constructor - Calls init(), which runs setup.
- WP_Rewrite::set_category_base()Sets the category base for the category permalink.
- WP_Rewrite::set_permalink_structure()Sets the main permalink structure for the site.
- WP_Rewrite::set_tag_base()Sets the tag base for the tag permalink.
Source code
public function init() { $this->extra_rules = array(); $this->non_wp_rules = array(); $this->endpoints = array(); $this->permalink_structure = get_option( 'permalink_structure' ); $this->front = substr( $this->permalink_structure, 0, strpos( $this->permalink_structure, '%' ) ); $this->root = ''; if ( $this->using_index_permalinks() ) { $this->root = $this->index . '/'; } unset( $this->author_structure ); unset( $this->date_structure ); unset( $this->page_structure ); unset( $this->search_structure ); unset( $this->feed_structure ); unset( $this->comment_feed_structure ); $this->use_trailing_slashes = str_ends_with( $this->permalink_structure, '/' ); // Enable generic rules for pages if permalink structure doesn't begin with a wildcard. if ( preg_match( '/^[^%]*%(?:postname|category|tag|author)%/', $this->permalink_structure ) ) { $this->use_verbose_page_rules = true; } else { $this->use_verbose_page_rules = false; } }Changelog
Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/class-wp-rewrite.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.