16 * @see wp_category_checklist() |
16 * @see wp_category_checklist() |
17 * @see wp_terms_checklist() |
17 * @see wp_terms_checklist() |
18 */ |
18 */ |
19 class Walker_Category_Checklist extends Walker { |
19 class Walker_Category_Checklist extends Walker { |
20 public $tree_type = 'category'; |
20 public $tree_type = 'category'; |
21 public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this |
21 public $db_fields = array( |
|
22 'parent' => 'parent', |
|
23 'id' => 'term_id', |
|
24 ); //TODO: decouple this |
22 |
25 |
23 /** |
26 /** |
24 * Starts the list before the elements are added. |
27 * Starts the list before the elements are added. |
25 * |
28 * |
26 * @see Walker:start_lvl() |
29 * @see Walker:start_lvl() |
30 * @param string $output Used to append additional content (passed by reference). |
33 * @param string $output Used to append additional content (passed by reference). |
31 * @param int $depth Depth of category. Used for tab indentation. |
34 * @param int $depth Depth of category. Used for tab indentation. |
32 * @param array $args An array of arguments. @see wp_terms_checklist() |
35 * @param array $args An array of arguments. @see wp_terms_checklist() |
33 */ |
36 */ |
34 public function start_lvl( &$output, $depth = 0, $args = array() ) { |
37 public function start_lvl( &$output, $depth = 0, $args = array() ) { |
35 $indent = str_repeat("\t", $depth); |
38 $indent = str_repeat( "\t", $depth ); |
36 $output .= "$indent<ul class='children'>\n"; |
39 $output .= "$indent<ul class='children'>\n"; |
37 } |
40 } |
38 |
41 |
39 /** |
42 /** |
40 * Ends the list of after the elements are added. |
43 * Ends the list of after the elements are added. |
46 * @param string $output Used to append additional content (passed by reference). |
49 * @param string $output Used to append additional content (passed by reference). |
47 * @param int $depth Depth of category. Used for tab indentation. |
50 * @param int $depth Depth of category. Used for tab indentation. |
48 * @param array $args An array of arguments. @see wp_terms_checklist() |
51 * @param array $args An array of arguments. @see wp_terms_checklist() |
49 */ |
52 */ |
50 public function end_lvl( &$output, $depth = 0, $args = array() ) { |
53 public function end_lvl( &$output, $depth = 0, $args = array() ) { |
51 $indent = str_repeat("\t", $depth); |
54 $indent = str_repeat( "\t", $depth ); |
52 $output .= "$indent</ul>\n"; |
55 $output .= "$indent</ul>\n"; |
53 } |
56 } |
54 |
57 |
55 /** |
58 /** |
56 * Start the element output. |
59 * Start the element output. |
77 } else { |
80 } else { |
78 $name = 'tax_input[' . $taxonomy . ']'; |
81 $name = 'tax_input[' . $taxonomy . ']'; |
79 } |
82 } |
80 |
83 |
81 $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats']; |
84 $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats']; |
82 $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : ''; |
85 $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : ''; |
83 |
86 |
84 $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats']; |
87 $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats']; |
85 |
88 |
86 if ( ! empty( $args['list_only'] ) ) { |
89 if ( ! empty( $args['list_only'] ) ) { |
87 $aria_checked = 'false'; |
90 $aria_checked = 'false'; |
88 $inner_class = 'category'; |
91 $inner_class = 'category'; |
89 |
92 |
90 if ( in_array( $category->term_id, $args['selected_cats'] ) ) { |
93 if ( in_array( $category->term_id, $args['selected_cats'] ) ) { |
91 $inner_class .= ' selected'; |
94 $inner_class .= ' selected'; |
92 $aria_checked = 'true'; |
95 $aria_checked = 'true'; |
93 } |
96 } |
98 ' tabindex="0" role="checkbox" aria-checked="' . $aria_checked . '">' . |
101 ' tabindex="0" role="checkbox" aria-checked="' . $aria_checked . '">' . |
99 esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</div>'; |
102 esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</div>'; |
100 } else { |
103 } else { |
101 /** This filter is documented in wp-includes/category-template.php */ |
104 /** This filter is documented in wp-includes/category-template.php */ |
102 $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . |
105 $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 . '"' . |
106 '<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 ) . |
107 checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) . |
105 disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . |
108 disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . |
106 esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</label>'; |
109 esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</label>'; |
107 } |
110 } |
108 } |
111 } |