WP_Rewrite::get_date_permastruct(): string|false
- Since
- 1.5.0
- Source
wp-includes/class-wp-rewrite.php:495
Description
The permalink structure for the date, if not set already depends on the permalink structure. It can be one of three formats. The first is year, month, day; the second is day, month, year; and the last format is month, day, year. These are matched against the permalink structure for which one is used. If none matches, then the default will be used, which is year, month, day.
Prevents post ID and date permalinks from overlapping. In the case of post_id, the date permalink will be prepended with front permalink with 'date/' before the actual permalink to form the complete date permalink structure.
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.
Return value
string|false- Date permalink structure on success, false on failure.
Performance profile
How much work a call to WP_Rewrite::get_date_permastruct() 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
- 4–42
- Plugin surface
- None
- Called by
- 4
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 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
- regexregular expression over the whole input
preg_match_all()called directly
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Rewrite::get_date_permastruct() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 4–7 | none |
!isset($value) && !empty($value) | 28–42 | preg_match_all() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 49 | 4–42 | 10 | |
| 8.5 | 49 | 4–42 | 10 | |
| 8.4 | 49 | 4–42 | 10 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 52 | 4–45 | 10 | |
| 8.2 | 52 | 4–45 | 10 | |
| 8.1 | 52 | 4–45 | 10 | |
| 7.4 | 52 | 4–45 | 10 |
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 · 1
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
Used by · 4
- WP_Rewrite::get_day_permastruct()Retrieves the day permalink structure with month and year.
- WP_Rewrite::get_month_permastruct()Retrieves the month permalink structure without day and with year.
- WP_Rewrite::get_year_permastruct()Retrieves the year permalink structure without month and day.
- WP_Rewrite::rewrite_rules()Constructs rewrite matches and queries from permalink structure.
Source code
public function get_date_permastruct() { if ( isset( $this->date_structure ) ) { return $this->date_structure; } if ( empty( $this->permalink_structure ) ) { $this->date_structure = ''; return false; } // The date permalink must have year, month, and day separated by slashes. $endians = array( '%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%' ); $this->date_structure = ''; $date_endian = ''; foreach ( $endians as $endian ) { if ( str_contains( $this->permalink_structure, $endian ) ) { $date_endian = $endian; break; } } if ( empty( $date_endian ) ) { $date_endian = '%year%/%monthnum%/%day%'; } /* * Do not allow the date tags and %post_id% to overlap in the permalink * structure. If they do, move the date tags to $front/date/. */ $front = $this->front; preg_match_all( '/%.+?%/', $this->permalink_structure, $tokens ); $tok_index = 1; foreach ( (array) $tokens[0] as $token ) { if ( '%post_id%' === $token && ( $tok_index <= 3 ) ) { $front = $front . 'date/'; break; } ++$tok_index; } $this->date_structure = $front . $date_endian; return $this->date_structure; }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.