Beispiel #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);
     }
 }
 /**
  * Add default value for 'taxonomy' field
  *
  * @param $field
  *
  * @return array
  */
 static function normalize_field($field)
 {
     $default_args = array('hide_empty' => false);
     // Set default args
     $field['options']['args'] = !isset($field['options']['args']) ? $default_args : wp_parse_args($field['options']['args'], $default_args);
     $tax = get_taxonomy($field['options']['taxonomy']);
     $field['placeholder'] = empty($field['placeholder']) ? sprintf(__('Select a %s'), $tax->labels->singular_name) : $field['placeholder'];
     switch ($field['options']['type']) {
         case 'select_advanced':
             $field = Field_Select_Advanced::normalize_field($field);
             break;
         case 'checkbox_list':
         case 'checkbox_tree':
             $field = Field_Checkbox_List::normalize_field($field);
             break;
         case 'select':
         case 'select_tree':
             $field = Field_Select::normalize_field($field);
             break;
         default:
             $field['options']['type'] = 'select';
             $field = Field_Select::normalize_field($field);
     }
     if (in_array($field['options']['type'], array('checkbox_tree', 'select_tree'))) {
         if (isset($field['options']['args']['parent'])) {
             $field['options']['parent'] = $field['options']['args']['parent'];
             unset($field['options']['args']['parent']);
         } else {
             $field['options']['parent'] = 0;
         }
     }
     return $field;
 }
Beispiel #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;
 }