Making WordPress.org

Changeset 10586


Ignore:
Timestamp:
01/15/2021 06:14:21 AM (6 years ago)
Author:
dd32
Message:

User Tweaks: Add BuddyPress support.

See #5578.

File:
1 edited

Legend:

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

    r10585 r10586  
    4141
    4242/**
     43 * Filter the BuddyPress displayed name.
     44 */
     45add_filter( 'bp_displayed_user_fullname', function( $name ) {
     46        if ( '' === $name ) {
     47                buddypress()->displayed_user->user_nicename;
     48        }
     49
     50        $name = maybe_replace_blocked_user_name( $name, buddypress()->displayed_user );
     51
     52        return $name;
     53} );
     54
     55/**
    4356 * Some users have an empty display_name field, which shouldn't happen, but does due to sanitization.
    4457 *
    … …  
    6275 */
    6376function maybe_replace_blocked_user_name( $name, $user ) {
    64         if ( ! defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
     77        if ( ! ( $user instanceof WP_User ) ) {
     78                if ( ! empty( $user->ID ) ) {
     79                        $user_id = $user->ID;
     80                } elseif ( !empty( $user->id ) ) {
     81                        $user_id = $user->id;
     82                } else {
     83                        $user_id = $user;
     84                }
     85
     86                $user = get_user_by( 'id', $user_id );
     87        }
     88
     89        if ( ! $user || ! $user->exists() ) {
    6590                return $name;
    6691        }
    6792
    68         $user_id = is_object( $user ) ? $user->ID : $user;
    69         if ( ! $user_id ) {
    70                 return $name;
     93        // If it's a recently blocked user, it'll have a broken user_pass, use that.
     94        if ( 'BLOCKED' === substr( $user->user_pass, 0, 7 ) ) {
     95                return $user->user_nicename;
    7196        }
    7297
    73         if ( ! ( $user instanceof WP_User ) ) {
    74                 $user = get_user_by( 'id', $user );
     98        if ( defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
     99                $user->for_site( WPORG_SUPPORT_FORUMS_BLOGID );
    75100        }
    76101
    77         if ( ! $user ) {
    78                 return $name;
    79         }
    80 
    81         $user->for_site( WPORG_SUPPORT_FORUMS_BLOGID );
    82 
    83         /* Cannot use $user->has_cap( 'bbp_blocked' ), as we may be within a capability filter. */
    84         if ( !empty( $user->roles ) && in_array( 'bbp_blocked', $user->roles ) ) {
     102        // Cannot use $user->has_cap( 'bbp_blocked' ), as we may be within a capability filter.
     103        // Only works on the WordPress.org network.
     104        if ( ! empty( $user->roles ) && in_array( 'bbp_blocked', $user->roles ) ) {
    85105                return $user->user_nicename;
    86106        }
Note: See TracChangeset for help on using the changeset viewer.