Add null safety checks to prevent PHP warnings#4905
Open
GaryJones wants to merge 1 commit intobuddyboss:releasefrom
Open
Add null safety checks to prevent PHP warnings#4905GaryJones wants to merge 1 commit intobuddyboss:releasefrom
GaryJones wants to merge 1 commit intobuddyboss:releasefrom
Conversation
Four small fixes for undefined property/variable warnings and null parameter deprecations on PHP 8.1+: 1. Null-coalescing fallback for missing title_required property on activity objects (bp-groups-activity.php). 2. Null-coalescing fallback before passing bb_notification_small_icon() result to wp_kses_post() (bp-notifications-functions.php). 3. Early return in profile completion widget when user_progress is empty or missing completion_percentage key (class-bp-xprofile-profile-completion-widget.php). 4. Initialise $result to empty array before conditional assignment in topics manager (class-bb-topics-manager.php).
chetansatasiya
approved these changes
Mar 3, 2026
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
Four places in the codebase lack null/undefined checks, producing PHP warnings or deprecation notices on PHP 8.1+.
1. Undefined
title_requiredproperty on activity objectsIn
bp-groups/bp-groups-activity.php, when updating a group activity, the code accesses$activity->title_requiredwithout a fallback. If the property doesn't exist on the activity object, PHP emits an undefined property warning.Fix: Add
?? falsenull-coalescing fallback.2. Null passed to
wp_kses_post()from notification iconIn
bp-notifications/bp-notifications-functions.php,bb_notification_small_icon()can returnnull, which is then passed directly towp_kses_post(). On PHP 8.1+, this triggers a deprecation warning sincewp_kses_post()expects a string.Fix: Add
?? ''null-coalescing fallback.3. Missing progress data in profile completion widget
In
class-bp-xprofile-profile-completion-widget.php, the widget accesses$user_progress['completion_percentage']without checking whether$user_progressis populated or the key exists. When no applicable profile fields are configured, this produces undefined key warnings.Fix: Add an early return when
$user_progressis empty or missing thecompletion_percentagekey.4. Uninitialised
$resultvariable in topics managerIn
class-bb-topics-manager.php, the$resultvariable is only assigned inside a conditional block (if ( 'migrate' === $migrate_type && $new_topic_id )). When the condition is false,$resultis undefined for any subsequent code that references it.Fix: Initialise
$result = array()before the conditional.Test plan
title_requiredis not set on the activity object — no PHP warningbb_notification_small_icon()returns null — no deprecation notice