WP_Customize_Manager::add_setting( WP_Customize_Setting|string $id, array $args = array() )

Add a customize setting.



(Required) Customize Setting object, or ID.


(Optional) Array of properties for the new WP_Customize_Setting.

  • 'type'
    (string) Type of the setting. Default 'theme_mod'. Default 160.
  • 'capability'
    (string) Capability required for the setting. Default 'edit_theme_options'
  • 'theme_supports'
    (string|array) Theme features required to support the panel. Default is none.
  • 'default'
    (string) Default value for the setting. Default is empty string.
  • 'transport'
    (string) Options for rendering the live preview of changes in Theme Customizer. Using 'refresh' makes the change visible by reloading the whole preview. Using 'postMessage' allows a custom JavaScript to handle live changes. @link <a href="https://developer.wordpress.org/themes/customize-api">https://developer.wordpress.org/themes/customize-api</a> Default is 'refresh'
  • 'validate_callback'
    (callable) Server-side validation callback for the setting's value.
  • 'sanitize_callback'
    (callable) Callback to filter a Customize setting value in un-slashed form.
  • 'sanitize_js_callback'
    (callable) Callback to convert a Customize PHP setting value to a value that is JSON serializable.
  • 'dirty'
    (bool) Whether or not the setting is initially dirty when created.

Default value: array()


(WP_Customize_Setting) The instance of the setting that was added.


File: wp-includes/class-wp-customize-manager.php

	public function add_setting( $id, $args = array() ) {
		if ( $id instanceof WP_Customize_Setting ) {
			$setting = $id;
		} else {
			$class = 'WP_Customize_Setting';

			/** This filter is documented in wp-includes/class-wp-customize-manager.php */
			$args = apply_filters( 'customize_dynamic_setting_args', $args, $id );

			/** This filter is documented in wp-includes/class-wp-customize-manager.php */
			$class = apply_filters( 'customize_dynamic_setting_class', $class, $id, $args );

			$setting = new $class( $this, $id, $args );

		$this->settings[ $setting->id ] = $setting;
		return $setting;


Version Description
WP-4.5.0 Return added WP_Customize_Setting instance.
WP-3.4.0 Introduced.