BP_Walker_Category_Checklist

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

Defined (1)

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

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