Add null safety checks in forums code#4901
Open
GaryJones wants to merge 1 commit intobuddyboss:releasefrom
Open
Add null safety checks in forums code#4901GaryJones wants to merge 1 commit intobuddyboss:releasefrom
GaryJones wants to merge 1 commit intobuddyboss:releasefrom
Conversation
Three small fixes to prevent PHP warnings and errors: 1. Null-check get_post() result before accessing post_parent in forum group detection (bp-forums/functions.php). 2. Guard REST reply update permission check so the author comparison only runs when $retval is already true, preventing errors when the prior permission check failed (class-bp-rest-reply-endpoint.php). 3. Add null-coalescing fallback for the tag REST parameter before passing to sanitize_title(), preventing a PHP 8.1+ deprecation warning (class-bp-rest-topics-endpoint.php).
chetansatasiya
approved these changes
Mar 2, 2026
Contributor
|
@GaryJones Thanks for the PR and it will be added in our upcoming release. |
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
Three places in the forums code lack null safety checks, causing PHP warnings, deprecation notices, or potential fatal errors on PHP 8.1+.
1. Null post object access in forum group detection
In
bp-forums/functions.php,get_post( $forum_id )can returnnullwhen the forum post does not exist (e.g. it was deleted or the ID is invalid). The code immediately accesses$current_post->post_parentwithout checking, causing a fatal error.Fix: Add
$current_post &&before accessing the property.2. REST reply permission check logic error
In
class-bp-rest-reply-endpoint.php, theupdate_item_permissions_checkmethod calls$this->get_item_permissions_check()which may return aWP_Error. The code then unconditionally compares the reply author, even when$retvalis already an error. This can cause unexpected behaviour or mask the original permission error.Fix: Add
true === $retval &&to only evaluate the author check when the prior permission check passed.3. Null passed to sanitize_title() for REST topic tag
In
class-bp-rest-topics-endpoint.php,$request->get_param( 'tag' )returnsnullwhen the parameter is not provided. Passingnulltosanitize_title()triggers a deprecation warning on PHP 8.1+.Fix: Add
?? ''null-coalescing fallback.Test plan
tagparameter on PHP 8.1+ — no deprecation warning