Notifications
Clear all

Script [Solved] How to change member's display name?

2 Posts
1 Users
1 Reactions
173 Views
Posts: 4
Topic starter
(@apos37)
Active Member
Joined: 4 months ago

Is there a PHP hook that I can use to filter the member's display name? I need to display a different name based on their role.

Topic Tags
1 Reply
Posts: 4
Topic starter
(@apos37)
Active Member
Joined: 4 months ago

I figured it out after scouring through your code. Found the following filters. For anyone interested, here is my implementation inside my class.

add_filter( 'wpforo_get_member', [ $this, 'forum_topics_member_name' ], 1000 );
add_filter( 'wpforo_user_display_name', [ $this, 'forum_profile_member_name' ], 1000, 2 );
add_filter( 'wpforo_member_nicename', [ $this, 'forum_profile_nicename' ], 1000, 2 );
...


/**
 * Forum member name on topics
 *
 * @param array $member
 * @return array
 */
public function forum_topics_member_name( $member ) {
    // My own function that gets the name how I want it to
    $member[ 'display_name' ] = $this->get_user_nickname( $member[ 'userid' ], false );
    return $member;
} // End forum_topics_member_name


/**
 * Forum member name on profile
 *
 * @param string $member
 * @param array $member
 * @return string
 */
public function forum_profile_member_name( $dname, $user ) {
    // My own function that gets the name how I want it to
    return $this->get_user_nickname( $user[ 'userid' ], false ); 
} // End forum_profile_member_name


/**
 * Remove forum nicename on profile
 *
 * @param string $member
 * @param array $member
 * @return string
 */
public function forum_profile_nicename( $nicename, $member ) {
    return '';
} // End forum_profile_nicename