WP_Customize_Manager::add_control( WP_Customize_Control|string $id, array $args = array() )

Add a customize control.


Parameters

$id

(WP_Customize_Control|string) (Required) Customize Control object, or ID.

$args

(array) (Optional) Array of properties for the new Control object.

  • 'settings'
    (array) All settings tied to the control. If undefined, defaults to $setting. IDs in the array correspond to the ID of a registered WP_Customize_Setting.
  • 'setting'
    (string) The primary setting for the control (if there is one). Default is 'default'.
  • 'capability'
    (string) Capability required to use this control. Normally derived from $settings.
  • 'priority'
    (int) Order priority to load the control. Default 10.
  • 'section'
    (string) The section this control belongs to.
  • 'label'
    (string) Label for the control.
  • 'description'
    (string) Description for the control.
  • 'choices'
    (array) List of choices for 'radio' or 'select' type controls, where values are the keys, and labels are the values.
  • 'input_attrs'
    (array) List of custom input attributes for control output, where attribute names are the keys and values are the values.
  • 'allow_addition'
    (bool) Show UI for adding new content, currently only used for the dropdown-pages control. Default false.
  • 'type'
    (string) The type of the control. Default 'text'.
  • 'active_callback'
    (callback) Active callback.

Default value: array()


Return

(WP_Customize_Control) The instance of the control that was added.


Source

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

	public function add_control( $id, $args = array() ) {
		if ( $id instanceof WP_Customize_Control ) {
			$control = $id;
		} else {
			$control = new WP_Customize_Control( $this, $id, $args );
		}

		$this->controls[ $control->id ] = $control;
		return $control;
	}


Changelog

Changelog
Version Description
WP-4.5.0 Return added WP_Customize_Control instance.
WP-3.4.0 Introduced.