/**
  * Normalize parameters for field
  *
  * @param array $field
  *
  * @return array
  */
 static function normalize_field($field)
 {
     $field = parent::normalize_field($field);
     $field = wp_parse_args($field, array('js_options' => array()));
     $field['js_options'] = wp_parse_args($field['js_options'], array('allowClear' => true, 'width' => 'resolve', 'placeholder' => $field['placeholder']));
     return $field;
 }
Esempio n. 2
0
 /**
  * Save meta value
  * If field is cloneable, value is saved as a single entry in DB
  * Otherwise value is saved as multiple entries (for backward compatibility)
  *
  * TODO: A good way to ALWAYS save values in single entry in DB, while maintaining backward compatibility
  *
  * @param $new
  * @param $old
  * @param $post_id
  * @param $field
  */
 static function save($new, $old, $post_id, $field)
 {
     return SW_META_Select_Field::save($new, $old, $post_id, $field);
 }
Esempio n. 3
0
 /**
  * Walker for displaying select in tree format
  *
  * @param        $meta
  * @param        $field
  * @param        $elements
  * @param int    $parent
  * @param bool   $active
  *
  * @return string
  */
 static function walk_select_tree($meta, $field, $elements, $parent = 0, $active = false)
 {
     if (!isset($elements[$parent])) {
         return;
     }
     $terms = $elements[$parent];
     $field['options'] = self::get_options($terms);
     $classes = array('rw-taxonomy-tree');
     $classes[] = $active ? 'active' : 'disabled';
     $classes[] = "SW_META-taxonomy-{$parent}";
     $html = '<div class="' . implode(' ', $classes) . '">';
     $html .= SW_META_Select_Field::html($meta, $field);
     foreach ($terms as $term) {
         $html .= self::walk_select_tree($meta, $field, $elements, $term->term_id, $active && in_array($term->term_id, $meta));
     }
     $html .= '</div>';
     return $html;
 }