Fix null activity objects causing PHP warnings#4919
Open
GaryJones wants to merge 1 commit intobuddyboss:releasefrom
Open
Fix null activity objects causing PHP warnings#4919GaryJones wants to merge 1 commit intobuddyboss:releasefrom
GaryJones wants to merge 1 commit intobuddyboss:releasefrom
Conversation
When an activity ID exists in query results but the corresponding row has been deleted from the database, wp_cache_get() returns false. get_activity_data() unconditionally adds this falsy value to the $activities array, causing PHP warnings when downstream code accesses properties on null entries (->id, ->mptt_right, ->component). Only add the activity to the return array when it is a valid object. Add a defensive is_object() check in bp_friends_prefetch_activity_object_data() as well.
62f6c63 to
e031f46
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When activity rows are deleted from the database but their IDs are still
referenced (e.g. in cached query results),
BP_Activity_Activity::get_activity_data()adds
falseentries to the$activitiesarray. This happens becausewp_cache_get()returnsfalsefor missing cache keys, and the resultis unconditionally appended to the array regardless of validity.
Downstream code then iterates over these null entries and attempts
property access, producing three PHP warnings:
Fix
get_activity_data()— wrap the$activities[] = $activityassignment with
if ( ! empty( $activity ) )so that only validobjects are added to the return array. This is the root cause fix
and prevents all three warnings.
bp_friends_prefetch_activity_object_data()— add a defensiveis_object()check to skip non-object entries, protecting againstany code path that might pass invalid data into this function.
Testing
bp_activitytable without clearingthe object cache or any referencing queries
appear