wppaste
WordPress

WP_Rewrite::get_date_permastruct(): string|false

Since
1.5.0
Source
wp-includes/class-wp-rewrite.php:495
Retrieves date permalink structure, with year, month, and day.

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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
4–42

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 49.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
4

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 inputpreg_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.

WhenInstructionsCalls it makes
always4–7none
!isset($value) && !empty($value)28–42preg_match_all()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev494–4210
8.5494–4210
8.4494–42103 fewer instructions than PHP 8.3
8.3524–4510
8.2524–4510
8.1524–4510
7.4524–4510

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

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.