Making WordPress.org

Changeset 12104


Ignore:
Timestamp:
10/06/2022 02:53:18 AM (19 months ago)
Author:
dd32
Message:

User Tweaks: Aparently we have a number of locations where a $user_id which doesn't exist is the author of a comment/post/etc, and additionally, we often call get_the_author_meta() without a user context.

See #4644.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/wporg-user-tweaks.php

    r12103 r12104  
    1414    }
    1515
    16     if ( '' === $name ) {
    17         $name = get_user_by( 'id', $user_id )->user_nicename;
     16    if ( '' === $name && $user_id ) {
     17        $name = get_user_by( 'id', $user_id )->user_nicename ?? $user_id;
    1818    }
    1919
     
    2525// Filter `get_the_author_meta()`.
    2626add_filter( 'get_the_author_display_name', function( $name, $user_id ) {
    27     if ( '' === $name ) {
    28         $name = get_user_by( 'id', $user_id )->user_nicename;
     27
     28    if ( '' === $name && $user_id ) {
     29        $name = get_user_by( 'id', $user_id )->user_nicename ?? $user_id;
    2930    }
    3031
Note: See TracChangeset for help on using the changeset viewer.