wppaste
WordPress

WP_Customize_Manager::import_theme_starter_content( array $starter_content = array() )

Since
4.7.0
Source
wp-includes/class-wp-customize-manager.php:1203
Imports theme starter content into the customized state.

Compatibility

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

$starter_contentarrayoptional
Starter content. Defaults to get_theme_starter_content().Default: array()

Performance profile

How much work a call to WP_Customize_Manager::import_theme_starter_content() 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_post().

Scaling
Scales with input

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

Instructions
95–141

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

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
  • querycontent queryget_post()called directly
  • serializeserialisationmaybe_serialize()called directly
  • hookthird-party callbacksapply_filters()one call below WP_Customize_Manager::import_theme_starter_content()
  • cacheobject cachewp_cache_get()one call below WP_Customize_Manager::import_theme_starter_content()

Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 21 distinct outcomes

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

WhenInstructionsCalls it makes
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && empty($value) && array_keys() && empty($starter_content_auto_draft_post_ids) && empty($all_post_slugs) && empty($attachments) && empty($posts)95–100->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($starter_content_auto_draft_post_ids) && empty($all_post_slugs) && empty($attachments) && empty($posts) && did_action()101–106->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), did_action(), ->_save_starter_content_changeset()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && empty($value) && array_keys() && empty($starter_content_auto_draft_post_ids) && empty($all_post_slugs) && !empty($attachments) && empty($posts)106–111->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_values(), array_merge()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($starter_content_auto_draft_post_ids) && empty($all_post_slugs) && empty($attachments) && empty($posts) && !did_action()107–112->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), did_action()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && empty($value) && array_keys() && empty($starter_content_auto_draft_post_ids) && empty($all_post_slugs) && empty($attachments) && !empty($posts)109–115->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_keys(), wp_list_pluck(), array_merge()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($all_post_slugs) && empty($attachments) && empty($posts)111–114->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_values(), array_unique(), ->set_post_value()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($starter_content_auto_draft_post_ids) && empty($all_post_slugs) && !empty($attachments) && empty($posts) && did_action()112–117->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_values(), array_merge(), did_action(), ->_save_starter_content_changeset()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($starter_content_auto_draft_post_ids) && empty($all_post_slugs) && empty($attachments) && !empty($posts) && did_action()115–121->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_keys(), wp_list_pluck(), array_merge(), did_action(), ->_save_starter_content_changeset()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($all_post_slugs) && empty($attachments) && empty($posts) && did_action()117–120->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_values(), array_unique(), ->set_post_value(), did_action(), ->_save_starter_content_changeset()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($starter_content_auto_draft_post_ids) && empty($all_post_slugs) && !empty($attachments) && empty($posts) && !did_action()118–123->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_values(), array_merge(), did_action()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && empty($value) && array_keys() && empty($starter_content_auto_draft_post_ids) && empty($all_post_slugs) && !empty($attachments) && !empty($posts)120–123->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_values(), array_merge(), array_keys(), wp_list_pluck(), array_merge()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($starter_content_auto_draft_post_ids) && empty($all_post_slugs) && empty($attachments) && !empty($posts) && !did_action()121–127->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_keys(), wp_list_pluck(), array_merge(), did_action()
9 further outcomes, up to 141 instructions
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($all_post_slugs) && !empty($attachments) && empty($posts)122–125->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_values(), array_merge(), array_values(), array_unique(), ->set_post_value()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($all_post_slugs) && empty($attachments) && empty($posts) && !did_action()123–126->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_values(), array_unique(), ->set_post_value(), did_action()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($all_post_slugs) && empty($attachments) && !empty($posts)125–129->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_keys(), wp_list_pluck(), array_merge(), array_values(), array_unique(), ->set_post_value()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($starter_content_auto_draft_post_ids) && empty($all_post_slugs) && !empty($attachments) && !empty($posts) && did_action()126–129->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_values(), array_merge(), array_keys(), wp_list_pluck(), array_merge(), did_action(), ->_save_starter_content_changeset()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($all_post_slugs) && !empty($attachments) && empty($posts) && did_action()128–131->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_values(), array_merge(), array_values(), array_unique(), ->set_post_value(), did_action(), ->_save_starter_content_changeset()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($all_post_slugs) && empty($attachments) && !empty($posts) && did_action()131–135->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_keys(), wp_list_pluck(), array_merge(), array_values(), array_unique(), ->set_post_value(), did_action(), ->_save_starter_content_changeset()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($starter_content_auto_draft_post_ids) && empty($all_post_slugs) && !empty($attachments) && !empty($posts) && !did_action()132–135->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_values(), array_merge(), array_keys(), wp_list_pluck(), array_merge(), did_action()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($all_post_slugs) && !empty($attachments) && empty($posts) && !did_action()134–137->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_values(), array_merge(), array_values(), array_unique(), ->set_post_value(), did_action()
!empty($starter_content) && !->changeset_post_id() && !isset($starter_content) && !$starter_content && array_keys() && empty($all_post_slugs) && empty($attachments) && !empty($posts) && !did_action()137–141->changeset_post_id(), ->prepare_starter_content_attachments(), array_keys(), wp_list_pluck(), wp_list_pluck(), array_merge(), wp_list_pluck(), array_merge(), array_filter(), array_keys(), wp_list_pluck(), array_merge(), array_values(), array_unique(), ->set_post_value(), did_action()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev90795–141121
8.590795–141121
8.490795–14112111 fewer instructions than PHP 8.3
8.391895–141121
8.291895–1411211 more instruction than PHP 8.1
8.191795–1411213 fewer instructions than PHP 7.4
7.492095–141121

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

Show all 31

Source code

	public function import_theme_starter_content( $starter_content = array() ) {		if ( empty( $starter_content ) ) {			$starter_content = get_theme_starter_content();		} 		$changeset_data = array();		if ( $this->changeset_post_id() ) {			/*			 * Don't re-import starter content into a changeset saved persistently.			 * This will need to be revisited in the future once theme switching			 * is allowed with drafted/scheduled changesets, since switching to			 * another theme could result in more starter content being applied.			 * However, when doing an explicit save it is currently possible for			 * nav menus and nav menu items specifically to lose their starter_content			 * flags, thus resulting in duplicates being created since they fail			 * to get re-used. See #40146.			 */			if ( 'auto-draft' !== get_post_status( $this->changeset_post_id() ) ) {				return;			} 			$changeset_data = $this->get_changeset_post_data( $this->changeset_post_id() );		} 		$sidebars_widgets = isset( $starter_content['widgets'] ) && ! empty( $this->widgets ) ? $starter_content['widgets'] : array();		$attachments      = isset( $starter_content['attachments'] ) && ! empty( $this->nav_menus ) ? $starter_content['attachments'] : array();		$posts            = isset( $starter_content['posts'] ) && ! empty( $this->nav_menus ) ? $starter_content['posts'] : array();		$options          = $starter_content['options'] ?? array();		$nav_menus        = isset( $starter_content['nav_menus'] ) && ! empty( $this->nav_menus ) ? $starter_content['nav_menus'] : array();		$theme_mods       = $starter_content['theme_mods'] ?? array(); 		// Widgets.		$max_widget_numbers = array();		foreach ( $sidebars_widgets as $sidebar_id => $widgets ) {			$sidebar_widget_ids = array();			foreach ( $widgets as $widget ) {				list( $id_base, $instance ) = $widget; 				if ( ! isset( $max_widget_numbers[ $id_base ] ) ) { 					// When $settings is an array-like object, get an intrinsic array for use with array_keys().					$settings = get_option( "widget_{$id_base}", array() );					if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) {						$settings = $settings->getArrayCopy();					} 					unset( $settings['_multiwidget'] ); 					// Find the max widget number for this type.					$widget_numbers = array_keys( $settings );					if ( count( $widget_numbers ) > 0 ) {						$widget_numbers[]               = 1;						$max_widget_numbers[ $id_base ] = max( ...$widget_numbers );					} else {						$max_widget_numbers[ $id_base ] = 1;					}				}				$max_widget_numbers[ $id_base ] += 1; 				$widget_id  = sprintf( '%s-%d', $id_base, $max_widget_numbers[ $id_base ] );				$setting_id = sprintf( 'widget_%s[%d]', $id_base, $max_widget_numbers[ $id_base ] ); 				$setting_value = $this->widgets->sanitize_widget_js_instance( $instance );				if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) {					$this->set_post_value( $setting_id, $setting_value );					$this->pending_starter_content_settings_ids[] = $setting_id;				}				$sidebar_widget_ids[] = $widget_id;			} 			$setting_id = sprintf( 'sidebars_widgets[%s]', $sidebar_id );			if ( empty( $changeset_data[ $setting_id ] ) || ! empty( $changeset_data[ $setting_id ]['starter_content'] ) ) {				$this->set_post_value( $setting_id, $sidebar_widget_ids );				$this->pending_starter_content_settings_ids[] = $setting_id;			}		} 		$starter_content_auto_draft_post_ids = array();		if ( ! empty( $changeset_data['nav_menus_created_posts']['value'] ) ) {			$starter_content_auto_draft_post_ids = array_merge( $starter_content_auto_draft_post_ids, $changeset_data['nav_menus_created_posts']['value'] );

Changelog

Introduced in 4.7.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.1.0 tag, from src/wp-includes/class-wp-customize-manager.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.