Skip to:
Content

bbPress.org

Changeset 7143


Ignore:
Timestamp:
11/03/2020 10:07:02 PM (13 months ago)
Author:
johnjamesjacoby
Message:

Users: avoid PHP notice (warning in PHP8) when getting a user nicename.

This commit improves the internal logic of bbp_get_user_nicename() to handle a missing or invalid user object, defaulting to an empty string in that specific instance.

In branches/2.6, for 2.6.6. See #3402.

Props dd32.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/src/includes/users/template.php

    r7031 r7143  
    488488        ), 'get_user_nicename' );
    489489
    490         // Get the user data and nicename
    491         if ( empty( $r['force'] ) ) {
    492             $user     = get_userdata( $user_id );
    493             $nicename = $user->user_nicename;
    494 
    495         // Force the nicename to something else
     490        // Force the nicename (likely from a previous user query)
     491        if ( ! empty( $r['force'] ) ) {
     492            $nicename = (string) $r['force'];
     493
     494        // Maybe fallback to getting the nicename from user data
     495        } elseif ( ! empty( $r['user_id'] ) ) {
     496            $user     = get_userdata( $r['user_id'] );
     497            $nicename = ! empty( $user )
     498                ? $user->user_nicename
     499                : '';
     500
     501        // Maybe fallback to empty string so filter still applies
    496502        } else {
    497             $nicename = (string) $r['force'];
     503            $nicename = '';
    498504        }
    499505
Note: See TracChangeset for help on using the changeset viewer.