示例#1
0
 /**
  * Normalize parameters for field
  *
  * @param array $field
  *
  * @return array
  */
 static function normalize_field($field)
 {
     $field = wp_parse_args($field, array('post_type' => 'post', 'field_type' => 'select_advanced', 'parent' => false, 'query_args' => array()));
     /**
      * Set default placeholder
      * - If multiple post types: show 'Select a post'
      * - If single post type: show 'Select a %post_type_name%'
      */
     if (empty($field['placeholder'])) {
         $label = __('Select a post', 'meta-box');
         if (is_string($field['post_type'])) {
             $post_type_object = get_post_type_object($field['post_type']);
             $label = sprintf(__('Select a %s', 'meta-box'), $post_type_object->labels->singular_name);
         }
         $field['placeholder'] = $label;
     }
     if ($field['parent']) {
         $field['multiple'] = false;
         $field['field_name'] = 'parent_id';
     }
     $field['query_args'] = wp_parse_args($field['query_args'], array('post_type' => $field['post_type'], 'post_status' => 'publish', 'posts_per_page' => -1));
     switch ($field['field_type']) {
         case 'select':
             return Field_Select::normalize_field($field);
             break;
         case 'select_advanced':
         default:
             return Field_Select_Advanced::normalize_field($field);
     }
 }
示例#2
0
 /**
  * Normalize parameters for field
  *
  * @param array $field
  *
  * @return array
  */
 public static function normalize_field($field)
 {
     $field = parent::normalize_field($field);
     if (!isset($field['js_options'])) {
         $field['js_options'] = array();
     }
     $field['js_options'] = wp_parse_args($field['js_options'], array('allowClear' => true, 'width' => 'resolve', 'placeholder' => $field['placeholder'], '_ajax_url' => isset($field['url']) ? $field['url'] : false));
     return $field;
 }
示例#3
0
 /**
  * Normalize parameters for field
  *
  * @param array $field
  *
  * @return array
  */
 static function normalize_field($field)
 {
     $default_post_type = __('User');
     $field = wp_parse_args($field, array('field_type' => 'select_advanced', 'parent' => false, 'query_args' => array()));
     $field['std'] = empty($field['std']) ? sprintf(__('Select a %s', 'meta-box'), $default_post_type) : $field['std'];
     $field['query_args'] = wp_parse_args($field['query_args'], array('orderby' => 'display_name', 'order' => 'asc', 'role' => '', 'fields' => 'all'));
     switch ($field['field_type']) {
         case 'select':
             $field = Field_Select::normalize_field($field);
             break;
         case 'select_advanced':
         default:
             $field = Field_Select_Advanced::normalize_field($field);
     }
     return $field;
 }
 /**
  * Get field HTML
  *
  * @param $field
  * @param $meta
  *
  * @return string
  */
 static function html($meta, $field)
 {
     $options = $field->options;
     $terms = get_terms($options['taxonomy'], $options['args']);
     $field->options = self::get_options($terms);
     $field->display_type = $options['type'];
     $html = '';
     switch ($options['type']) {
         case 'checkbox_list':
             $html = Field_Checkbox_List::html($meta, $field);
             break;
         case 'checkbox_tree':
             $elements = self::process_terms($terms);
             $html .= self::walk_checkbox_tree($meta, $field, $elements, $options['parent'], true);
             break;
         case 'select_tree':
             $elements = self::process_terms($terms);
             $html .= self::walk_select_tree($meta, $field, $elements, $options['parent'], true);
             break;
         case 'select_advanced':
             $html = Field_Select_Advanced::html($meta, $field);
             break;
         case 'select':
         default:
             $html = Field_Select::html($meta, $field);
     }
     return $html;
 }