[buddypress-trac] [BuddyPress Trac] #9276: error when using $bp->displayed_user->domain
buddypress-trac
noreply at wordpress.org
Fri Dec 26 02:11:52 UTC 2025
#9276: error when using $bp->displayed_user->domain
--------------------------+--------------------------
Reporter: locker17 | Owner: espellcaste
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 15.0.0
Component: Members | Version: 14.3.2
Severity: normal | Resolution:
Keywords: |
--------------------------+--------------------------
Comment (by vapvarun):
Attaching a patch that fixes the "Undefined property" error on PHP 8.2+
when accessing `$bp->displayed_user->domain` before a user profile is set.
Issue
`$bp->displayed_user` is a plain stdClass object. On PHP 8.2+, accessing
undefined properties on stdClass triggers warnings/errors. Unlike
`$bp->loggedin_user` which now uses the `BP_LoggedIn_User` class with
magic methods (since 15.0.0), `displayed_user` remains a plain stdClass.
This Patch (Simple Approach)
Pre-initialize commonly accessed properties with sensible default values
in `class-buddypress.php`:
* id = 0
* domain = ''
* userdata = null
* fullname = ''
* front_template = null
This prevents the undefined property errors while maintaining backward
compatibility. Default values are falsy so existing checks like `if ( !
$bp->displayed_user->domain )` still work correctly.
Alternative Approach
For consistency with the 15.0.0 pattern, a `BP_Displayed_User` class could
be created similar to `BP_LoggedIn_User` with magic `__get()` and
`__isset()` methods. This would be more comprehensive but requires a new
file.
Let me know if you prefer the class-based approach and I can prepare that
patch instead.
Testing
* Verified default values are correct before user is set
* Verified values are correctly overwritten when viewing a profile
* Verified `isset()`, `empty()`, and `!value` patterns all work correctly
* Page loads tested (homepage, members directory, user profiles)
* Logged-in user navigation tested
* Viewing another user's profile tested
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/9276#comment:4>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list