コード例 #1
0
ファイル: Repeatable.php プロジェクト: felixarntz/wpdlib
 /**
  * Class constructor.
  *
  * For an overview of the supported arguments, please read the Field Types Reference.
  *
  * @since 0.5.0
  * @param string $type the field type
  * @param array $args array of field type arguments
  */
 public function __construct($type, $args)
 {
     $args = wp_parse_args($args, array('repeatable' => array()));
     if (!is_array($args['repeatable'])) {
         $args['repeatable'] = array();
     }
     if (!isset($args['repeatable']['limit'])) {
         $args['repeatable']['limit'] = 0;
     } else {
         $args['repeatable']['limit'] = absint($args['repeatable']['limit']);
     }
     if (!isset($args['repeatable']['fields']) || !is_array($args['repeatable']['fields'])) {
         $args['repeatable']['fields'] = array();
     }
     parent::__construct($type, $args);
     foreach ($this->args['repeatable']['fields'] as $field_slug => $field_args) {
         $field = FieldManager::get_instance($field_args);
         if ($field !== null) {
             $this->fields[$field_slug] = $field;
         }
     }
 }
コード例 #2
0
 /**
  * Validates the arguments array.
  *
  * @since 0.5.0
  * @param WPWD\Components\Section $parent the parent component
  * @return bool|WPDLib\Util\Error an error object if an error occurred during validation, true if it was validated, false if it did not need to be validated
  */
 public function validate($parent = null)
 {
     $status = parent::validate($parent);
     if ($status === true) {
         if (is_array($this->args['class'])) {
             $this->args['class'] = implode(' ', $this->args['class']);
         }
         if (!empty($this->args['class'])) {
             $this->args['class'] .= ' ';
         }
         $this->args['class'] .= 'widefat';
         if (isset($this->args['options']) && !is_array($this->args['options'])) {
             $this->args['options'] = array();
         }
         $this->_field = FieldManager::get_instance($this->args);
         if ($this->_field === null) {
             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.', 'widgets-definitely'), $this->args['type'], $this->slug), '', ComponentManager::get_scope());
         }
         if (null === $this->args['default']) {
             $this->args['default'] = $this->_field->validate();
         }
         $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;
 }