wppaste
WordPress

populate_options( array $options = array() )

Since
1.5.0, 5.1.0
Source
wp-admin/includes/schema.php:362
Create WordPress options and set the default values.

Compatibility

WordPress
since 5.1.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.

Parameters

$optionsarrayoptional
Custom option $key => $value pairs to use. Default empty array.Default: array()

Performance profile

How much work a call to populate_options() 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
Heavy

Reaches the database via ->get_col().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
202–242

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

Plugin surface
1 hook

Third-party callbacks on 'populate_options' run inside this call, and their cost is not bounded by anything here.

Called by
4

4 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()called directly
  • serializeserialisationmaybe_serialize()called directly
  • optionoption read or writeupdate_option()called directly
  • sqldatabase query->get_col()called directly
  • cacheobject cachewp_cache_get()one call below populate_options()

Further down the call graph this can also reach 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 · 32 distinct outcomes

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

WhenInstructionsCalls it makes
->exists() && empty($insert) && __get_option()202–215wp_guess_url(), do_action(), wp_get_theme(), ->exists(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), ->query(), delete_expired_transients()
!->exists() && empty($insert) && __get_option()205–218wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), ->query(), delete_expired_transients()
->exists() && empty($insert) && !__get_option()206–219wp_guess_url(), do_action(), wp_get_theme(), ->exists(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), update_option(), ->query(), delete_expired_transients()
->exists() && !$offset_or_tz && empty($insert) && __get_option()208–221wp_guess_url(), do_action(), wp_get_theme(), ->exists(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), ->query(), delete_expired_transients()
->exists() && empty($insert) && __get_option()208–221wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ->get_stylesheet(), ->get_template(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), ->query(), delete_expired_transients()
!->exists() && empty($insert) && !__get_option()209–222wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), update_option(), ->query(), delete_expired_transients()
->exists() && !empty($insert) && __get_option()210–223wp_guess_url(), do_action(), wp_get_theme(), ->exists(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), ->query(), delete_expired_transients()
!->exists() && !$offset_or_tz && empty($insert) && __get_option()211–224wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), ->query(), delete_expired_transients()
!->exists() && empty($insert) && __get_option()211–224wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), ->get_stylesheet(), ->get_template(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), ->query(), delete_expired_transients()
->exists() && !$offset_or_tz && empty($insert) && !__get_option()212–225wp_guess_url(), do_action(), wp_get_theme(), ->exists(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), update_option(), ->query(), delete_expired_transients()
->exists() && empty($insert) && !__get_option()212–225wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ->get_stylesheet(), ->get_template(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), update_option(), ->query(), delete_expired_transients()
!->exists() && !empty($insert) && __get_option()213–226wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), ->query(), delete_expired_transients()
20 further outcomes, up to 242 instructions
->exists() && !empty($insert) && !__get_option()214–227wp_guess_url(), do_action(), wp_get_theme(), ->exists(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), update_option(), ->query(), delete_expired_transients()
->exists() && !$offset_or_tz && empty($insert) && __get_option()214–227wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ->get_stylesheet(), ->get_template(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), ->query(), delete_expired_transients()
!->exists() && !$offset_or_tz && empty($insert) && !__get_option()215–228wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), update_option(), ->query(), delete_expired_transients()
!->exists() && empty($insert) && !__get_option()215–228wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), ->get_stylesheet(), ->get_template(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), update_option(), ->query(), delete_expired_transients()
->exists() && !$offset_or_tz && !empty($insert) && __get_option()216–229wp_guess_url(), do_action(), wp_get_theme(), ->exists(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), ->query(), delete_expired_transients()
->exists() && !empty($insert) && __get_option()216–229wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ->get_stylesheet(), ->get_template(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), ->query(), delete_expired_transients()
!->exists() && !empty($insert) && !__get_option()217–230wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), update_option(), ->query(), delete_expired_transients()
!->exists() && !$offset_or_tz && empty($insert) && __get_option()217–230wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), ->get_stylesheet(), ->get_template(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), ->query(), delete_expired_transients()
->exists() && !$offset_or_tz && empty($insert) && !__get_option()218–231wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ->get_stylesheet(), ->get_template(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), update_option(), ->query(), delete_expired_transients()
!->exists() && !$offset_or_tz && !empty($insert) && __get_option()219–232wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), ->query(), delete_expired_transients()
!->exists() && !empty($insert) && __get_option()219–232wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), ->get_stylesheet(), ->get_template(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), ->query(), delete_expired_transients()
->exists() && !$offset_or_tz && !empty($insert) && !__get_option()220–233wp_guess_url(), do_action(), wp_get_theme(), ->exists(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), update_option(), ->query(), delete_expired_transients()
->exists() && !empty($insert) && !__get_option()220–233wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ->get_stylesheet(), ->get_template(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), update_option(), ->query(), delete_expired_transients()
!->exists() && !$offset_or_tz && empty($insert) && !__get_option()221–234wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), ->get_stylesheet(), ->get_template(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), __get_option(), update_option(), ->query(), delete_expired_transients()
->exists() && !$offset_or_tz && !empty($insert) && __get_option()222–235wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ->get_stylesheet(), ->get_template(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), ->query(), delete_expired_transients()
!->exists() && !$offset_or_tz && !empty($insert) && !__get_option()223–236wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), update_option(), ->query(), delete_expired_transients()
!->exists() && !empty($insert) && !__get_option()223–236wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), ->get_stylesheet(), ->get_template(), _x(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), update_option(), ->query(), delete_expired_transients()
!->exists() && !$offset_or_tz && !empty($insert) && __get_option()225–238wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), ->get_stylesheet(), ->get_template(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), ->query(), delete_expired_transients()
->exists() && !$offset_or_tz && !empty($insert) && !__get_option()226–239wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ->get_stylesheet(), ->get_template(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), update_option(), ->query(), delete_expired_transients()
!->exists() && !$offset_or_tz && !empty($insert) && !__get_option()229–242wp_guess_url(), do_action(), wp_get_theme(), ->exists(), ::WP_Theme(), ->get_stylesheet(), ->get_template(), _x(), timezone_identifiers_list(), __(), _x(), __(), __(), __(), time(), is_multisite(), is_multisite(), wp_parse_args(), array_keys(), ->get_col(), ->query(), __get_option(), update_option(), ->query(), delete_expired_transients()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev277202–24218
8.5277202–24218
8.4277202–2421811 fewer instructions than PHP 8.3
8.3288207–25018
8.2288207–25018
8.1288207–25018
7.4288207–25018

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.

Hooks and filters fired · 1

One hook fires while populate_options() runs, in this order:

  1. do_action( populate_options )actionline 371 (+9 into the body)

    Fires before creating WordPress options and populating their default values.

Uses · 14

Show all 14

Used by · 4

Source code

function populate_options( array $options = array() ) {	global $wpdb, $wp_db_version, $wp_current_db_version; 	$guessurl = wp_guess_url();	/**	 * Fires before creating WordPress options and populating their default values.	 *	 * @since 2.6.0	 */	do_action( 'populate_options' ); 	// If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme.	$stylesheet = WP_DEFAULT_THEME;	$template   = WP_DEFAULT_THEME;	$theme      = wp_get_theme( WP_DEFAULT_THEME );	if ( ! $theme->exists() ) {		$theme = WP_Theme::get_core_default_theme();	} 	// If we can't find a core default theme, WP_DEFAULT_THEME is the best we can do.	if ( $theme ) {		$stylesheet = $theme->get_stylesheet();		$template   = $theme->get_template();	} 	$timezone_string = '';	$gmt_offset      = 0;	/*	 * translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14)	 * or a valid timezone string (America/New_York). See https://www.php.net/manual/en/timezones.php	 * for all timezone strings currently supported by PHP.	 *	 * Important: When a previous timezone string, like `Europe/Kiev`, has been superseded by an	 * updated one, like `Europe/Kyiv`, as a rule of thumb, the **old** timezone name should be used	 * in the "translation" to allow for the default timezone setting to be PHP cross-version compatible,	 * as old timezone names will be recognized in new PHP versions, while new timezone names cannot	 * be recognized in old PHP versions.	 *	 * To verify which timezone strings are available in the _oldest_ PHP version supported, you can	 * use https://3v4l.org/6YQAt#v5.6.20 and replace the "BR" (Brazil) in the code line with the	 * country code for which you want to look up the supported timezone names.	 */	$offset_or_tz = _x( '0', 'default GMT offset or timezone string' );	if ( is_numeric( $offset_or_tz ) ) {		$gmt_offset = $offset_or_tz;	} elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ), true ) ) {		$timezone_string = $offset_or_tz;	} 	$defaults = array(		'siteurl'                         => $guessurl,		'home'                            => $guessurl,		'blogname'                        => __( 'My Site' ),		'blogdescription'                 => '',		'users_can_register'              => 0,		'admin_email'                     => '[email protected]',		/* translators: Default start of the week. 0 = Sunday, 1 = Monday. */		'start_of_week'                   => _x( '1', 'start of week' ),		'use_balanceTags'                 => 0,		'use_smilies'                     => 1,		'require_name_email'              => 1,		'comments_notify'                 => 1,		'posts_per_rss'                   => 10,		'rss_use_excerpt'                 => 0,		'mailserver_url'                  => 'mail.example.com',		'mailserver_login'                => '[email protected]',		'mailserver_pass'                 => '',		'mailserver_port'                 => 110,		'default_category'                => 1,		'default_comment_status'          => 'open',		'default_ping_status'             => 'open',		'default_pingback_flag'           => 1,		'posts_per_page'                  => 10,		/* translators: Default date format, see https://www.php.net/manual/datetime.format.php */		'date_format'                     => __( 'F j, Y' ),		/* translators: Default time format, see https://www.php.net/manual/datetime.format.php */		'time_format'                     => __( 'g:i a' ),		/* translators: Links last updated date format, see https://www.php.net/manual/datetime.format.php */		'links_updated_date_format'       => __( 'F j, Y g:i a' ),		'comment_moderation'              => 0,

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.

5.1.0
The $options parameter has been added.from the docblock
1.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-admin/includes/schema.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.