Title: WP_Customize_Setting::__construct
Published: April 25, 2014
Last modified: April 28, 2025

---

# WP_Customize_Setting::__construct( WP_Customize_Manager $manager, string $id, array $args = array() )

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#wp--skip-link--target)

Constructor.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#description)󠁿

Any supplied $args override class property defaults.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#parameters)󠁿

 `$manager`[WP_Customize_Manager](https://developer.wordpress.org/reference/classes/wp_customize_manager/)
required

Customizer bootstrap instance.

`$id`stringrequired

A specific ID of the setting.
 Can be a theme mod or option name.

`$args`arrayoptional

Array of properties for the new Setting object.

 * `type` string
 * Type of the setting. Default `'theme_mod'`.
 * `capability` string
 * Capability required for the setting. Default `'edit_theme_options'`
 * `theme_supports` string|string[]
 * 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 Customizer.
    Using `'refresh'`
   makes the change visible by reloading the whole preview. Using `'postMessage'`
   allows a custom JavaScript to handle live changes. 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:`array()`

## 󠀁[Source](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#source)󠁿

    ```php
    public function __construct( $manager, $id, $args = array() ) {
    	$keys = array_keys( get_object_vars( $this ) );
    	foreach ( $keys as $key ) {
    		if ( isset( $args[ $key ] ) ) {
    			$this->$key = $args[ $key ];
    		}
    	}

    	$this->manager = $manager;
    	$this->id      = $id;

    	// Parse the ID for array keys.
    	$this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) );
    	$this->id_data['base'] = array_shift( $this->id_data['keys'] );

    	// Rebuild the ID.
    	$this->id = $this->id_data['base'];
    	if ( ! empty( $this->id_data['keys'] ) ) {
    		$this->id .= '[' . implode( '][', $this->id_data['keys'] ) . ']';
    	}

    	if ( $this->validate_callback ) {
    		add_filter( "customize_validate_{$this->id}", $this->validate_callback, 10, 3 );
    	}
    	if ( $this->sanitize_callback ) {
    		add_filter( "customize_sanitize_{$this->id}", $this->sanitize_callback, 10, 2 );
    	}
    	if ( $this->sanitize_js_callback ) {
    		add_filter( "customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2 );
    	}

    	if ( 'option' === $this->type || 'theme_mod' === $this->type ) {
    		// Other setting types can opt-in to aggregate multidimensional explicitly.
    		$this->aggregate_multidimensional();

    		// Allow option settings to indicate whether they should be autoloaded.
    		if ( 'option' === $this->type && isset( $args['autoload'] ) ) {
    			self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload'] = $args['autoload'];
    		}
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-customize-setting.php#L183)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-customize-setting.php#L183-L223)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Customize_Setting::aggregate_multidimensional()](https://developer.wordpress.org/reference/classes/wp_customize_setting/aggregate_multidimensional/)`wp-includes/class-wp-customize-setting.php` |

Set up the setting for aggregated multidimensional values.

  | 
| [add_filter()](https://developer.wordpress.org/reference/functions/add_filter/)`wp-includes/plugin.php` |

Adds a callback function to a filter hook.

  |

| Used by | Description | 
| [WP_Customize_Custom_CSS_Setting::__construct()](https://developer.wordpress.org/reference/classes/wp_customize_custom_css_setting/__construct/)`wp-includes/customize/class-wp-customize-custom-css-setting.php` |

[WP_Customize_Custom_CSS_Setting](https://developer.wordpress.org/reference/classes/wp_customize_custom_css_setting/) constructor.

  | 
| [WP_Customize_Nav_Menu_Setting::__construct()](https://developer.wordpress.org/reference/classes/wp_customize_nav_menu_setting/__construct/)`wp-includes/customize/class-wp-customize-nav-menu-setting.php` |

Constructor.

  | 
| [WP_Customize_Nav_Menu_Item_Setting::__construct()](https://developer.wordpress.org/reference/classes/wp_customize_nav_menu_item_setting/__construct/)`wp-includes/customize/class-wp-customize-nav-menu-item-setting.php` |

Constructor.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#comment-content-5885)
 2.    [Andrea Alba](https://profiles.wordpress.org/subjuliodesign/)  [  4 years ago  ](https://developer.wordpress.org/reference/classes/wp_customize_setting/__construct/#comment-5885)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_customize_setting%2F__construct%2F%23comment-5885)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_customize_setting%2F__construct%2F%23comment-5885)
 4.  Documentation for [Setting Validation and Notifications](https://wp.me/p2AvED-4PM)
 5.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_customize_setting%2F__construct%2F%3Freplytocom%3D5885%23feedback-editor-5885)
 6.   [Skip to note 4 content](https://developer.wordpress.org/reference/classes/WP_Customize_Setting/__construct/?output_format=md#comment-content-4793)
 7.    [Prakash Rao](https://profiles.wordpress.org/prakashrao/)  [  5 years ago  ](https://developer.wordpress.org/reference/classes/wp_customize_setting/__construct/#comment-4793)
 8.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_customize_setting%2F__construct%2F%23comment-4793)
     Vote results for this note: -1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_customize_setting%2F__construct%2F%23comment-4793)
 9.  WordPress Appearance -> Customize section follows this structure: Panels -> Sections-
     > Settings (which can have [controls](https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/))
 10. We can add our custom Panels or We can add our sections in existing panels too.
     Below is the code to add a section in WooCommerce Panel, created default by WooCommerce.
 11.     ```php
         $wp_customize->add_section(
                 'WPDOCS_SECTION_ID',
                 array(
                   'title'    => __( 'WPDOCS_SECTION_NAME', 'textdomain' ),
                   'priority' => 20,
                   'panel'    => 'woocommerce',
                 )
               );
         ```
     
 12. Note: `WPDOCS_SECTION_ID` must be unique
      `WPDOCS_SECTION_NAME` as per your requirement
 13. Under each section you can add multiple settings. Code to add setting is:
 14.     ```php
         $wp_customize->add_setting(
                 'WPDOCS_SETTING_ID',
                 array(
                   'default'              => 'no',
                   'type'                 => 'option',
                   'capability'           => 'manage_woocommerce',
                   'sanitize_callback'    => 'wc_bool_to_string',
                   'sanitize_js_callback' => 'wc_string_to_bool',
                 )
               );
         ```
     
 15. Note: `WPDOCS_SETTING_ID` must be unique
 16. `$wp_customize->add_setting` basically creates a setting section. You will need
     the input controls under each setting section. [Controls](https://developer.wordpress.org/reference/classes/wp_customize_control/__construct/)
     can be added under settings.
 17. code:
 18.     ```php
         $wp_customize->add_control(
                 'WPDOCS_SETTING_ID',
                 array(
                   'label'    => __( 'WPDOCS_SETTING_LABEL', 'textdomain' ),
                   'description' => __( 'WPDOCS_SETTING_DESC', 'textdomain' ), 
                   'section'  => 'WPDOCS_SECTION_ID',
                   'settings' => 'WPDOCS_SETTING_ID',
                   'type'     => 'checkbox',
                 )
               ); 
         ```
     
 19. Note: `WPDOCS_SECTION_ID` and `WPDOCS_SETTING_ID` are the ones we added above.
 20.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_customize_setting%2F__construct%2F%3Freplytocom%3D4793%23feedback-editor-4793)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_customize_setting%2F__construct%2F)
before being able to contribute a note or feedback.