WP_Customize_Manager::import_theme_starter_content( array $starter_content = array() )
- Since
- 4.7.0
- Source
wp-includes/class-wp-customize-manager.php:1202
Imports theme starter content into the customized state.
Parameters
$starter_contentarrayoptional- Starter content. Defaults to
get_theme_starter_content().Default:array()
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
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'] );History
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.0.4 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.