tag-dropdown-widget.php 21.5 KB
Newer Older
1
2
3
4
5
6
7
8
<?php
/*
Plugin Name: Taxonomy Dropdown Widget
Plugin URI: http://www.ethitter.com/plugins/taxonomy-dropdown-widget/
Description: Creates a dropdown list of non-hierarchical taxonomies as an alternative to the term (tag) cloud. Widget provides numerous options to tailor the output to fit your site. Dropdown function can also be called directly for use outside of the widget. Formerly known as <strong><em>Tag Dropdown Widget</em></strong>.
Author: Erick Hitter
Version: 2.0.3
Author URI: http://www.ethitter.com/
Erick Hitter's avatar
License    
Erick Hitter committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23
24
25
26
27
28
*/

/**
 ** TAXONOMY DROPDOWN WIDGET PLUGIN
 **/
class taxonomy_dropdown_widget_plugin {
Erick Hitter's avatar
Erick Hitter committed
29
30
31
32
33
	/**
	 * Singleton!
	 */
	private static $__instance = null;

Erick Hitter's avatar
Erick Hitter committed
34
	/**
35
36
	 * Class variables
	 */
Erick Hitter's avatar
Erick Hitter committed
37
	protected $option_defaults = array(
38
39
40
41
42
43
44
45
46
47
48
49
50
51
		'taxonomy' => 'post_tag',
		'select_name' => 'Select Tag',
		'max_name_length' => 0,
		'cutoff' => '&hellip;',
		'limit' => 0,
		'order' => 'ASC',
		'orderby' => 'name',
		'threshold' => 0,
		'incexc' => 'exclude',
		'incexc_ids' => array(),
		'hide_empty' => true,
		'post_counts' => false
	);

Erick Hitter's avatar
Erick Hitter committed
52
53
54
55
56
57
58
59
60
61
62
63
64
	/**
	 * Implement the singleton
	 *
	 * @return object
	 */
	public static function get_instance() {
		if ( ! is_a( self::$__instance, __CLASS__ ) ) {
			self::$__instance = new self;
		}

		return self::$__instance;
	}

Erick Hitter's avatar
Erick Hitter committed
65
	/**
66
	 * Register actions and activation/deactivation hooks
Erick Hitter's avatar
Erick Hitter committed
67
68
69
	 * @uses add_action
	 * @uses register_activation_hook
	 * @uses register_deactivation_hook
70
71
	 * @return null
	 */
Erick Hitter's avatar
Erick Hitter committed
72
	protected function __construct() {
73
74
75
76
77
78
		add_action( 'widgets_init', array( $this, 'action_widgets_init' ) );

		register_activation_hook( __FILE__, array( $this, 'activation_hook' ) );
		register_deactivation_hook( __FILE__, array( $this, 'deactivation_hook' ) );
	}

79
80
81
82
83
84
85
86
87
88
89
90
	/**
	 * Allow access to certain variables that were previously public
	 *
	 * @return mixed
	 */
	public function __get( $var ) {
		if ( 'option_defaults' == $var )
			return $this->option_defaults;

		return false;
	}

Erick Hitter's avatar
Erick Hitter committed
91
	/**
92
	 * Run plugin cleanup on activation
93
	 * @uses this::cleanup
94
95
96
	 * @hook activation
	 * @return null
	 */
Erick Hitter's avatar
Erick Hitter committed
97
	public function activation_hook() {
98
99
100
		$this->cleanup();
	}

Erick Hitter's avatar
Erick Hitter committed
101
	/**
102
	 * Unregister widget when plugin is deactivated and run cleanup
103
	 * @uses this::cleanup
104
105
106
	 * @hook deactivation
	 * @return null
	 */
107
	public function deactivation_hook() {
108
109
110
		$this->cleanup();
	}

Erick Hitter's avatar
Erick Hitter committed
111
	/**
112
	 * Remove options related to plugin versions older than 2.0.
113
	 * @uses add_filter
114
115
116
	 * @uses delete_option
	 * @return null
	 */
Erick Hitter's avatar
Erick Hitter committed
117
	private function cleanup() {
118
119
120
		if ( ! add_filter( 'taxonomy_dropdown_widget_run_cleanup', true ) )
			return;

121
122
123
124
125
126
127
		$legacy_options = array(
			'widget_TagDropdown',
			'widget_TagDropdown_exclude',
			'function_TagDropdown',
			'TDW_direct'
		);

128
		foreach ( $legacy_options as $legacy_option ) {
129
			delete_option( $legacy_option );
130
		}
131
132
	}

Erick Hitter's avatar
Erick Hitter committed
133
	/**
134
135
136
137
138
	 * Register widget
	 * @uses register_widget
	 * @action widgets_init
	 * @return null
	 */
Erick Hitter's avatar
Erick Hitter committed
139
	public function action_widgets_init() {
140
		if ( class_exists( 'taxonomy_dropdown_widget' ) )
141
142
143
			register_widget( 'taxonomy_dropdown_widget' );
	}

Erick Hitter's avatar
Erick Hitter committed
144
	/**
145
146
147
	 * Render widget
	 * @param array $options
	 * @param string|int $id
Erick Hitter's avatar
Erick Hitter committed
148
149
150
151
152
153
154
155
156
157
	 * @uses wp_parse_args
	 * @uses sanitize_title
	 * @uses apply_filters
	 * @uses get_terms
	 * @uses is_wp_error
	 * @uses is_tag
	 * @uses is_tax
	 * @uses esc_url
	 * @uses get_term_link
	 * @uses selected
158
159
	 * @return string or false
	 */
Erick Hitter's avatar
Erick Hitter committed
160
	public function render_dropdown( $options, $id = false ) {
161
162
163
164
		$options = wp_parse_args( $options, $this->option_defaults );
		extract( $options );

		//ID
165
		if ( is_numeric( $id ) )
166
			$id = intval( $id );
167
		elseif ( is_string( $id ) )
168
169
170
171
172
173
174
175
176
177
			$id = sanitize_title( $id );

		//Set up options array for get_terms
		$options = array(
			'order' => $order,
			'orderby' => $orderby,
			'hide_empty' => $hide_empty,
			'hierarchical' => false
		);

178
		if ( $limit )
179
180
			$options[ 'number' ] = $limit;

181
		if ( !empty( $incexc_ids ) )
182
183
184
185
186
187
188
189
			$options[ $incexc ] = $incexc_ids;

		$options = apply_filters( 'taxonomy_dropdown_widget_options', $options, $id );
		$options = apply_filters( 'TagDropdown_get_tags', $options );

		//Get terms
		$terms = get_terms( $taxonomy, $options );

190
		if ( !is_wp_error( $terms ) && is_array( $terms ) && !empty( $terms ) ) {
191
			//CSS ID
192
			if ( is_int( $id ) )
193
				$css_id = ' id="taxonomy_dropdown_widget_dropdown_' . $id . '"';
194
			elseif ( is_string( $id ) && !empty( $id ) )
195
196
197
198
199
200
201
202
203
				$css_id = ' id="' . $id . '"';

			//Start dropdown
			$output = '<select name="taxonomy_dropdown_widget_dropdown_' . $id . '" class="taxonomy_dropdown_widget_dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"' . ( isset( $css_id ) ? $css_id : '' ) . '>';

			$output .= '<option value="">' . $select_name . '</option>';

			//Populate dropdown
			$i = 1;
204
205
			foreach ( $terms as $term ) {
				if ( $threshold > 0 && $term->count < $threshold )
206
207
208
209
210
211
212
213
214
215
					continue;

				//Set selected attribute if on an archive page for the current term
				$current = is_tag() ? is_tag( $term->slug ) : is_tax( $taxonomy, $term->slug );

				//Open option tag
				$output .= '<option value="' . esc_url( get_term_link( (int)$term->term_id, $taxonomy ) ) . '"' . ( selected( $current, true , false ) ) . '>';

				//Tag name
				$name = esc_attr( $term->name );
216
				if ( $max_name_length > 0 && strlen( $name ) > $max_name_length )
217
218
219
220
					$name = substr( $name, 0, $max_name_length ) . $cutoff;
				$output .= $name;

				//Count
221
				if ( $post_counts )
222
223
224
225
226
227
228
229
230
231
232
233
					$output .= ' (' . intval( $term->count ) . ')';

				//Close option tag
				$output .= '</option>';

				$i++;
			}

			//End dropdown
			$output .= '</select>';

			return $output;
234
		} else {
235
			return false;
236
		}
237
238
	}

Erick Hitter's avatar
Erick Hitter committed
239
	/**
240
241
	 * Sanitize plugin options
	 * @param array $options
Erick Hitter's avatar
Erick Hitter committed
242
243
244
245
	 * @uses taxonomy_exists
	 * @uses sanitize_text_field
	 * @uses absint
	 * @uses wp_parse_args
246
247
	 * @return array
	 */
Erick Hitter's avatar
Erick Hitter committed
248
	public function sanitize_options( $options ) {
249
250
251
252
253
254
255
		$options_sanitized = array(
			'hide_empty' => true,
			'post_counts' => false
		);

		$keys = array_merge( array_keys( $this->option_defaults ), array( 'title' ) );

256
257
258
		if ( is_array( $options ) ) {
			foreach ( $keys as $key ) {
				if ( !array_key_exists( $key, $options ) )
259
260
261
262
263
264
					continue;

				$value = $options[ $key ];

				switch( $key ) {
					case 'taxonomy':
265
						if ( taxonomy_exists( $value ) )
266
267
268
269
270
271
272
273
							$options_sanitized[ $key ] = $value;
					break;

					case 'title':
					case 'select_name':
					case 'cutoff':
						$value = sanitize_text_field( $value );

274
						if ( !empty( $value ) || $key == 'title' )
275
276
277
278
279
280
281
282
283
284
							$options_sanitized[ $key ] = $value;
					break;

					case 'max_name_length':
					case 'limit':
					case 'threshold':
						$options_sanitized[ $key ] = absint( $value );
					break;

					case 'order':
285
						if ( $value == 'ASC' || $value == 'DESC' )
286
287
288
289
							$options_sanitized[ $key ] = $value;
					break;

					case 'orderby':
290
						if ( $value == 'name' || $value == 'count' )
291
292
293
294
							$options_sanitized[ $key ] = $value;
					break;

					case 'incexc':
295
						if ( $value == 'include' || $value == 'exclude' )
296
297
298
299
300
301
							$options_sanitized[ $key ] = $value;
					break;

					case 'incexc_ids':
						$options_sanitized[ $key ] = array();

302
						if ( is_string( $value ) )
303
304
							$value = explode( ',', $value );

305
306
						if ( is_array( $value ) ) {
							foreach ( $value as $term_id ) {
307
308
								$term_id = intval( $term_id );

309
								if ( $term_id > 0 )
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
									$options_sanitized[ $key ][] = $term_id;

								unset( $term_id );
							}

							sort( $options_sanitized[ $key ], SORT_NUMERIC );
						}
					break;

					case 'hide_empty':
					case 'post_counts':
						$options_sanitized[ $key ] = (bool)$value;
					break;

					default:
						continue;
					break;
				}
			}
		}

		//Ensure array contains all keys by parsing against defaults after options are sanitized
		$options_sanitized = wp_parse_args( $options_sanitized, $this->option_defaults );

		return $options_sanitized;
	}
}
Erick Hitter's avatar
Erick Hitter committed
337
$GLOBALS['taxonomy_dropdown_widget_plugin'] = taxonomy_dropdown_widget_plugin::get_instance();
338
339
340
341
342

/**
 ** TAXONOMY DROPDOWN WIDGET
 **/
class taxonomy_dropdown_widget extends WP_Widget {
Erick Hitter's avatar
Erick Hitter committed
343
	/**
344
345
	 * Class variables
	 */
Erick Hitter's avatar
Erick Hitter committed
346
	private $defaults = array(
347
348
349
		'title' => 'Tags'
	);

Erick Hitter's avatar
Erick Hitter committed
350
	/**
351
	 * Register widget and populate class variables
Erick Hitter's avatar
Erick Hitter committed
352
353
	 * @uses this::WP_Widget
	 * @uses taxonomy_dropdown_widget_plugin
354
355
	 * @return null
	 */
Erick Hitter's avatar
Erick Hitter committed
356
	public function __construct() {
357
358
359
360
		$this->WP_Widget( false, 'Taxonomy Dropdown Widget', array( 'description' => 'Displays selected non-hierarchical taxonomy terms in a dropdown list.' ) );

		//Load plugin class and populate defaults
		global $taxonomy_dropdown_widget_plugin;
361
		if ( !is_a( $taxonomy_dropdown_widget_plugin, 'taxonomy_dropdown_widget_plugin' ) )
362
363
			$taxonomy_dropdown_widget_plugin = new taxonomy_dropdown_widget_plugin;

364
		if ( is_object( $taxonomy_dropdown_widget_plugin ) && property_exists( $taxonomy_dropdown_widget_plugin, 'option_defaults' ) && is_array( $taxonomy_dropdown_widget_plugin->option_defaults ) )
365
366
367
			$this->defaults = array_merge( $taxonomy_dropdown_widget_plugin->option_defaults, $this->defaults );
	}

Erick Hitter's avatar
Erick Hitter committed
368
	/**
369
370
371
	 * Render widget
	 * @param array $args
	 * @param array $instance
Erick Hitter's avatar
Erick Hitter committed
372
373
374
	 * @uses taxonomy_dropdown_widget_plugin
	 * @uses wp_parse_args
	 * @uses apply_filters
375
376
	 * @return string or null
	 */
Erick Hitter's avatar
Erick Hitter committed
377
	public function widget( $args, $instance ) {
378
379
		//Get plugin class for default options and to build widget
		global $taxonomy_dropdown_widget_plugin;
380
		if ( !is_a( $taxonomy_dropdown_widget_plugin, 'taxonomy_dropdown_widget_plugin' ) )
381
382
383
384
385
386
387
388
			$taxonomy_dropdown_widget_plugin = new taxonomy_dropdown_widget_plugin;

		//Options
		$instance = wp_parse_args( $instance, $this->defaults );
		extract( $args );
		extract( $instance );

		//Widget
389
		if ( $widget = $taxonomy_dropdown_widget_plugin->render_dropdown( $instance, $this->number ) ) {
390
391
392
			//Wrapper and title
			$output = $before_widget;

393
			if ( !empty( $title ) )
394
395
396
397
398
399
400
401
402
403
404
405
				$output .= $before_title . apply_filters( 'taxonomy_dropdown_widget_title', '<label for="taxonomy_dropdown_widget_dropdown_' . $this->number . '">' . $title . '</label>', $this->number ) . $after_title;

			//Widget
			$output .= $widget;

			//Wrapper
			$output .= $after_widget;

			echo $output;
		}
	}

Erick Hitter's avatar
Erick Hitter committed
406
	/**
407
408
409
	 * Options sanitization
	 * @param array $new_instance
	 * @param array $old_instance
Erick Hitter's avatar
Erick Hitter committed
410
	 * @uses taxonomy_dropdown_widget_plugin
411
412
	 * @return array
	 */
Erick Hitter's avatar
Erick Hitter committed
413
	public function update( $new_instance, $old_instance ) {
414
415
		//Get plugin class for sanitization function
		global $taxonomy_dropdown_widget_plugin;
416
		if ( !is_a( $taxonomy_dropdown_widget_plugin, 'taxonomy_dropdown_widget_plugin' ) )
417
418
419
420
421
			$taxonomy_dropdown_widget_plugin = new taxonomy_dropdown_widget_plugin;

		return $taxonomy_dropdown_widget_plugin->sanitize_options( $new_instance );
	}

Erick Hitter's avatar
Erick Hitter committed
422
	/**
423
424
	 * Widget options
	 * @param array $instance
Erick Hitter's avatar
Erick Hitter committed
425
426
427
428
429
430
431
432
	 * @uses wp_parse_args
	 * @uses get_taxonomies
	 * @uses _e
	 * @uses this::get_field_id
	 * @uses this::get_field_name
	 * @uses esc_attr
	 * @uses selected
	 * @uses checked
433
434
	 * @return string
	 */
Erick Hitter's avatar
Erick Hitter committed
435
	public function form( $instance ) {
436
437
438
439
440
441
442
443
444
445
		//Get options
		$options = wp_parse_args( $instance, $this->defaults );
		extract( $options );

		//Get taxonomies and remove certain Core taxonomies that shouldn't be accessed directly.
		$taxonomies = get_taxonomies( array(
			'public' => true,
			'hierarchical' => false
		), 'objects' );

446
		if ( array_key_exists( 'nav_menu', $taxonomies ) )
447
448
			unset( $taxonomies[ 'nav_menu' ] );

449
		if ( array_key_exists( 'post_format', $taxonomies ) )
450
451
452
453
454
455
456
457
			unset( $taxonomies[ 'post_format' ] );

	?>
		<h3><?php _e( 'Basic Settings' ); ?></h3>

		<p>
			<label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>"><?php _e( 'Taxonomy' ); ?>:</label><br />
			<select name="<?php echo $this->get_field_name( 'taxonomy' ); ?>" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>">
458
				<?php foreach ( $taxonomies as $tax ): ?>
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
					<option value="<?php echo esc_attr( $tax->name ); ?>"<?php selected( $tax->name, $taxonomy, true ); ?>><?php echo $tax->labels->name; ?></option>
				<?php endforeach; ?>
			</select>
		</p>

		<p>
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label><br />
			<input type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" class="widefat code" id="<?php echo $this->get_field_id( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>" />
		</p>

		<p>
			<label for="<?php echo $this->get_field_id( 'select_name' ); ?>"><?php _e( 'Default dropdown item:' ); ?></label><br />
			<input type="text" name="<?php echo $this->get_field_name( 'select_name' ); ?>" class="widefat code" id="<?php echo $this->get_field_id( 'select_name' ); ?>" value="<?php echo esc_attr( $select_name ); ?>" />
		</p>

		<h3><?php _e( 'Order' ); ?></h3>

		<p>
			<label><?php _e( 'Order terms by:' ); ?></label><br />

			<input type="radio" name="<?php echo $this->get_field_name( 'orderby' ); ?>" value="name" id="<?php echo $this->get_field_name( 'order_name' ); ?>"<?php checked( $orderby, 'name', true ); ?> />
			<label for="<?php echo $this->get_field_name( 'order_name' ); ?>"><?php _e( 'Name' ); ?></label><br />

			<input type="radio" name="<?php echo $this->get_field_name( 'orderby' ); ?>" value="count" id="<?php echo $this->get_field_name( 'order_count' ); ?>"<?php checked( $orderby, 'count', true ); ?> />
			<label for="<?php echo $this->get_field_name( 'order_count' ); ?>"><?php _e( 'Post count' ); ?></label>
		</p>

		<p>
			<label><?php _e( 'Order terms:' ); ?></label><br />

			<input type="radio" name="<?php echo $this->get_field_name( 'order' ); ?>" value="ASC" id="<?php echo $this->get_field_name( 'order_asc' ); ?>"<?php checked( $order, 'ASC', true ); ?> />
			<label for="<?php echo $this->get_field_name( 'order_asc' ); ?>"><?php _e( 'Ascending' ); ?></label><br />

			<input type="radio" name="<?php echo $this->get_field_name( 'order' ); ?>" value="DESC" id="<?php echo $this->get_field_name( 'order_desc' ); ?>"<?php checked( $order, 'DESC', true ); ?> />
			<label for="<?php echo $this->get_field_name( 'order_desc' ); ?>"><?php _e( 'Descending' ); ?></label>
		</p>

		<h3><?php _e( 'Term Display' ); ?></h3>

		<p>
			<label for="<?php echo $this->get_field_id( 'limit' ); ?>"><?php _e( 'Limit number of terms shown to:' ); ?></label><br />
			<input type="text" name="<?php echo $this->get_field_name( 'limit' ); ?>" id="<?php echo $this->get_field_id( 'limit' ); ?>" value="<?php echo intval( $limit ); ?>" size="3" /><br />
			<span class="description"><?php _e( '<small>Enter <strong>0</strong> for no limit.' ); ?></small></span>
		</p>

		<p>
			<label for="<?php echo $this->get_field_id( 'max_name_length' ); ?>"><?php _e( 'Trim long term names to <em>x</em> characters:</label>' ); ?><br />
			<input type="text" name="<?php echo $this->get_field_name( 'max_name_length' ); ?>" id="<?php echo $this->get_field_id( 'max_name_length' ); ?>" value="<?php echo intval( $max_name_length ); ?>" size="3" /><br />
			<span class="description"><?php _e( '<small>Enter <strong>0</strong> to show full tag names.' ); ?></small></span>
		</p>

		<p>
			<label for="<?php echo $this->get_field_id( 'cutoff' ); ?>"><?php _e( 'Indicator that term names are trimmed:' ); ?></label><br />
			<input type="text" name="<?php echo $this->get_field_name( 'cutoff' ); ?>" id="<?php echo $this->get_field_id( 'cutoff' ); ?>" value="<?php echo esc_attr( $cutoff ); ?>" size="3" /><br />
			<span class="description"><?php _e( '<small>Leave blank to use an elipsis (&hellip;).</small>' ); ?></span>
		</p>

		<p>
			<input type="checkbox" name="<?php echo $this->get_field_name( 'hide_empty' ); ?>" id="<?php echo $this->get_field_id( 'hide_empty' ); ?>"  value="0"<?php checked( false, $hide_empty, true ); ?> />
			<label for="<?php echo $this->get_field_id( 'hide_empty' ); ?>"><?php _e( 'Include terms that aren\'t assigned to any objects (empty terms).' ); ?></label>
		</p>

		<p>
			<input type="checkbox" name="<?php echo $this->get_field_name( 'post_counts' ); ?>" id="<?php echo $this->get_field_id( 'post_counts' ); ?>"  value="1"<?php checked( true, $post_counts, true ); ?> />
			<label for="<?php echo $this->get_field_id( 'post_counts' ); ?>"><?php _e( 'Display object (post) counts after term names.' ); ?></label>
		</p>

		<h3><?php _e( 'Include/Exclude Terms' ); ?></h3>

		<p>
			<label><?php _e( 'Include/exclude terms:' ); ?></label><br />

			<input type="radio" name="<?php echo $this->get_field_name( 'incexc' ); ?>" value="include" id="<?php echo $this->get_field_id( 'include' ); ?>"<?php checked( $incexc, 'include', true ); ?> />
			<label for="<?php echo $this->get_field_id( 'include' ); ?>"><?php _e( 'Include only the term IDs listed below' ); ?></label><br />

			<input type="radio" name="<?php echo $this->get_field_name( 'incexc' ); ?>" value="exclude" id="<?php echo $this->get_field_id( 'exclude' ); ?>"<?php checked( $incexc, 'exclude', true ); ?> />
			<label for="<?php echo $this->get_field_id( 'exclude' ); ?>"><?php _e( 'Exclude the term IDs listed below' ); ?></label>
		</p>

		<p>
			<label for="<?php echo $this->get_field_id( 'incexc_ids' ); ?>"><?php _e( 'Term IDs to include/exclude based on above setting:' ); ?></label><br />
			<input type="text" name="<?php echo $this->get_field_name( 'incexc_ids' ); ?>" class="widefat code" id="<?php echo $this->get_field_id( 'incexc_ids' ); ?>" value="<?php echo esc_attr( implode( ', ', $incexc_ids ) ); ?>" /><br />
			<span class="description"><?php _e( '<small>Enter comma-separated list of term IDs.</small>' ); ?></span>
		</p>

		<h3><?php _e( 'Advanced' ); ?></h3>

		<p>
			<label for="<?php echo $this->get_field_id( 'threshold' ); ?>"><?php _e( 'Show terms assigned to at least this many posts:' ); ?></label><br />
			<input type="text" name="<?php echo $this->get_field_name( 'threshold' ); ?>" id="<?php echo $this->get_field_id( 'threshold' ); ?>" value="<?php echo intval( $threshold ); ?>" size="3" /><br />
			<span class="description"><?php _e( '<small>Set to <strong>0</strong> to display all terms matching the above criteria.</small>' ); ?></span>
		</p>

	<?php
	}
}

/**
 ** HELPER FUNCTIONS
 **/

Erick Hitter's avatar
Erick Hitter committed
560
/**
561
562
563
 * Render taxonomy dropdown
 * @param array $options
 * @param string|int $id
Erick Hitter's avatar
Erick Hitter committed
564
 * @uses taxonomy_dropdown_widget_plugin::get_instance
565
566
567
 * @return string or false
 */
function taxonomy_dropdown_widget( $options = array(), $id = '' ) {
Erick Hitter's avatar
Erick Hitter committed
568
569
	// Sanitize options
	$options = taxonomy_dropdown_widget_plugin::get_instance()->sanitize_options( $options );
570

Erick Hitter's avatar
Erick Hitter committed
571
	return taxonomy_dropdown_widget_plugin::get_instance()->render_dropdown( $options, $id );
572
573
574
575
576
577
}

/**
 ** LEGACY FUNCTIONS FOR BACKWARDS COMPATIBILITY
 **/

578
if ( !function_exists( 'generateTagDropdown' ) ):
Erick Hitter's avatar
Erick Hitter committed
579
	/**
580
581
	 * Build tag dropdown based on provided arguments
	 * @since 1.7
582
	 * @uses _deprecated_function
Erick Hitter's avatar
Erick Hitter committed
583
	 * @uses taxonomy_dropdown_widget_plugin::get_instance
584
585
586
	 * @return string or false
	 */
	function generateTagDropdown( $args ) {
587
588
		_deprecated_function( 'generateTagDropdown', '2.0 of Taxonomy (Tag) Dropdown Widget', 'taxonomy_dropdown_widget' );

Erick Hitter's avatar
Erick Hitter committed
589
590
		// Sanitize options
		$options = taxonomy_dropdown_widget_plugin::get_instance()->sanitize_options( $args );
591

Erick Hitter's avatar
Erick Hitter committed
592
		return '<!-- NOTICE: The function used to generate this dropdown list is deprecated as of version 2.0 of Taxonomy Dropdown Widget. You should update your template to use `taxonomy_dropdown_widget` instead. -->' . taxonomy_dropdown_widget_plugin::get_instance()->render_dropdown( $options, 'legacy_gtd' );
593
594
595
	}
endif;

596
if ( !function_exists( 'TDW_direct' ) ):
Erick Hitter's avatar
Erick Hitter committed
597
	/**
598
599
	 * Build tag dropdown based on provided arguments
	 * @since 1.6
600
	 * @uses _deprecated_function
Erick Hitter's avatar
Erick Hitter committed
601
	 * @uses taxonomy_dropdown_widget_plugin::get_instance
602
603
604
	 * @return string or false
	 */
	function TDW_direct( $limit = false, $count = false, $exclude = false ) {
605
606
		_deprecated_function( 'TDW_direct', '1.7 of Taxonomy (Tag) Dropdown Widget', 'taxonomy_dropdown_widget' );

Erick Hitter's avatar
Erick Hitter committed
607
		// Build options array from function parameters
608
609
		$options = array(
			'max_name_length' => $limit,
Erick Hitter's avatar
Erick Hitter committed
610
			'post_count'      => $count
611
612
		);

613
		if ( $exclude ) {
Erick Hitter's avatar
Erick Hitter committed
614
			$options[ 'incexc' ]     = 'exclude';
615
616
617
618
			$options[ 'incexc_ids' ] = $exclude;
		}

		//Sanitize options
Erick Hitter's avatar
Erick Hitter committed
619
		$options = taxonomy_dropdown_widget_plugin::get_instance()->sanitize_options( $options );
620

Erick Hitter's avatar
Erick Hitter committed
621
		echo '<!-- NOTICE: The function used to generate this dropdown list is deprecated as of version 1.7 of Taxonomy Dropdown Widget. You should update your template to use `taxonomy_dropdown_widget` instead. -->' . taxonomy_dropdown_widget_plugin::get_instance()->render_dropdown( $options, 'legacy_tdw' );
622
623
624
	}
endif;

625
if ( !function_exists( 'makeTagDropdown' ) ):
Erick Hitter's avatar
Erick Hitter committed
626
	/**
627
628
	 * Build tag dropdown based on provided arguments
	 * @since 1.3
629
	 * @uses _deprecated_function
Erick Hitter's avatar
Erick Hitter committed
630
	 * @uses taxonomy_dropdown_widget_plugin::get_instance
631
632
633
	 * @return string or false
	 */
	function makeTagDropdown( $limit = false ) {
634
635
636
		_deprecated_function( 'makeTagDropdown', '1.6 of Taxonomy (Tag) Dropdown Widget', 'taxonomy_dropdown_widget' );

		// Sanitize options
637
638
639
640
		$options = array(
			'max_name_length' => intval( $limit )
		);

Erick Hitter's avatar
Erick Hitter committed
641
		echo '<!-- NOTICE: The function used to generate this dropdown list is deprecated as of version 1.6 of Taxonomy Dropdown Widget. You should update your template to use `taxonomy_dropdown_widget` instead. -->' . taxonomy_dropdown_widget_plugin::get_instance()->render_dropdown( $options, 'legacy_mtd' );
642
643
644
}
endif;
?>