/** * The run() method. * * This will initialize the plugin on the 'after_setup_theme' action. * If we are currently in the WordPress admin area, the WPCD\Admin class will be instantiated. * * @since 0.5.0 */ protected function run() { FieldManager::init(); Customizer::instance(); AJAX::instance(); CSSGenerator::instance(); // use after_setup_theme action so it is initialized as soon as possible, but also so that both plugins and themes can use the action add_action('after_setup_theme', array($this, 'init'), 3); add_filter('wpcd_panel_validated', array($this, 'panel_validated'), 10, 2); add_filter('wpcd_section_validated', array($this, 'section_validated'), 10, 2); }
/** * 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; }