3 * Taxonomy API: Walker_Category_Checklist class
6 * @subpackage Administration
11 * Core walker class to output an unordered list of category checkbox input elements.
16 * @see wp_category_checklist()
17 * @see wp_terms_checklist()
19 class Walker_Category_Checklist extends Walker {
20 public $tree_type = 'category';
21 public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
24 * Starts the list before the elements are added.
26 * @see Walker:start_lvl()
30 * @param string $output Passed by reference. Used to append additional content.
31 * @param int $depth Depth of category. Used for tab indentation.
32 * @param array $args An array of arguments. @see wp_terms_checklist()
34 public function start_lvl( &$output, $depth = 0, $args = array() ) {
35 $indent = str_repeat("\t", $depth);
36 $output .= "$indent<ul class='children'>\n";
40 * Ends the list of after the elements are added.
42 * @see Walker::end_lvl()
46 * @param string $output Passed by reference. Used to append additional content.
47 * @param int $depth Depth of category. Used for tab indentation.
48 * @param array $args An array of arguments. @see wp_terms_checklist()
50 public function end_lvl( &$output, $depth = 0, $args = array() ) {
51 $indent = str_repeat("\t", $depth);
52 $output .= "$indent</ul>\n";
56 * Start the element output.
58 * @see Walker::start_el()
62 * @param string $output Passed by reference. Used to append additional content.
63 * @param object $category The current term object.
64 * @param int $depth Depth of the term in reference to parents. Default 0.
65 * @param array $args An array of arguments. @see wp_terms_checklist()
66 * @param int $id ID of the current term.
68 public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
69 if ( empty( $args['taxonomy'] ) ) {
70 $taxonomy = 'category';
72 $taxonomy = $args['taxonomy'];
75 if ( $taxonomy == 'category' ) {
76 $name = 'post_category';
78 $name = 'tax_input[' . $taxonomy . ']';
81 $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
82 $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
84 $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
86 if ( ! empty( $args['list_only'] ) ) {
87 $aria_cheched = 'false';
88 $inner_class = 'category';
90 if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
91 $inner_class .= ' selected';
92 $aria_cheched = 'true';
95 /** This filter is documented in wp-includes/category-template.php */
96 $output .= "\n" . '<li' . $class . '>' .
97 '<div class="' . $inner_class . '" data-term-id=' . $category->term_id .
98 ' tabindex="0" role="checkbox" aria-checked="' . $aria_cheched . '">' .
99 esc_html( apply_filters( 'the_category', $category->name ) ) . '</div>';
101 /** This filter is documented in wp-includes/category-template.php */
102 $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
103 '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' .
104 checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
105 disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
106 esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
111 * Ends the element output, if needed.
113 * @see Walker::end_el()
117 * @param string $output Passed by reference. Used to append additional content.
118 * @param object $category The current term object.
119 * @param int $depth Depth of the term in reference to parents. Default 0.
120 * @param array $args An array of arguments. @see wp_terms_checklist()
122 public function end_el( &$output, $category, $depth = 0, $args = array() ) {
123 $output .= "</li>\n";