function wpcd_get_customizer_setting($panel_slug, $field_slug, $formatted = false)
 {
     if (doing_action('wpcd') || !did_action('wpcd')) {
         if ('general' === $panel_slug) {
             $setting = get_theme_mod($field_slug, null);
             if (!$setting) {
                 $setting = get_option($field_slug, null);
             }
             return $setting;
         }
         $settings = get_theme_mod($panel_slug, array());
         if (!isset($settings[$field_slug])) {
             $settings = get_option($panel_slug, array());
         }
         return isset($settings[$field_slug]) ? $settings[$field_slug] : null;
     }
     $setting = null;
     $field = \WPDLib\Components\Manager::get($panel_slug . '.*.' . $field_slug, 'WPCD\\Components\\Panel', true);
     if ($field) {
         if ('general' === $panel_slug) {
             $setting = \WPCD\Utility::parse_setting('option' === $field->mode ? get_option($field->slug, null) : get_theme_mod($field->slug, null), $field, $formatted);
         } else {
             if ('option' === $field->mode) {
                 $_options = get_option($panel_slug, array());
                 $setting = \WPCD\Utility::parse_setting(isset($_options[$field->slug]) ? $_options[$field->slug] : null, $field, $formatted);
             } else {
                 $_thememods = get_theme_mod($panel_slug, array());
                 $setting = \WPCD\Utility::parse_setting(isset($_thememods[$field->slug]) ? $_thememods[$field->slug] : null, $field, $formatted);
             }
         }
     }
     return $setting;
 }
예제 #2
0
 /**
  * Validates the arguments array.
  *
  * @since 0.5.0
  */
 public function validate($parent = null)
 {
     $status = parent::validate($parent);
     if ($status === true) {
         if (null === $this->args['capability']) {
             $this->args['capability'] = 'edit_theme_options';
         }
         if (isset($this->args['priority'])) {
             if (null === $this->args['position']) {
                 $this->args['position'] = $this->args['priority'];
             }
             unset($this->args['priority']);
         }
         $this->args = Utility::validate_position_args($this->args);
     }
     return $status;
 }
예제 #3
0
 /**
  * Validates the arguments array.
  *
  * @since 0.5.0
  */
 public function validate($parent = null)
 {
     $status = parent::validate($parent);
     if ($status === true) {
         if (null === $this->args['capability']) {
             $this->args['capability'] = $parent->capability;
         }
         if (isset($this->args['priority'])) {
             if (null === $this->args['position']) {
                 $this->args['position'] = $this->args['priority'];
             }
             unset($this->args['priority']);
         }
         $this->args = Utility::validate_position_args($this->args);
         if (null === $this->args['mode']) {
             $this->args['mode'] = $parent->get_parent()->mode;
         }
         if (is_array($this->args['class'])) {
             $this->args['class'] = implode(' ', $this->args['class']);
         }
         if (isset($this->args['options']) && !is_array($this->args['options'])) {
             $this->args['options'] = array();
         }
         if (in_array($this->args['type'], array('multiselect', 'multibox'), true)) {
             return new UtilError('multichoice_not_supported', sprintf(__('The multichoice field type assigned to the field component %s is not supported in the Customizer.', 'customizer-definitely'), $this->slug), '', ComponentManager::get_scope());
         }
         if ('repeatable' == $this->args['type']) {
             return new UtilError('repeatable_not_supported', sprintf(__('The repeatable field type assigned to the field component %s is not supported in the Customizer.', 'customizer-definitely'), $this->slug), '', ComponentManager::get_scope());
         }
         $this->_field = FieldManager::get_instance($this->args);
         if (null === $this->_field) {
             return new UtilError('no_valid_field_type', sprintf(__('The field type %1$s assigned to the field component %2$s is not a valid field type.', 'customizer-definitely'), $this->args['type'], $this->slug), '', ComponentManager::get_scope());
         }
         if (null === $this->args['default']) {
             $this->args['default'] = $this->_field->validate();
         }
         $this->args['preview_args'] = Customizer::instance()->validate_preview_args($this->args['preview_args'], $this->args['type'], $this->_field);
         if (null === $this->args['transport']) {
             if ($this->args['preview_args']['update_callback']) {
                 $this->args['transport'] = 'postMessage';
             } else {
                 $this->args['transport'] = 'refresh';
             }
         }
     }
     return $status;
 }