BuddyDev

Search

Different Member Types, Different Display Names

  • Participant
    Level: Initiated
    Posts: 10
    RES on #31814

    I’ve been looking around for a bit of time for a solution to a problem. I have Two different Member Types each with their own WordPress Role. I need one Member Type (Teachers) to have the Full Name (First and Last Names) displayed and the other (Students) the username or “nicename” displayed.

    I found a plugin, “Display Name Publicly As” that may do what I need at:

    https://memberfix.rocks/change-display-name-publicly-as/

    I was hoping to find a simpler solution.

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #31833

    Hi RES,
    Thank you for the question.

    It is a simple customization. you can do it with a couple of lines of code.

    I will rephrase your question and share the code.

    Here is the code that will show nice name for all users except the teacher(for them, let the full name work).

    
    
    /**
     * Filter Display Name.
     */
    add_filter( 'bp_core_get_user_displayname', function ( $name, $user_id ) {
    	if ( ! bp_has_member_type( $user_id, 'teacher' ) ) {
    		$name = bp_members_get_user_nicename( $user_id );
    	}
    
    	return $name;
    }, 10, 2 );
    
    /**
     * Filter Displayed User full name for BuddyPress.
     */
    add_filter( 'bp_displayed_user_fullname', function ( $name ) {
    	if ( ! bp_has_member_type( bp_displayed_user_id(), 'teacher' ) ) {
    		$name = bp_members_get_user_nicename( bp_displayed_user_id() );
    	}
    
    	return $name;
    } );
    
    

    You can put it in bp-custom.php in plugins directory or functions.php of your theme.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 10
    RES on #31887

    I appreciate your response very much. Unfortunately I tested it in both a BuddyPress and BuddyBoss setups (both multisite) and I could not get it to work. I tried various scenarios. I’m running WordPress version 5.4.2 and PHP version 7.4.4.

    I feel as though I’m already asking a lot but I have a request. I believe the code reads, “if not teacher, display nicename. I have different levels of teachers so I think it would work better if the code was “if student, full name”. I hope that’s clear.

    Thank you very, very much.

    Here are the plugins I’m using on the BuddyPress site:

    Astra Pro Version 2.5.1 by Brainstorm Force
    Autoptimize Version 2.7.3 by Frank Goossens (futtta) (Latest version: 2.7.5)
    BP Profile Search Version 5.3.3 by Andrea Tarantini
    BuddyPress Version 6.1.0 by The BuddyPress Community
    BuddyPress Admin Only Profile Fields Version 1.2 by Ashley Rich
    BuddyPress Member Type Generator Version 1.0.6 by BuddyDev
    BuddyPress Multi Network Version 1.0.2 by Brajesh Singh
    BuddyPress Xprofile Custom Field Types Version 1.1.5 by BuddyDev
    Classic Editor Version 1.5 by WordPress Contributors
    Custom Profile Menu for BuddyPress Version 1.0.2 by Nahid Ferdous Mohit
    Paid Memberships Pro Version 2.3.4 by Stranger Studios
    Paid Memberships Pro – BuddyPress Add On Version 1.2.5 by Paid Memberships Pro
    Paid Memberships Pro – Roles Add On Version 1.2 by Paid Memberships Pro
    Premium Starter Templates Version 2.3.1 by Brainstorm Force (Latest version: 2.3.2)
    Weaver Xtreme Theme Support Version 4.0.5 by wpweaver
    WP Multi-Network Version 2.2.0 by johnjamesjacoby, ddean, BrianLayman, rmccue
    WP Super Cache Version 1.7.1 by Automattic

    Here are the plugins I’m using on the BuddyBoss site:

    BuddyBoss Platform v1.4.6
    Contact Form 7 v5.2
    LearnDash LMS – Course Grid v1.6.0
    LearnDash LMS – WooCommerce Integration v1.8.0
    Mailchimp for WooCommerce v2.4.1
    Paid Memberships Pro v2.3.4
    Paid Memberships Pro – BuddyPress Add On v1.2.5
    Paid Memberships Pro – Roles Add On v1.2
    LearnDash LMS v3.2.1
    WooCommerce v4.3.0
    WP Mail SMTP v2.2.1
    WP Multi-Network v2.4.0
    Duplicator Pro v3.8.9.1
    BuddyPress Multi Network v1.0.2

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #31889

    Hi RES,
    No issues.

    can you please tell me where did you place the code ? is it in wp-content/plugins/bp-custom.php?

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 10
    RES on #31902

    The code is in wp-content/plugins/bp-custom.php. By the way, both sites are Multi-Network in addition to Multisite, on two separate installations on WordPress. And, both sites are the main site on their respective network.

    Again, thank you very much.

  • Participant
    Level: Initiated
    Posts: 10
    RES on #39098

    Just checking if there is something else I can try to get the code to work. I now have a non-multisite setup and it still isn’t working for me. Thank you, I really appreciate your time. Please let me know how much you would charge for this.

  • Participant
    Level: Initiated
    Posts: 10
    RES on #39099

    I forgot to mention, I am solely on BuddyBoss.

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #39278

    Hi,
    I am sorry for the delay.

    You will need assistance from BuddyBoss support. I am unable to find time to assist you with BuddyBoss and other other plguins.

    The above code is for BuddyPress.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved