/** * Generate taxonomy control * * @param string $title Field label * @param string $id Field id * @param array $args field options * @return string field markup */ public function taxonomy($title, $id, $args = array(), $taxonomy, $tax_args = array()) { $terms = get_terms($taxonomy ? $taxonomy : 'category', $tax_args); $options = array(); if (!empty($terms) && !is_wp_error($terms)) { foreach ($terms as $term) { $options[$term->term_id] = $term->name; } } /* Create taxonomy with specific field, default select field*/ if ($args['type']) { $input = parent::$args['type']($title, $id, $args, $options); } else { $input = parent::select($title, $id, $args, $options); } /* Echo field or return the markup */ if ($echo === false) { return $input; } else { echo $input; } }
* @param array $options List of slect options * @return string Field markup */ public function radio($title, $id, $args = array(), $options = array()) { $this->title = $title; $this->id = $id; $this->args = $args; /* Make $args array key into variable */ extract($this->args); /* Validation for every control attributes must have value */ $control_id = self::must_exists($id, "id='{$id}'", ''); $control_name = self::must_exists($name, 'name="' . $name . '"', 'name="' . $id . '"'); $control_value = self::must_exists($value, "value='{$value}'", ''); $control_label = self::must_exists($title, "<label class='control-label' for='{$id}'>{$title}</label>", ''); $control_info = self::must_exists($info, "<span class='control-info'>{$info}</span>", ''); $before_control = self::must_exists($before_control, $before_control, "<div class='widget-separator'>"); $after_control = self::must_exists($after_control, $after_control, "</div>"); $control_attr = self::each_attr($attr); /* Print markup before control*/ $input = $before_control . $control_label . "<div class='radio-wrapper widefat {$class}' {$control_id} >" . self::each_radio($control_name, $options, $value, $control_attr) . "</div>" . $control_info . $after_control; /* Echo field or return the markup */ if ($echo === false) { return $input; } else { echo $input; } } } Basic_Fields::getInstance(); }