WP_Customize_Manager::__construct( array $args = array() )
- Since
- 3.4.0, 4.7.0
- Source
wp-includes/class-wp-customize-manager.php:262
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
$argsarrayoptional- Args.Default:
array()$changeset_uuidnull|string|falseChangeset UUID, thepost_namefor the customize_changeset post containing the customized state. Defaults tonullresulting in a UUID to be immediately generated. Iffalseis provided, then then the changeset UUID will be determined duringafter_setup_theme: when thecustomize_changeset_branchingfilter returns false, then the default UUID will be that of the most recentcustomize_changesetpost that has a status other than 'auto-draft', 'publish', or 'trash'. Otherwise, if changeset branching is enabled, then a random UUID will be used.$themestringTheme to be previewed (for theme switch). Defaults to customize_theme or theme query params.$messenger_channelstringMessenger channel. Defaults to customize_messenger_channel query param.$settings_previewedboolIf settings should be previewed. Defaults to true.$branchingboolIf changeset branching is allowed; otherwise, changesets are linear. Defaults to true.$autosavedboolIf data from a changeset's autosaved revision should be loaded if it exists. Defaults to false.
Performance profile
How much work a call to WP_Customize_Manager::__construct() 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
- 407–456
- Plugin surface
- 1 hook
- Called by
- 2
Reads stored settings via get_option(), cached per request but not free on a cold cache.
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 490.
Third-party callbacks on 'customize_loaded_components' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()one call below WP_Customize_Manager::__construct()
Further down the call graph this can also reach cache, serialize, 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 · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Customize_Manager::__construct() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
isset($args) && !current_user_can() | 407–443 | array_fill_keys(), array_merge(), wp_is_block_theme(), get_stylesheet(), validate_file(), wp_get_theme(), apply_filters(), remove_action(), remove_action(), remove_action(), remove_action(), current_user_can(), current_user_can() |
isset($args) && current_user_can() | 410–446 | array_fill_keys(), array_merge(), wp_is_block_theme(), get_stylesheet(), validate_file(), wp_get_theme(), apply_filters(), remove_action(), remove_action(), remove_action(), remove_action(), current_user_can(), add_action() |
isset($args) | 414–450 | array_fill_keys(), array_merge(), wp_is_block_theme(), get_stylesheet(), validate_file(), wp_get_theme(), apply_filters(), remove_action(), remove_action(), remove_action(), remove_action(), current_user_can(), current_user_can(), add_action() |
isset($value) && !current_user_can() | 421–449 | array_fill_keys(), array_merge(), wp_unslash(), sanitize_key(), wp_is_block_theme(), get_stylesheet(), validate_file(), wp_get_theme(), apply_filters(), remove_action(), remove_action(), remove_action(), remove_action(), current_user_can(), current_user_can() |
isset($value) && current_user_can() | 424–452 | array_fill_keys(), array_merge(), wp_unslash(), sanitize_key(), wp_is_block_theme(), get_stylesheet(), validate_file(), wp_get_theme(), apply_filters(), remove_action(), remove_action(), remove_action(), remove_action(), current_user_can(), add_action() |
isset($value) | 428–456 | array_fill_keys(), array_merge(), wp_unslash(), sanitize_key(), wp_is_block_theme(), get_stylesheet(), validate_file(), wp_get_theme(), apply_filters(), remove_action(), remove_action(), remove_action(), remove_action(), current_user_can(), current_user_can(), add_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 | 490 | 407–456 | 15 | |
| 8.5 | 490 | 407–456 | 15 | |
| 8.4 | 490 | 407–456 | 15 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 496 | 413–462 | 15 | |
| 8.2 | 496 | 413–462 | 15 | |
| 8.1 | 496 | 413–462 | 15 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 497 | 413–462 | 15 |
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 WP_Customize_Manager::__construct() runs, in this order:
- apply_filters( customize_loaded_components )filterline 359 (+97 into the body)
Filters the core Customizer components to load.
Uses · 15
- wp_generate_uuid4()Generates a random UUID (version 4).
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- sanitize_key()Sanitizes a string key.
- wp_is_block_theme()Returns whether the active theme is a block-based theme or not.
- get_stylesheet()Retrieves name of the current stylesheet.
- wp_get_theme()Gets a WP_Theme object for a theme.
- validate_file()Validates a file name and path against an allowed set of rules.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- add_action()Adds a callback function to an action hook.
- remove_action()Removes a callback function from an action hook.
- add_filter()Adds a callback function to a filter hook.
- current_user_can()Returns whether the current user has the specified capability.
Show all 15
- WP_Customize_Selective_Refresh::__construct()Plugin bootstrap for Partial Refresh functionality.
- WP_Customize_Widgets::__construct()Initial loader.
- WP_Customize_Nav_Menus::__construct()Constructor.
Used by · 2
- _wp_customize_include()Includes and instantiates the WP_Customize_Manager class.
- _wp_customize_publish_changeset()Publishes a snapshot's changes.
Source code
public function __construct( $args = array() ) { $args = array_merge( array_fill_keys( array( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed', 'autosaved', 'branching' ), null ), $args ); // Note that the UUID format will be validated in the setup_theme() method. if ( ! isset( $args['changeset_uuid'] ) ) { $args['changeset_uuid'] = wp_generate_uuid4(); } /* * The theme and messenger_channel should be supplied via $args, * but they are also looked at in the $_REQUEST global here for back-compat. */ if ( ! isset( $args['theme'] ) ) { if ( isset( $_REQUEST['customize_theme'] ) ) { $args['theme'] = wp_unslash( $_REQUEST['customize_theme'] ); } elseif ( isset( $_REQUEST['theme'] ) ) { // Deprecated. $args['theme'] = wp_unslash( $_REQUEST['theme'] ); } } if ( ! isset( $args['messenger_channel'] ) && isset( $_REQUEST['customize_messenger_channel'] ) ) { $args['messenger_channel'] = sanitize_key( wp_unslash( $_REQUEST['customize_messenger_channel'] ) ); } // Do not load 'widgets' component if a block theme is activated. if ( ! wp_is_block_theme() ) { $this->components[] = 'widgets'; } $this->original_stylesheet = get_stylesheet(); $this->theme = wp_get_theme( 0 === validate_file( $args['theme'] ) ? $args['theme'] : null ); $this->messenger_channel = $args['messenger_channel']; $this->_changeset_uuid = $args['changeset_uuid']; foreach ( array( 'settings_previewed', 'autosaved', 'branching' ) as $key ) { if ( isset( $args[ $key ] ) ) { $this->$key = (bool) $args[ $key ]; } } require_once ABSPATH . WPINC . '/class-wp-customize-setting.php'; require_once ABSPATH . WPINC . '/class-wp-customize-panel.php'; require_once ABSPATH . WPINC . '/class-wp-customize-section.php'; require_once ABSPATH . WPINC . '/class-wp-customize-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-color-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-media-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-upload-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-image-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-background-image-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-background-position-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-cropped-image-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-site-icon-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-header-image-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-theme-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-code-editor-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-widget-area-customize-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-widget-form-customize-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-location-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-name-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-locations-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-auto-add-control.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menus-panel.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-themes-panel.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-themes-section.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-sidebar-section.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-section.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-custom-css-setting.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-filter-setting.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-header-image-setting.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-background-image-setting.php'; require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-setting.php';Changelog
Introduced in 3.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$args parameter.from the docblockAbout 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.