wppaste
WordPress

WP_Customize_Manager::add_dynamic_settings( array $setting_ids ): array

Since
4.2.0
Source
wp-includes/class-wp-customize-manager.php:3814
Registers any dynamically-created settings, such as those from $_POST['customized'] that have no corresponding setting created.

Description

This is a mechanism to "wake up" settings that have been dynamically created on the front end and have been sent to WordPress in $_POST['customized']. When WP loads, the dynamically-created settings then will get created and previewed even though they are not directly created statically with code.

Compatibility

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

$setting_idsarray
The setting IDs to add.

Return value

array
The WP_Customize_Setting objects added.

Performance profile

How much work a call to WP_Customize_Manager::add_dynamic_settings() 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
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

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

Instructions
5–6

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

Plugin surface
2 hooks

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

Called by
3

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

What it touches

  • hookthird-party callbacksapply_filters()called directly

What one call costs · 1 distinct outcome

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

WhenInstructionsCalls it makes
always5–6none

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 41 instructions, 5–6 executed per call, 4 branches. The work does not change between versions.

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

2 hooks fire while WP_Customize_Manager::add_dynamic_settings() runs, in this order:

  1. apply_filters( customize_dynamic_setting_args )filterline 3837 (+23 into the body)

    Filters a dynamic setting's constructor args.

  2. apply_filters( customize_dynamic_setting_class )filterline 3851 (+37 into the body)

    Allow non-statically created settings to be constructed with custom WP_Customize_Setting subclass.

Uses · 3

Used by · 3

Source code

	public function add_dynamic_settings( $setting_ids ) {		$new_settings = array();		foreach ( $setting_ids as $setting_id ) {			// Skip settings already created.			if ( $this->get_setting( $setting_id ) ) {				continue;			} 			$setting_args  = false;			$setting_class = 'WP_Customize_Setting'; 			/**			 * Filters a dynamic setting's constructor args.			 *			 * For a dynamic setting to be registered, this filter must be employed			 * to override the default false value with an array of args to pass to			 * the WP_Customize_Setting constructor.			 *			 * @since 4.2.0			 *			 * @param false|array $setting_args The arguments to the WP_Customize_Setting constructor.			 * @param string      $setting_id   ID for dynamic setting, usually coming from `$_POST['customized']`.			 */			$setting_args = apply_filters( 'customize_dynamic_setting_args', $setting_args, $setting_id );			if ( false === $setting_args ) {				continue;			} 			/**			 * Allow non-statically created settings to be constructed with custom WP_Customize_Setting subclass.			 *			 * @since 4.2.0			 *			 * @param string $setting_class WP_Customize_Setting or a subclass.			 * @param string $setting_id    ID for dynamic setting, usually coming from `$_POST['customized']`.			 * @param array  $setting_args  WP_Customize_Setting or a subclass.			 */			$setting_class = apply_filters( 'customize_dynamic_setting_class', $setting_class, $setting_id, $setting_args ); 			$setting = new $setting_class( $this, $setting_id, $setting_args ); 			$this->add_setting( $setting );			$new_settings[] = $setting;		}		return $new_settings;	}

Changelog

Introduced in 4.2.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 6.8.8 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.