Rest_BBP_Walker_Reply
Create hierarchical list of bbPress replies.
Description
Source
File: bp-forums/classes/class-bp-rest-bbp-walker-reply.php
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | class Rest_BBP_Walker_Reply extends Walker { /** * @see Walker::$tree_type * * @since 2.4.0 bbPress (r4944) * * @var string */ public $tree_type = 'reply' ; /** * @see Walker::$db_fields * * @since 2.4.0 bbPress (r4944) * * @var array */ public $db_fields = array ( 'parent' => 'reply_to' , 'id' => 'ID' , ); /** * Confirm the tree_type * * @since 2.6.0 bbPress (r5389) */ public function __construct() { $this ->tree_type = bbp_get_reply_post_type(); } /** * @see Walker::start_lvl() * * @since 2.4.0 bbPress (r4944) * * @param string $output Passed by reference. Used to append additional content * @param int $depth Depth of reply * @param array $args Uses 'style' argument for type of HTML list */ public function start_lvl( & $output = '' , $depth = 0, $args = array () ) { bbpress()->reply_query->reply_depth = (int) $depth + 1; } /** * @see Walker::end_lvl() * * @since 2.4.0 bbPress (r4944) * * @param string $output Passed by reference. Used to append additional content * @param int $depth Depth of reply * @param array $args Will only append content if style argument value is 'ol' or 'ul' */ public function end_lvl( & $output = '' , $depth = 0, $args = array () ) { bbpress()->reply_query->reply_depth = (int) $depth + 1; } /** * @since 2.4.0 bbPress (r4944) */ public function display_element( $element = false, & $children_elements = array (), $max_depth = 0, $depth = 0, $args = array (), & $output = '' ) { if ( empty ( $element ) ) { return ; } // Get element's id $id_field = $this ->db_fields[ 'id' ]; $id = $element -> $id_field ; // Display element parent::display_element( $element , $children_elements , $max_depth , $depth , $args , $output ); // If we're at the max depth and the current element still has children, loop over those // and display them at this level to prevent them being orphaned to the end of the list. if ( ( $max_depth <= (int) $depth + 1 ) && isset( $children_elements [ $id ] ) ) { foreach ( $children_elements [ $id ] as $child ) { $this ->display_element( $child , $children_elements , $max_depth , $depth , $args , $output ); } unset( $children_elements [ $id ] ); } } /** * @see Walker:start_el() * * @since 2.4.0 bbPress (r4944) */ public function start_el( & $output , $object , $depth = 0, $args = array (), $current_object_id = 0 ) { global $buddyboss_thread_reply ; // Set up reply $depth ++; $object ->depth = $depth ; $buddyboss_thread_reply [ $object ->ID ] = $object ; } /** * @since 2.4.0 bbPress (r4944) */ public function end_el( & $output = '' , $object = false, $depth = 0, $args = array () ) { } } |
Changelog
Version | Description |
---|---|
0.1.0 | Introduced. |
Methods
- __construct — Confirm the tree_type
- display_element
- end_el
- end_lvl
- start_el
- start_lvl
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.