/** * 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; }
/** * Normalize parameters for field * * @param array $field * * @return array */ static function normalize($field) { /** * Set default field args */ $field = wp_parse_args($field, array('post_type' => 'post', 'field_type' => 'select', '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'])) { $field['placeholder'] = __('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']); $field['placeholder'] = sprintf(__('Select a %s', 'meta-box'), $post_type_object->labels->singular_name); } } /** * Set parent option, which will change field name to `parent_id` to save as post parent */ if ($field['parent']) { $field['multiple'] = false; $field['field_name'] = 'parent_id'; } /** * Set default query args */ $field['query_args'] = wp_parse_args($field['query_args'], array('post_status' => 'publish', 'posts_per_page' => -1)); $field['query_args']['post_type'] = $field['post_type']; $field = parent::normalize($field); return $field; }
/** * 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; }