There’s no such thing as a depth 0 comment, and it should never happen, here is your problem:
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
$output .= var_dump($depth);
No depth incrementing is happening so it is always 0. start_el
has several responsibilities as part of the walking, and for comment loop setup.
If we look at the start_el
method of the Walker_Comment
class, the first thing it does is increment the depth and set the necessary global variables:
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
// Restores the more descriptive, specific name for use within this method.
$comment = $data_object;
$depth++;
$GLOBALS['comment_depth'] = $depth;
$GLOBALS['comment'] = $comment;
Since yours doesn’t do this, $depth
will never be incremented no matter how deep the walker goes, and will always remain at the default 0
. You should also expect lots of PHP warnings as a result of the globals being undefined.
However, if implemented correctly, $depth
will always be 1
or higher, and get_comment_reply_link
will never receive a 0
value.
This and other functions need to do several other things as well to behave correctly as a comment walker. As a rule of thumb, copy paste the entirety of the method you’re replacing in your custom walker, then modify it, but don’t delete it entirely and start from scratch.