]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/class-walker-category-dropdown.php
Wordpress 4.5.3
[autoinstalls/wordpress.git] / wp-includes / class-walker-category-dropdown.php
1 <?php
2 /**
3  * Taxonomy API: Walker_CategoryDropdown class
4  *
5  * @package WordPress
6  * @subpackage Template
7  * @since 4.4.0
8  */
9
10 /**
11  * Core class used to create an HTML dropdown list of Categories.
12  *
13  * @since 2.1.0
14  *
15  * @see Walker
16  */
17 class Walker_CategoryDropdown extends Walker {
18
19         /**
20          * What the class handles.
21          *
22          * @since 2.1.0
23          * @access private
24          * @var string
25          *
26          * @see Walker::$tree_type
27          */
28         public $tree_type = 'category';
29
30         /**
31          * Database fields to use.
32          *
33          * @since 2.1.0
34          * @access public
35          * @todo Decouple this
36          * @var array
37          *
38          * @see Walker::$db_fields
39          */
40         public $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
41
42         /**
43          * Starts the element output.
44          *
45          * @since 2.1.0
46          * @access public
47          *
48          * @see Walker::start_el()
49          *
50          * @param string $output   Passed by reference. Used to append additional content.
51          * @param object $category Category data object.
52          * @param int    $depth    Depth of category. Used for padding.
53          * @param array  $args     Uses 'selected', 'show_count', and 'value_field' keys, if they exist.
54          *                         See wp_dropdown_categories().
55          * @param int    $id       Optional. ID of the current category. Default 0 (unused).
56          */
57         public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
58                 $pad = str_repeat('&nbsp;', $depth * 3);
59
60                 /** This filter is documented in wp-includes/category-template.php */
61                 $cat_name = apply_filters( 'list_cats', $category->name, $category );
62
63                 if ( isset( $args['value_field'] ) && isset( $category->{$args['value_field']} ) ) {
64                         $value_field = $args['value_field'];
65                 } else {
66                         $value_field = 'term_id';
67                 }
68
69                 $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$value_field} ) . "\"";
70
71                 // Type-juggling causes false matches, so we force everything to a string.
72                 if ( (string) $category->{$value_field} === (string) $args['selected'] )
73                         $output .= ' selected="selected"';
74                 $output .= '>';
75                 $output .= $pad.$cat_name;
76                 if ( $args['show_count'] )
77                         $output .= '&nbsp;&nbsp;('. number_format_i18n( $category->count ) .')';
78                 $output .= "</option>\n";
79         }
80 }