Walker_Category_Checklist

Core walker class to output an unordered list of category checkbox input elements.

Defined (1)

The class is defined in the following location(s).

/wp-admin/includes/class-walker-category-checklist.php  
  1. class Walker_Category_Checklist extends Walker { 
  2. public $tree_type = 'category'; 
  3. public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this 
  4.  
  5. /** 
  6. * Starts the list before the elements are added. 
  7. * @see Walker:start_lvl() 
  8. * @since 2.5.1 
  9. * @param string $output Passed by reference. Used to append additional content. 
  10. * @param int $depth Depth of category. Used for tab indentation. 
  11. * @param array $args An array of arguments. @see wp_terms_checklist() 
  12. */ 
  13. public function start_lvl( &$output, $depth = 0, $args = array() ) { 
  14. $indent = str_repeat("\t", $depth); 
  15. $output .= "$indent<ul class='children'>\n"; 
  16.  
  17. /** 
  18. * Ends the list of after the elements are added. 
  19. * @see Walker::end_lvl() 
  20. * @since 2.5.1 
  21. * @param string $output Passed by reference. Used to append additional content. 
  22. * @param int $depth Depth of category. Used for tab indentation. 
  23. * @param array $args An array of arguments. @see wp_terms_checklist() 
  24. */ 
  25. public function end_lvl( &$output, $depth = 0, $args = array() ) { 
  26. $indent = str_repeat("\t", $depth); 
  27. $output .= "$indent</ul>\n"; 
  28.  
  29. /** 
  30. * Start the element output. 
  31. * @see Walker::start_el() 
  32. * @since 2.5.1 
  33. * @param string $output Passed by reference. Used to append additional content. 
  34. * @param object $category The current term object. 
  35. * @param int $depth Depth of the term in reference to parents. Default 0. 
  36. * @param array $args An array of arguments. @see wp_terms_checklist() 
  37. * @param int $id ID of the current term. 
  38. */ 
  39. public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { 
  40. if ( empty( $args['taxonomy'] ) ) { 
  41. $taxonomy = 'category'; 
  42. } else { 
  43. $taxonomy = $args['taxonomy']; 
  44.  
  45. if ( $taxonomy == 'category' ) { 
  46. $name = 'post_category'; 
  47. } else { 
  48. $name = 'tax_input[' . $taxonomy . ']'; 
  49.  
  50. $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats']; 
  51. $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : ''; 
  52.  
  53. $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats']; 
  54.  
  55. if ( ! empty( $args['list_only'] ) ) { 
  56. $aria_cheched = 'false'; 
  57. $inner_class = 'category'; 
  58.  
  59. if ( in_array( $category->term_id, $args['selected_cats'] ) ) { 
  60. $inner_class .= ' selected'; 
  61. $aria_cheched = 'true'; 
  62.  
  63. /** This filter is documented in wp-includes/category-template.php */ 
  64. $output .= "\n" . '<li' . $class . '>' . 
  65. '<div class="' . $inner_class . '" data-term-id=' . $category->term_id . 
  66. ' tabindex="0" role="checkbox" aria-checked="' . $aria_cheched . '">' . 
  67. esc_html( apply_filters( 'the_category', $category->name ) ) . '</div>'; 
  68. } else { 
  69. /** This filter is documented in wp-includes/category-template.php */ 
  70. $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . 
  71. '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . 
  72. checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) . 
  73. disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . 
  74. esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>'; 
  75.  
  76. /** 
  77. * Ends the element output, if needed. 
  78. * @see Walker::end_el() 
  79. * @since 2.5.1 
  80. * @param string $output Passed by reference. Used to append additional content. 
  81. * @param object $category The current term object. 
  82. * @param int $depth Depth of the term in reference to parents. Default 0. 
  83. * @param array $args An array of arguments. @see wp_terms_checklist() 
  84. */ 
  85. public function end_el( &$output, $category, $depth = 0, $args = array() ) { 
  86. $output .= "</li>\n";