/** * Normalize parameters for field * * @param array $field * * @return array */ static function normalize_field($field) { $default_post_type = __('User', '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']; $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 SW_META_Select_Field::normalize_field($field); break; case 'select_advanced': default: return SW_META_Select_Advanced_Field::normalize_field($field); } }
/** * Normalize parameters for field * * @param array $field * * @return array */ static function normalize_field($field) { $default_post_type = __('Post', 'meta-box'); 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', 'meta-box'), $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 SW_META_Select_Field::normalize_field($field); break; case 'select_advanced': default: return SW_META_Select_Advanced_Field::normalize_field($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); $html = ''; switch ($options['type']) { case 'checkbox_list': $html = SW_META_Checkbox_List_Field::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 = SW_META_Select_Advanced_Field::html($meta, $field); break; case 'select': default: $html = SW_META_Select_Field::html($meta, $field); } return $html; }