Skip to:
Content

BuddyPress.org

Changeset 13309


Ignore:
Timestamp:
08/08/2022 09:24:03 PM (4 years ago)
Author:
imath
Message:

Adapt to WP Cache API latest change about cache key requirements

In WordPress 6.1, a cache key needs to be an integer or a "not empty" string. See WP53818 changeset.

After analysing the failing PHPUnit failing tests, it seems we were not careful enough about cache key checks in a few cases:

  • When generating an activity comment without a corresponding parent activity in our tests.
  • When trying to cache a group membership ID for the group creator before this membership has been created.
  • When trying to check if a member had a member type or a group had a group type using an empty string although into 2 of our unit tests.

Fixes #8727

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-cache.php

    r13149 r13309  
    5050
    5151        // Clear the comments cache for the parent activity ID.
    52         if ( 'activity_comment' === $activity->type ) {
     52        if ( 'activity_comment' === $activity->type && ! empty( $activity->item_id ) ) {
    5353                wp_cache_delete( $activity->item_id, 'bp_activity_comments' );
    5454        }
  • trunk/src/bp-activity/bp-activity-functions.php

    r13305 r13309  
    20642064
    20652065        // If this is an activity comment, rebuild the tree.
    2066         if ( 'activity_comment' === $activity->type ) {
     2066        if ( 'activity_comment' === $activity->type && ! empty( $activity->item_id ) ) {
    20672067                // Also clear the comment cache for the parent activity ID.
    20682068                wp_cache_delete( $activity->item_id, 'bp_activity_comments' );
  • trunk/src/bp-groups/bp-groups-cache.php

    r12429 r13309  
    250250function bp_groups_clear_user_group_cache_on_membership_save( BP_Groups_Member $member ) {
    251251        wp_cache_delete( $member->user_id, 'bp_groups_memberships_for_user' );
    252         wp_cache_delete( $member->id, 'bp_groups_memberships' );
     252
     253        if ( ! is_null( $member->id ) ) {
     254                wp_cache_delete( $member->id, 'bp_groups_memberships' );
     255        }
    253256}
    254257add_action( 'groups_member_before_save', 'bp_groups_clear_user_group_cache_on_membership_save' );
  • trunk/src/bp-groups/bp-groups-functions.php

    r13280 r13309  
    32483248        }
    32493249
     3250        $group_id = (int) $group_id;
     3251        if ( ! $group_id ) {
     3252                return false;
     3253        }
     3254
    32503255        // Get all group's group types.
    32513256        $types = bp_groups_get_group_type( $group_id, false );
  • trunk/src/bp-members/bp-members-functions.php

    r13293 r13309  
    32663266        // Bail if no valid member type was passed.
    32673267        if ( empty( $member_type ) || ! bp_get_member_type_object( $member_type ) ) {
     3268                return false;
     3269        }
     3270
     3271        $user_id = (int) $user_id;
     3272        if ( ! $user_id ) {
    32683273                return false;
    32693274        }
  • trunk/tests/phpunit/testcases/groups/types.php

    r12731 r13309  
    196196                bp_groups_register_group_type( 'foo' );
    197197
    198                 $this->assertFalse( bp_groups_has_group_type( '', 'foo' ) );
     198                $this->assertFalse( bp_groups_has_group_type( 0, 'foo' ) );
    199199        }
    200200
  • trunk/tests/phpunit/testcases/members/types.php

    r13239 r13309  
    374374                bp_register_member_type( 'foo' );
    375375
    376                 $this->assertFalse( bp_has_member_type( '', 'foo' ) );
     376                $this->assertFalse( bp_has_member_type( 0, 'foo' ) );
    377377        }
    378378
Note: See TracChangeset for help on using the changeset viewer.