Example #1
1
 /**
  * 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', 'framework'), $tax->labels->singular_name) : $field['placeholder'];
     switch ($field['options']['type']) {
         case 'select_advanced':
             $field = RWMB_Select_Advanced_Field::normalize_field($field);
             break;
         case 'checkbox_list':
         case 'checkbox_tree':
             $field = RWMB_Checkbox_List_Field::normalize_field($field);
             break;
         case 'select':
         case 'select_tree':
             $field = RWMB_Select_Field::normalize_field($field);
             break;
         default:
             $field['options']['type'] = 'select';
             $field = RWMB_Select_Field::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;
         }
     }
     $field['field_name'] = "{$field['id']}[]";
     return $field;
 }
Example #2
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_exists($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 RWMB_Select_Field::normalize_field($field);
             break;
         case 'select_advanced':
         default:
             return RWMB_Select_Advanced_Field::normalize_field($field);
     }
 }
Example #3
0
 /**
  * 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);
     //Field name be an array by default
     $field['field_name'] = "{$field['id']}[]";
     switch ($field['options']['type']) {
         case 'select_advanced':
             $field = RWMB_Select_Advanced_Field::normalize_field($field);
             break;
         case 'checkbox_list':
         case 'checkbox_tree':
             $field = RWMB_Checkbox_List_Field::normalize_field($field);
             break;
         case 'select':
         case 'select_tree':
             $field = RWMB_Select_Field::normalize_field($field);
             break;
         default:
             $field['options']['type'] = 'select';
             $field = RWMB_Select_Field::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;
 }
Example #4
0
 /**
  * Normalize parameters for field
  *
  * @param array $field
  *
  * @return array
  */
 static function normalize_field($field)
 {
     $pt_obj = get_post_type_object($field['post_type']);
     $field = wp_parse_args($field, array('post_type' => 'post', 'field_type' => 'select_advanced', 'default' => sprintf(__('Select a %s', 'rwmb'), $pt_obj->labels->singular_name), 'parent' => false, 'query_args' => array()));
     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'));
     return RWMB_Select_Advanced_Field::normalize_field($field);
 }
Example #5
0
 /**
  * Normalize parameters for field
  *
  * @param array $field
  *
  * @return array
  */
 static function normalize_field($field)
 {
     $field = wp_parse_args($field, array('field_type' => 'select_advanced', 'parent' => false, 'query_args' => array()));
     $field['std'] = empty($field['std']) ? __('Select an user', 'meta-box') : $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':
             return RWMB_Select_Field::normalize_field($field);
             break;
         case 'select_advanced':
         default:
             return RWMB_Select_Advanced_Field::normalize_field($field);
     }
 }
Example #6
0
 /**
  * Normalize parameters for field
  *
  * @param array $field
  *
  * @return array
  */
 static function normalize_field($field)
 {
     $default_post_type = __('用户', 'rwmb');
     $field = wp_parse_args($field, array('field_type' => 'select_advanced', 'parent' => false, 'query_args' => array()));
     $field['std'] = empty($field['std']) ? sprintf(__('已选择 %s', 'rwmb'), $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':
             return RWMB_Select_Field::normalize_field($field);
             break;
         case 'select_advanced':
         default:
             return RWMB_Select_Advanced_Field::normalize_field($field);
     }
 }
Example #7
0
 /**
  * Normalize parameters for field
  *
  * @param array $field
  *
  * @return array
  */
 static function normalize_field($field)
 {
     $default_post_type = __('Post', 'meta-box');
     $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'];
     if ($field['parent']) {
         $field['multiple'] = false;
         $field['field_name'] = 'parent_id';
     }
     switch ($field['field_type']) {
         case 'select':
             return RWMB_Select_Field::normalize_field($field);
             break;
         case 'select_advanced':
         default:
             return RWMB_Select_Advanced_Field::normalize_field($field);
     }
 }
Example #8
0
 /**
  * Normalize parameters for field
  *
  * @param array $field
  *
  * @return array
  */
 static function normalize_field($field)
 {
     $default_post_type = __('Post', 'rwmb');
     if (is_string($field['post_type'])) {
         $post_type_object = get_post_type_object($field['post_type']);
         $default_post_type = $post_type_object->labels->singular_name;
     }
     $field = wp_parse_args($field, array('post_type' => 'post', 'field_type' => 'select_advanced', 'parent' => false, 'query_args' => array()));
     $field['std'] = empty($field['std']) ? sprintf(__('Select a %s', 'rwmb'), $default_post_type) : $field['std'];
     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 RWMB_Select_Field::normalize_field($field);
             break;
         case 'select_advanced':
         default:
             return RWMB_Select_Advanced_Field::normalize_field($field);
     }
 }