#50771 closed enhancement (wontfix)
WP_Comment protected $children
Reported by: | Tkama | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.4.2 |
Component: | Comments | Keywords: | |
Focuses: | Cc: |
Description
Why we need $children
prop of WP_Comment
class to be protected?
It's very inconvenient in some cases, for example, I use get_comments()
with hierarchical => threaded
param and get comment objects which contains nested comments:
// I delete some fields of WP_Comment Object for convenience.
Array
[22986] => WP_Comment Object
[comment_ID] => 22986
[comment_post_ID] => 8342
[comment_author] => camp
[comment_date] => 2018-04-11 19:07:08
[comment_content] => Добавлено.
[comment_type] =>
[comment_parent] => 22430
[populated_children:protected] => 1
[children:protected] => Array
[22998] => WP_Comment Object
[comment_ID] => 22998
[comment_post_ID] => 8342
[comment_author] => Максим
[comment_date] => 2018-04-12 12:15:25
[comment_content] => Работает отлично. Спасибо!
[comment_type] =>
[comment_parent] => 22986
[populated_children:protected] => 1
[children:protected] => Array
[23035] => WP_Comment Object
[comment_ID] => 23035
[comment_post_ID] => 8342
[comment_author] => camp
[comment_date] => 2018-04-16 15:36:00
[comment_content] => Спасибо за обратную связь!
[comment_type] =>
[comment_parent] => 22998
[children:protected] =>
[populated_children:protected] => 1
Now I want to use this nested data, but I can't access it.
Maybe make $children
prop public?
Change History (3)
Note: See
TracTickets for help on using
tickets.
Thanks for the ticket!
Replying to Tkama:
You should be able to access it with the WP_Comment::get_children() method:
https://wordpress.stackexchange.com/questions/301190/how-to-check-if-a-comment-has-replies/356389#356389