__construct() public method

Supplied $args override class property defaults. If $args['settings'] is not defined, use the $id as the setting ID.
Since: 2.3.5
public __construct ( WP_Customize_Manager $manager, string $id, array $args = [] )
$manager WP_Customize_Manager Customizer bootstrap instance.
$id string Control ID.
$args array { Optional. Arguments to override class property defaults. @type int $instance_number Order in which this instance was created in relation to other instances. @type WP_Customize_Manager $manager Customizer bootstrap instance. @type string $id Control ID. @type array $settings All settings tied to the control. If undefined, `$id` will be used. @type string $setting The primary setting for the control (if there is one). Default 'default'. @type int $priority Order priority to load the control. Default 10. @type string $section Section the control belongs to. Default empty. @type string $label Label for the control. Default empty. @type string $description Description for the control. Default empty. @type array $choices List of choices for 'radio' or 'select' type controls, where values are the keys, and labels are the values. Default empty array. @type 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. Default empty array. @type array $json Deprecated. Use WP_Customize_Control::json() instead. @type string $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. Default 'text'. }
 public function __construct($manager, $id, $args = array())
 {
     parent::__construct($manager, $id, $args);
     if (empty($this->button_label)) {
         $this->button_label = esc_attr__('Add new row', 'Kirki');
     }
     if (empty($args['fields']) || !is_array($args['fields'])) {
         $args['fields'] = array();
     }
     foreach ($args['fields'] as $key => $value) {
         if (!isset($value['default'])) {
             $args['fields'][$key]['default'] = '';
         }
         if (!isset($value['label'])) {
             $args['fields'][$key]['label'] = '';
         }
         $args['fields'][$key]['id'] = $key;
     }
     $this->fields = $args['fields'];
 }
 public function __construct($manager, $id, $args = array())
 {
     parent::__construct($manager, $id, $args);
     add_filter('customize_sanitize_' . $id, array($this, 'customize_sanitize'));
 }
 /**
  * Constructor.
  * Supplied `$args` override class property defaults.
  * If `$args['settings']` is not defined, use the $id as the setting ID.
  *
  * @param WP_Customize_Manager $manager Customizer bootstrap instance.
  * @param string               $id      Control ID.
  * @param array                $args    {@see WP_Customize_Control::__construct}.
  */
 public function __construct($manager, $id, $args = array())
 {
     parent::__construct($manager, $id, $args);
     // Set up defaults for row labels.
     $this->row_label = array('type' => 'text', 'value' => $this->l10n['row'], 'field' => false);
     // Validating args for row labels.
     if (isset($args['row_label']) && is_array($args['row_label']) && !empty($args['row_label'])) {
         // Validating row label type.
         if (isset($args['row_label']['type']) && ('text' === $args['row_label']['type'] || 'field' === $args['row_label']['type'])) {
             $this->row_label['type'] = $args['row_label']['type'];
         }
         // Validating row label type.
         if (isset($args['row_label']['value']) && !empty($args['row_label']['value'])) {
             $this->row_label['value'] = esc_attr($args['row_label']['value']);
         }
         // Validating row label field.
         if (isset($args['row_label']['field']) && !empty($args['row_label']['field']) && isset($args['fields'][esc_attr($args['row_label']['field'])])) {
             $this->row_label['field'] = esc_attr($args['row_label']['field']);
         } else {
             // If from field is not set correctly, making sure standard is set as the type.
             $this->row_label['type'] = 'text';
         }
     }
     if (empty($this->button_label)) {
         $this->button_label = $this->l10n['add-new'] . ' ' . $this->row_label['value'];
     }
     if (empty($args['fields']) || !is_array($args['fields'])) {
         $args['fields'] = array();
     }
     // An array to store keys of fields that need to be filtered.
     $media_fields_to_filter = array();
     foreach ($args['fields'] as $key => $value) {
         if (!isset($value['default'])) {
             $args['fields'][$key]['default'] = '';
         }
         if (!isset($value['label'])) {
             $args['fields'][$key]['label'] = '';
         }
         $args['fields'][$key]['id'] = $key;
         // We check if the filed is an uploaded media ( image , file, video, etc.. ).
         if (isset($value['type']) && ('image' === $value['type'] || 'cropped_image' === $value['type'] || 'upload' === $value['type'])) {
             // We add it to the list of fields that need some extra filtering/processing.
             $media_fields_to_filter[$key] = true;
         }
         // If the field is a dropdown-pages field then add it to args.
         if (isset($value['type']) && 'dropdown-pages' === $value['type']) {
             $dropdown = wp_dropdown_pages(array('name' => '', 'echo' => 0, 'show_option_none' => esc_attr($this->l10n['select-page']), 'option_none_value' => '0', 'selected' => ''));
             // Hackily add in the data link parameter.
             $dropdown = str_replace('<select', '<select data-field="' . esc_attr($args['fields'][$key]['id']) . '"' . $this->get_link(), $dropdown);
             $args['fields'][$key]['dropdown'] = $dropdown;
         }
     }
     $this->fields = $args['fields'];
     // Now we are going to filter the fields.
     // First we create a copy of the value that would be used otherwise.
     $this->filtered_value = $this->value();
     if (is_array($this->filtered_value) && !empty($this->filtered_value)) {
         // We iterate over the list of fields.
         foreach ($this->filtered_value as &$filtered_value_field) {
             if (is_array($filtered_value_field) && !empty($filtered_value_field)) {
                 // We iterate over the list of properties for this field.
                 foreach ($filtered_value_field as $key => &$value) {
                     // We check if this field was marked as requiring extra filtering (in this case image, cropped_images, upload).
                     if (array_key_exists($key, $media_fields_to_filter)) {
                         // What follows was made this way to preserve backward compatibility.
                         // The repeater control use to store the URL for images instead of the attachment ID.
                         // We check if the value look like an ID (otherwise it's probably a URL so don't filter it).
                         if (is_numeric($value)) {
                             // "sanitize" the value.
                             $attachment_id = (int) $value;
                             // Try to get the attachment_url.
                             $url = wp_get_attachment_url($attachment_id);
                             $filename = basename(get_attached_file($attachment_id));
                             // If we got a URL.
                             if ($url) {
                                 // 'id' is needed for form hidden value, URL is needed to display the image.
                                 $value = array('id' => $attachment_id, 'url' => $url, 'filename' => $filename);
                             }
                         }
                     }
                 }
             }
         }
     }
 }