wppaste
WordPress

WP_Customize_Date_Time_Control::content_template()

Since
4.9.0
Source
wp-includes/customize/class-wp-customize-date-time-control.php:98
Renders a JS template for the content of date time control.

Compatibility

WordPress
since 4.9.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_Customize_Date_Time_Control::content_template() 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

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
110–122

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()one call below WP_Customize_Date_Time_Control::content_template()
  • cacheobject cachewp_cache_get()one call below WP_Customize_Date_Time_Control::content_template()
  • serializeserialisationmaybe_unserialize()one call below WP_Customize_Date_Time_Control::content_template()

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 · 3 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Customize_Date_Time_Control::content_template() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always110->json(), ->get_month_choices(), array_merge(), ->get_timezone_info(), get_option(), substr_count(), wp_json_encode(), esc_html_e(), ob_start(), esc_html_e(), ob_get_clean(), ob_start(), esc_html_e(), ob_get_clean(), ob_start(), esc_html_e(), ob_get_clean(), printf(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e()
always116->json(), ->get_month_choices(), array_merge(), ->get_timezone_info(), get_option(), substr_count(), substr_count(), wp_json_encode(), esc_html_e(), ob_start(), esc_html_e(), ob_get_clean(), ob_start(), esc_html_e(), ob_get_clean(), ob_start(), esc_html_e(), ob_get_clean(), printf(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e()
always121–122->json(), ->get_month_choices(), array_merge(), ->get_timezone_info(), get_option(), substr_count(), substr_count(), substr_count(), wp_json_encode(), esc_html_e(), ob_start(), esc_html_e(), ob_get_clean(), ob_start(), esc_html_e(), ob_get_clean(), ob_start(), esc_html_e(), ob_get_clean(), printf(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e(), esc_html_e()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev122110–1223
8.5122110–1223
8.4122110–122318 fewer instructions than PHP 8.3
8.3140128–1403
8.2140128–1403
8.1140128–1403
7.4140128–1403

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 · 6

Source code

	public function content_template() {		$data          = array_merge( $this->json(), $this->get_month_choices() );		$timezone_info = $this->get_timezone_info(); 		$date_format = get_option( 'date_format' );		$date_format = preg_replace( '/(?<!\\\\)[Yyo]/', '%1$s', $date_format );		$date_format = preg_replace( '/(?<!\\\\)[FmMn]/', '%2$s', $date_format );		$date_format = preg_replace( '/(?<!\\\\)[jd]/', '%3$s', $date_format ); 		// Fallback to ISO date format if year, month, or day are missing from the date format.		if ( 1 !== substr_count( $date_format, '%1$s' ) || 1 !== substr_count( $date_format, '%2$s' ) || 1 !== substr_count( $date_format, '%3$s' ) ) {			$date_format = '%1$s-%2$s-%3$s';		}		?> 		<# _.defaults( data, <?php echo wp_json_encode( $data ); ?> ); #>		<# var idPrefix = _.uniqueId( 'el' ) + '-'; #> 		<# if ( data.label ) { #>			<span class="customize-control-title">				{{ data.label }}			</span>		<# } #>		<div class="customize-control-notifications-container"></div>		<# if ( data.description ) { #>			<span class="description customize-control-description">{{ data.description }}</span>		<# } #>		<div class="date-time-fields {{ data.includeTime ? 'includes-time' : '' }}">			<fieldset class="day-row">				<legend class="title-day {{ ! data.includeTime ? 'screen-reader-text' : '' }}"><?php esc_html_e( 'Date' ); ?></legend>				<div class="day-fields clear">					<?php ob_start(); ?>					<label for="{{ idPrefix }}date-time-month" class="screen-reader-text">						<?php						/* translators: Hidden accessibility text. */						esc_html_e( 'Month' );						?>					</label>					<select id="{{ idPrefix }}date-time-month" class="date-input month" data-component="month">						<# _.each( data.month_choices, function( choice ) {							if ( _.isObject( choice ) && ! _.isUndefined( choice.text ) && ! _.isUndefined( choice.value ) ) {								text = choice.text;								value = choice.value;							}							#>							<option value="{{ value }}" >								{{ text }}							</option>						<# } ); #>					</select>					<?php $month_field = trim( ob_get_clean() ); ?> 					<?php ob_start(); ?>					<label for="{{ idPrefix }}date-time-day" class="screen-reader-text">						<?php						/* translators: Hidden accessibility text. */						esc_html_e( 'Day' );						?>					</label>					<input id="{{ idPrefix }}date-time-day" type="number" size="2" autocomplete="off" class="date-input day" data-component="day" min="1" max="31" />					<?php $day_field = trim( ob_get_clean() ); ?> 					<?php ob_start(); ?>					<label for="{{ idPrefix }}date-time-year" class="screen-reader-text">						<?php						/* translators: Hidden accessibility text. */						esc_html_e( 'Year' );						?>					</label>					<input id="{{ idPrefix }}date-time-year" type="number" size="4" autocomplete="off" class="date-input year" data-component="year" min="{{ data.minYear }}" max="{{ data.maxYear }}">					<?php $year_field = trim( ob_get_clean() ); ?> 					<?php printf( $date_format, $year_field, $month_field, $day_field ); ?>				</div>			</fieldset>			<# if ( data.includeTime ) { #>				<fieldset class="time-row clear">					<legend class="title-time"><?php esc_html_e( 'Time' ); ?></legend>					<div class="time-fields clear">						<label for="{{ idPrefix }}date-time-hour" class="screen-reader-text">

Changelog

Introduced in 4.9.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 6.7.7 tag, from src/wp-includes/customize/class-wp-customize-date-time-control.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.