WP_Customize_Control::__construct()publicWP 3.4.0

Constructor.

Supplied $args override class property defaults.

If $args['settings'] is not defined, use the $id as the setting ID.

Метод класса: WP_Customize_Control{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$WP_Customize_Control = new WP_Customize_Control();
$WP_Customize_Control->__construct( $manager, $id, $args );
$manager(WP_Customize_Manager) (обязательный)
Customizer bootstrap instance.
$id(строка) (обязательный)
Control ID.
$args(массив)

Array of properties for the new Control object.

По умолчанию: empty array

  • instance_number(int)
    Order in which this instance was created in relation to other instances.

  • manager(WP_Customize_Manager)
    Customizer bootstrap instance.

  • id(строка)
    Control ID.

  • settings(массив)
    All settings tied to the control. If undefined, $id will be used.

  • setting(строка)
    The primary setting for the control (if there is one).
    По умолчанию: 'default'

  • capability(строка)
    Capability required to use this control. Normally this is empty and the capability is derived from $settings.

  • priority(int)
    Order priority to load the control.
    По умолчанию: 10

  • section(строка)
    Section the control belongs to.
    По умолчанию: ''

  • label(строка)
    Label for the control.
    По умолчанию: ''

  • description(строка)
    Description for the control.
    По умолчанию: ''

  • choices(массив)
    List of choices for 'radio' or 'select' type controls, where values are the keys, and labels are the values.
    По умолчанию: empty array

  • input_attrs(массив)
    List of custom input attributes for control output, where attribute names are the keys and values are the values. Not used for 'checkbox', 'radio', 'select', 'textarea', or 'dropdown-pages' control types.
    По умолчанию: empty array

  • allow_addition(true|false)
    Show UI for adding new content, currently only used for the dropdown-pages control.
    По умолчанию: false

  • json(массив)
    Deprecated. Use WP_Customize_Control::json() instead.

  • type(строка)
    Control type. Core controls include 'text', 'checkbox', 'textarea', 'radio', 'select', and 'dropdown-pages'. Additional input types such as 'email', 'url', 'number', 'hidden', and 'date' are supported implicitly.
    По умолчанию: 'text'

  • active_callback(callable)
    Active callback.

Список изменений

С версии 3.4.0 Введена.

Код WP_Customize_Control::__construct() WP 6.5.2

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;
	if ( empty( $this->active_callback ) ) {
		$this->active_callback = array( $this, 'active_callback' );
	}
	self::$instance_count += 1;
	$this->instance_number = self::$instance_count;

	// Process settings.
	if ( ! isset( $this->settings ) ) {
		$this->settings = $id;
	}

	$settings = array();
	if ( is_array( $this->settings ) ) {
		foreach ( $this->settings as $key => $setting ) {
			$settings[ $key ] = $this->manager->get_setting( $setting );
		}
	} elseif ( is_string( $this->settings ) ) {
		$this->setting       = $this->manager->get_setting( $this->settings );
		$settings['default'] = $this->setting;
	}
	$this->settings = $settings;
}