WPCOM_JSON_API_List_Comments_Walker

The Jetpack by WordPress.com WPCOM JSON API List Comments Walker class.

Defined (1)

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

/json-endpoints/class.wpcom-json-api-list-comments-endpoint.php  
  1. class WPCOM_JSON_API_List_Comments_Walker extends Walker { 
  2. public $tree_type = 'comment'; 
  3.  
  4. public $db_fields = array( 
  5. 'parent' => 'comment_parent',  
  6. 'id' => 'comment_ID' 
  7. ); 
  8.  
  9. public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { 
  10. $output[] = $object->comment_ID; 
  11.  
  12. /** 
  13. * Taken from WordPress's Walker_Comment::display_element() 
  14. * This function is designed to enhance Walker::display_element() to 
  15. * display children of higher nesting levels than selected inline on 
  16. * the highest depth level displayed. This prevents them being orphaned 
  17. * at the end of the comment list. 
  18. * Example: max_depth = 2, with 5 levels of nested content. 
  19. * 1 
  20. * 1.1 
  21. * 1.1.1 
  22. * 1.1.1.1 
  23. * 1.1.1.1.1 
  24. * 1.1.2 
  25. * 1.1.2.1 
  26. * 2 
  27. * 2.2 
  28. * @see Walker_Comment::display_element() 
  29. * @see Walker::display_element() 
  30. * @see wp_list_comments() 
  31. */ 
  32. public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { 
  33.  
  34. if ( !$element ) 
  35. return; 
  36.  
  37. $id_field = $this->db_fields['id']; 
  38. $id = $element->$id_field; 
  39.  
  40. parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); 
  41.  
  42. // If we're at the max depth, and the current element still has children, loop over those and display them at this level 
  43. // This is to prevent them being orphaned to the end of the list. 
  44. if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) { 
  45. foreach ( $children_elements[ $id ] as $child ) 
  46. $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output ); 
  47.  
  48. unset( $children_elements[ $id ] ); 
  49.