public static function sortble_term($args = array()) { $option_name = ''; $sortable_class = ''; $sortable_active_class = ''; $term_args = array(); $taxonomy = ''; if (is_array($args)) { extract($args); } if (empty($option_name) || empty($taxonomy)) { return; } $sortable_class = SB_PHP::add_string_with_space_before($sortable_class, 'connected-sortable sb-sortable-list left min-height sortable-source'); $sortable_active_class = SB_PHP::add_string_with_space_before($sortable_active_class, 'connected-sortable active-sortable sb-sortable-list min-height right'); $active_terms = SB_Option::get_theme_option_single_key($option_name); $term_args['exclude'] = $active_terms; $terms = SB_Term::get($taxonomy, $term_args); ?> <div class="sb-sortable"> <div class="sb-sortable-container"> <ul class="<?php echo $sortable_class; ?> "> <?php foreach ($terms as $term) { ?> <li data-term="<?php echo $term->term_id; ?> " class="ui-state-default"><?php echo $term->name; ?> </li> <?php } ?> </ul> <ul class="<?php echo $sortable_active_class; ?> "> <?php $terms = $active_terms; $active_terms = explode(',', $active_terms); ?> <?php foreach ($active_terms as $term_id) { if ($term_id < 1) { continue; } $term = get_term($term_id, $taxonomy); ?> <?php if (!$term) { continue; } ?> <li data-term="<?php echo $term->term_id; ?> " class="ui-state-default"><?php echo $term->name; ?> </li> <?php } ?> </ul> </div> <input type="hidden" class="active-sortalbe-value" name="sb_options[theme][<?php echo $option_name; ?> ]" value="<?php echo $terms; ?> "> </div> <p class="description" style="clear: both"><?php _e('Drag and drop the widget into right box to active it.', 'sb-theme'); ?> </p> <?php }
public static function select_term($args = array()) { $container_class = isset($args['container_class']) ? $args['container_class'] : ''; $id = isset($args['id']) ? $args['id'] : ''; $name = isset($args['name']) ? $args['name'] : ''; $field_class = isset($args['field_class']) ? $args['field_class'] : ''; $label = isset($args['label']) ? $args['label'] : ''; $options = isset($args['options']) ? $args['options'] : array(); $value = isset($args['value']) ? $args['value'] : ''; $description = isset($args['description']) ? $args['description'] : ''; $taxonomy = isset($args['taxonomy']) ? $args['taxonomy'] : ''; $taxonomy_id = isset($args['taxonomy_id']) ? $args['taxonomy_id'] : ''; $taxonomy_name = isset($args['taxonomy_name']) ? $args['taxonomy_name'] : ''; $show_count = isset($args['show_count']) ? $args['show_count'] : true; $before = isset($args['before']) ? $args['before'] : '<p class="' . esc_attr($container_class) . '">'; $after = isset($args['after']) ? $args['after'] : '</p>'; echo $before; self::label(array('for' => $id, 'text' => $label)); $all_option = '<option value="0">' . __('Choose term', 'sb-core') . '</option>'; $args['before'] = ''; if (count($options) > 0) { foreach ($options as $tax) { $terms = get_terms($tax->name); if (!SB_Core::is_error($terms) && count($terms) > 0) { $tmp = '<optgroup label="' . $tax->labels->name . '">'; foreach ($terms as $cat) { $option_text = $cat->name . $show_count ? ' (' . $cat->count . ')' : ''; $tmp .= self::get_option(array('value' => $cat->term_id, 'attributes' => array('data-taxonomy' => $tax->name), 'selected' => $value, 'text' => $option_text)); } $tmp .= '</optgroup>'; $all_option .= $tmp; } } } else { $terms = SB_Term::get($taxonomy); if (!SB_Core::is_error($terms) && count($terms) > 0) { foreach ($terms as $cat) { $all_option .= self::get_option(array('value' => $cat->term_id, 'attributes' => array('data-taxonomy' => $tax->name), 'selected' => $value, 'text' => $option_text)); } } } $args['all_option'] = $all_option; self::select($args); if (!empty($taxonomy_name)) { $args['id'] = $taxonomy_id; $args['name'] = $taxonomy_name; $args['value'] = $taxonomy; $args['field_class'] = 'widefat taxonomy'; $args['type'] = 'hidden'; self::text($args); } echo $after; }