WP_Customize_Manager::import_theme_starter_content( array $starter_content = array() )
- Since
- 4.7.0
- Source
wp-includes/class-wp-customize-manager.php:1203
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
- Scaling
- Scales with input
- Instructions
- 95–141
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 907.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- optionoption read or write
get_option()called directly - querycontent query
get_post()called directly - serializeserialisation
maybe_serialize()called directly - hookthird-party callbacks
apply_filters()one call below WP_Customize_Manager::import_theme_starter_content() - cacheobject cache
wp_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.
| When | Instructions | Calls 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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 907 | 95–141 | 121 | |
| 8.5 | 907 | 95–141 | 121 | |
| 8.4 | 907 | 95–141 | 121 | 11 fewer instructions than PHP 8.3 |
| 8.3 | 918 | 95–141 | 121 | |
| 8.2 | 918 | 95–141 | 121 | 1 more instruction than PHP 8.1 |
| 8.1 | 917 | 95–141 | 121 | 3 fewer instructions than PHP 7.4 |
| 7.4 | 920 | 95–141 | 121 |
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
- get_theme_starter_content()Expands a theme's starter content configuration using core-provided data.
- get_post_status()Retrieves the post status based on the post ID.
- get_option()Retrieves an option value based on an option name.
- sanitize_title()Sanitizes a string into a slug, which can be used in URLs or HTML attributes.
- wp_list_pluck()Plucks a certain field out of each object or array in an array.
- get_post_meta()Retrieves a post meta field for the given post ID.
- get_post_stati()Gets a list of post statuses.
- get_attached_file()Retrieves attached file path based on attachment ID.
- wp_generate_attachment_metadata()Generates attachment meta data and create image sub-sizes for images.
- wp_update_attachment_metadata()Updates metadata for an attachment.
- update_post_meta()Updates a post meta field based on the given post ID.
- wp_tempnam()Returns a filename of a temporary unique file.
Show all 31
- wp_basename()i18n-friendly version of basename().
- wp_array_slice_assoc()Extracts a slice of an array, given a list of keys.
- media_handle_sideload()Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload().
- is_wp_error()Checks whether the given variable is a WordPress Error.
- get_post()Retrieves post data given a post ID or post object.
- maybe_serialize()Serializes data, if needed.
- is_serialized()Checks value to find if it was serialized.
- maybe_unserialize()Unserializes data only if it was serialized.
- wp_get_attachment_metadata()Retrieves attachment metadata for attachment ID.
- wp_get_attachment_url()Retrieves the URL for an attachment.
- did_action()Retrieves the number of times an action has been fired during the current request.
- add_action()Adds a callback function to an action hook.
- WP_Customize_Manager::changeset_post_id()Gets the changeset post ID for the loaded changeset.
- WP_Customize_Manager::get_changeset_post_data()Gets the data stored in a changeset post.
- WP_Customize_Manager::set_post_value()Overrides a setting's value in the current customized state.
- WP_Customize_Manager::prepare_starter_content_attachments()Prepares starter content attachments.
- WP_Query::__construct()Constructor.
- WP_Customize_Manager::get_stylesheet()Retrieves the stylesheet name of the previewed theme.
- WP_Customize_Manager::_save_starter_content_changeset()Saves starter content changeset.
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.
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.