Kirki_Customize_Control::to_json PHP Method

to_json() public method

Refresh the parameters passed to the JavaScript via JSON.
See also: WP_Customize_Control::to_json()
public to_json ( )
        public function to_json()
        {
            parent::to_json();
            if (isset($this->default)) {
                $this->json['default'] = $this->default;
            } else {
                $this->json['default'] = $this->setting->default;
            }
            $this->json['js_vars'] = $this->js_vars;
            $this->json['output'] = $this->output;
            $this->json['value'] = $this->value();
            $this->json['choices'] = $this->choices;
            $this->json['link'] = $this->get_link();
            $this->json['tooltip'] = $this->tooltip;
            $this->json['id'] = $this->id;
            $this->json['l10n'] = $this->l10n;
            $this->json['kirkiConfig'] = $this->kirki_config;
            if ('user_meta' === $this->option_type) {
                $this->json['value'] = get_user_meta(get_current_user_id(), $this->id, true);
            }
            $this->json['inputAttrs'] = '';
            foreach ($this->input_attrs as $attr => $value) {
                $this->json['inputAttrs'] .= $attr . '="' . esc_attr($value) . '" ';
            }
        }

Usage Example

 public function to_json()
 {
     parent::to_json();
     $this->json['choices'] = array();
     if (is_array($this->choices)) {
         if (isset($this->choices['top']) && true == $this->choices['top']) {
             $this->json['choices']['top'] = true;
         }
         if (isset($this->choices['bottom']) && true == $this->choices['bottom']) {
             $this->json['choices']['bottom'] = true;
         }
         if (isset($this->choices['left']) && true == $this->choices['left']) {
             $this->json['choices']['left'] = true;
         }
         if (isset($this->choices['right']) && true == $this->choices['right']) {
             $this->json['choices']['right'] = true;
         }
     }
     $i18n = Kirki_Toolkit::i18n();
     $this->json['l10n'] = array('top' => $i18n['top'], 'bottom' => $i18n['bottom'], 'left' => $i18n['left'], 'right' => $i18n['right']);
     if (isset($this->json['choices']['top']) && !isset($this->json['value']['top'])) {
         $this->json['value']['top'] = $this->json['default']['top'];
     }
     if (isset($this->json['choices']['bottom']) && !isset($this->json['value']['bottom'])) {
         $this->json['value']['bottom'] = $this->json['default']['bottom'];
     }
     if (isset($this->json['choices']['left']) && !isset($this->json['value']['left'])) {
         $this->json['value']['left'] = $this->json['default']['left'];
     }
     if (isset($this->json['choices']['right']) && !isset($this->json['value']['top'])) {
         $this->json['value']['right'] = $this->json['default']['right'];
     }
 }
All Usage Examples Of Kirki_Customize_Control::to_json