BBP_Walker_Reply

Create hierarchical list of bbPress replies.

Defined (1)

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

/includes/common/classes.php  
  1. class BBP_Walker_Reply extends Walker { 
  2.  
  3. /** 
  4. * @see Walker::$tree_type 
  5. * @since bbPress (r4944) 
  6. * @var string 
  7. */ 
  8. var $tree_type = 'reply'; 
  9.  
  10. /** 
  11. * @see Walker::$db_fields 
  12. * @since bbPress (r4944) 
  13. * @var array 
  14. */ 
  15. var $db_fields = array( 
  16. 'parent' => 'reply_to',  
  17. 'id' => 'ID' 
  18. ); 
  19.  
  20. /** 
  21. * @see Walker::start_lvl() 
  22. * @since bbPress (r4944) 
  23. * @param string $output Passed by reference. Used to append additional content 
  24. * @param int $depth Depth of reply 
  25. * @param array $args Uses 'style' argument for type of HTML list 
  26. */ 
  27. public function start_lvl( &$output = '', $depth = 0, $args = array() ) { 
  28. bbpress()->reply_query->reply_depth = $depth + 1; 
  29.  
  30. switch ( $args['style'] ) { 
  31. case 'div': 
  32. break; 
  33. case 'ol': 
  34. echo "<ol class='bbp-threaded-replies'>\n"; 
  35. break; 
  36. case 'ul': 
  37. default: 
  38. echo "<ul class='bbp-threaded-replies'>\n"; 
  39. break; 
  40.  
  41. /** 
  42. * @see Walker::end_lvl() 
  43. * @since bbPress (r4944) 
  44. * @param string $output Passed by reference. Used to append additional content 
  45. * @param int $depth Depth of reply 
  46. * @param array $args Will only append content if style argument value is 'ol' or 'ul' 
  47. */ 
  48. public function end_lvl( &$output = '', $depth = 0, $args = array() ) { 
  49. bbpress()->reply_query->reply_depth = (int) $depth + 1; 
  50.  
  51. switch ( $args['style'] ) { 
  52. case 'div': 
  53. break; 
  54. case 'ol': 
  55. echo "</ol>\n"; 
  56. break; 
  57. case 'ul': 
  58. default: 
  59. echo "</ul>\n"; 
  60. break; 
  61.  
  62. /** 
  63. * @since bbPress (r4944) 
  64. */ 
  65. public function display_element( $element = false, &$children_elements = array(), $max_depth = 0, $depth = 0, $args = array(), &$output = '' ) { 
  66.  
  67. if ( empty( $element ) ) 
  68. return; 
  69.  
  70. // Get element's id 
  71. $id_field = $this->db_fields['id']; 
  72. $id = $element->$id_field; 
  73.  
  74. // Display element 
  75. parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); 
  76.  
  77. // If we're at the max depth and the current element still has children, loop over those 
  78. // and display them at this level to prevent them being orphaned to the end of the list. 
  79. if ( ( $max_depth <= (int) $depth + 1 ) && isset( $children_elements[$id] ) ) { 
  80. foreach ( $children_elements[$id] as $child ) { 
  81. $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output ); 
  82. unset( $children_elements[$id] ); 
  83.  
  84. /** 
  85. * @see Walker:start_el() 
  86. * @since bbPress (r4944) 
  87. */ 
  88. public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { 
  89.  
  90. // Set up reply 
  91. $depth++; 
  92. bbpress()->reply_query->reply_depth = $depth; 
  93. bbpress()->reply_query->post = $object; 
  94. bbpress()->current_reply_id = $object->ID; 
  95.  
  96. // Check for a callback and use it if specified 
  97. if ( !empty( $args['callback'] ) ) { 
  98. call_user_func( $args['callback'], $object, $args, $depth ); 
  99. return; 
  100.  
  101. // Style for div or list element 
  102. if ( !empty( $args['style'] ) && ( 'div' === $args['style'] ) ) { 
  103. echo "<div>\n"; 
  104. } else { 
  105. echo "<li>\n"; 
  106.  
  107. bbp_get_template_part( 'loop', 'single-reply' ); 
  108.  
  109. /** 
  110. * @since bbPress (r4944) 
  111. */ 
  112. public function end_el( &$output = '', $object = false, $depth = 0, $args = array() ) { 
  113.  
  114. // Check for a callback and use it if specified 
  115. if ( !empty( $args['end-callback'] ) ) { 
  116. call_user_func( $args['end-callback'], $object, $args, $depth ); 
  117. return; 
  118.  
  119. // Style for div or list element 
  120. if ( !empty( $args['style'] ) && ( 'div' === $args['style'] ) ) { 
  121. echo "</div>\n"; 
  122. } else { 
  123. echo "</li>\n";