Skip to:
Content

bbPress.org

Changeset 7144


Ignore:
Timestamp:
11/03/2020 10:07:38 PM (4 years 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 trunk, for 2.7. Fixes #3402.

Props dd32.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/users/template.php

    r7032 r7144  
    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.