Changeset 10585 for sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/wporg-user-tweaks.php
- Timestamp:
- 01/15/2021 05:55:03 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/wporg-user-tweaks.php
r10238 r10585 1 1 <?php 2 namespace WordPressdotorg\User_Tweaks; 3 use WP_User; 4 use add_filter; 5 2 6 /** 3 7 * Plugin Name: W.org User Tweaks … … 5 9 6 10 // Some users have an empty display_name field, which shouldn't happen but does due to sanitization. 7 add_filter( 'user_display_name', function( $name, $user_id ) { 11 add_filter( 'user_display_name', function( $name, $user_id, $context ) { 12 if ( 'edit' === $context ) { 13 return $name; 14 } 15 8 16 if ( '' === $name ) { 9 17 $name = get_user_by( 'id', $user_id )->user_nicename; 10 18 } 11 19 20 $name = maybe_replace_blocked_user_name( $name, $user_id ); 21 12 22 return $name; 13 }, 1, 2);23 }, 1, 3 ); 14 24 15 25 // bbPress skips user filtering and does it's own 16 add_filter( 'bbp_get_displayed_user_field', function( $value, $field ) { 17 if ( 'display_name' === $field && '' === $value ) { 18 $value = bbpress()->displayed_user->user_nicename; 26 add_filter( 'bbp_get_displayed_user_field', function( $value, $field, $filter ) { 27 if ( 'edit' === $filter ) { 28 return $value; 29 } 30 31 if ( 'display_name' === $field ) { 32 if ( '' === $value ) { 33 $value = bbpress()->displayed_user->user_nicename; 34 } 35 36 $value = maybe_replace_blocked_user_name( $value, bbpress()->displayed_user ); 19 37 } 20 38 21 39 return $value; 22 }, 1, 2);40 }, 1, 3 ); 23 41 24 42 /** … … 34 52 } 35 53 54 // Intentionally not used, as this will override in edit contexts too. 55 //$wp_user->display_name = maybe_replace_blocked_user_name( $wp_user->display_name, $wp_user ); 56 36 57 return $allcaps; 37 58 }, 1, 4 ); 59 60 /** 61 * Use the nicename field for blocked users. 62 */ 63 function maybe_replace_blocked_user_name( $name, $user ) { 64 if ( ! defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) { 65 return $name; 66 } 67 68 $user_id = is_object( $user ) ? $user->ID : $user; 69 if ( ! $user_id ) { 70 return $name; 71 } 72 73 if ( ! ( $user instanceof WP_User ) ) { 74 $user = get_user_by( 'id', $user ); 75 } 76 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 ) ) { 85 return $user->user_nicename; 86 } 87 88 return $name; 89 }
Note: See TracChangeset
for help on using the changeset viewer.