Inheritance: extends RWMB_Field
Esempio n. 1
0
 /**
  * Normalize parameters for field
  *
  * @param array $field
  *
  * @return array
  */
 static function normalize($field)
 {
     /**
      * Set default field args
      */
     $field = wp_parse_args($field, array('field_type' => 'select', 'query_args' => array()));
     /**
      * Prevent select tree for user since it's not hierarchical
      */
     $field['field_type'] = 'select_tree' === $field['field_type'] ? 'select' : $field['field_type'];
     /**
      * Set to always flat
      */
     $field['flatten'] = true;
     /**
      * Set default placeholder
      */
     $field['placeholder'] = empty($field['placeholder']) ? __('Select an user', 'meta-box') : $field['placeholder'];
     /**
      * Set default query args
      */
     $field['query_args'] = wp_parse_args($field['query_args'], array('orderby' => 'display_name', 'order' => 'asc', 'role' => '', 'fields' => 'all'));
     $field = parent::normalize($field);
     return $field;
 }
Esempio n. 2
0
 /**
  * Get 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)
  *
  * @see "save" method for better understanding
  *
  * @param $post_id
  * @param $saved
  * @param $field
  *
  * @return array
  */
 static function meta($post_id, $saved, $field)
 {
     if (isset($field['parent']) && $field['parent']) {
         $post = get_post($post_id);
         return $post->post_parent;
     }
     return parent::meta($post_id, $saved, $field);
 }
Esempio n. 3
0
 /**
  * Add default value for 'taxonomy' field
  *
  * @param $field
  * @return array
  */
 public static function normalize($field)
 {
     /**
      * Backwards compatibility with field args
      */
     if (isset($field['options']['args'])) {
         $field['query_args'] = $field['options']['args'];
     }
     if (isset($field['options']['taxonomy'])) {
         $field['taxonomy'] = $field['options']['taxonomy'];
     }
     if (isset($field['options']['type'])) {
         $field['field_type'] = $field['options']['type'];
     }
     /**
      * Set default field args
      */
     $field = parent::normalize($field);
     $field = wp_parse_args($field, array('taxonomy' => 'category'));
     /**
      * Set default query args
      */
     $field['query_args'] = wp_parse_args($field['query_args'], array('hide_empty' => false));
     /**
      * Set default placeholder
      * - If multiple taxonomies: show 'Select a term'
      * - If single taxonomy: show 'Select a %taxonomy_name%'
      */
     if (empty($field['placeholder'])) {
         $field['placeholder'] = __('Select a term', 'meta-box');
         if (is_string($field['taxonomy']) && taxonomy_exists($field['taxonomy'])) {
             $taxonomy_object = get_taxonomy($field['taxonomy']);
             $field['placeholder'] = sprintf(__('Select a %s', 'meta-box'), $taxonomy_object->labels->singular_name);
         }
     }
     /**
      * Prevent cloning for taxonomy field
      */
     $field['clone'] = false;
     return $field;
 }