Skip to:
Content

BuddyPress.org

Opened 11 months ago

Closed 3 weeks ago

#9270 closed defect (bug) (fixed)

Returns false when it should return an empty array.

Reported by: alexanderwbell's profile alexanderwbell Owned by: espellcaste's profile espellcaste
Milestone: 15.0.0 Priority: normal
Severity: minor Version: 14.3.2
Component: Activity Keywords: has-patch
Cc:

Description

When the activity item was cached and has no comments, we still need to return an empty array, just like how the rest of the function returns an empty array when there are no comments. Other functions depend on this being the case. For example, line 2618 in bp-activity-template.php in the function bp_activity_get_comment_depth will throw an error if this is not the case. We could also set bp_activity_get_comment_depth to check if $comments returned is false in that function and set it to an empty array.

But in this version, we return $comments (which is an empty array) instead of false on line 1649 (I believe) of class-bp-activity-activity.php in the public static function get_activity_comments.

if ( 'none' === $comments_cache ) {

return false;

}
Should I believe be:

if ( 'none' === $comments_cache ) {

return $comments;

}

Or we should check in
bp_activity_get_comment_depth
If the returned $comments is false and set it to an array.

Check github pull request.

Change History (3)

This ticket was mentioned in PR #405 on buddypress/buddypress by Alexanderwbell.


11 months ago
#1

  • Keywords has-patch added; needs-patch removed

https://buddypress.trac.wordpress.org/ticket/9270#ticket

When the activity item was cached and has no comments, we still need to return an empty array, just like how the rest of the function returns an empty array when there are no comments. Other functions depend on this being the case. For example, line 2618 in bp-activity-template.php in the function bp_activity_get_comment_depth will throw an error if this is not the case. We could also set bp_activity_get_comment_depth to check if $comments returned is false in that function and set it to an empty array.

But in this version, we return $comments (which is an empty array) instead of false on line 1649 (I believe) of class-bp-activity-activity.php in the public static function get_activity_comments.

Trac ticket:

#2 @espellcaste
3 weeks ago

  • Milestone changed from Awaiting Review to 15.0.0

This makes sense to me. In the original implementation, the false made sense. See [13312], but the implementation was changed at [13312].

For BP 14.5.0, this should not be an issue since [14149]. So I'll apply this patch to 15.0 only.

#3 @espellcaste
3 weeks ago

  • Owner set to espellcaste
  • Resolution set to fixed
  • Status changed from new to closed

In 14160:

Return an empty array (instead of false) when BP_Activity_Activity::get_activity_comments has no comments.

Previously, the method would return a boolean false when there was no cached comments. The false had meaning before, see [13312]. But it got changed at [13312].

Props alexanderwbell.

Closes https://github.com/buddypress/buddypress/pull/405
Fixes #9270.

Note: See TracTickets for help on using tickets.