Skip to:

Display Name in Group Member Search — is there a functions.php equiv. in admin?

  • Profile photo of evanvolgas


    I’ve searched for the past several hours and couldn’t find an answer to this… if someone already answered this, I apologize for repeating.

    I have a client who is developing a BP member area for nonprofit partners around the world. On the groups administration screen ( Dashboard –> Groups –> Edit –> Add new members ), they would like to change the display from “User name” and “user email” to “Display name” and “user email.”

    On line 946 of bp-groups-admin (content/plugins/buddypress/bp-groups/bp-groups-admin) I found

    * AJAX handler for group member autocomplete requests
    * @since BuddyPress (1.7)
    function bp_groups_admin_autocomplete_handler() {

    // Bail if user user shouldn’t be here, or is a large network
    if ( ! current_user_can( ‘bp_moderate’ ) || ( is_multisite() && wp_is_large_network( ‘users’ ) ) )
    wp_die( -1 );

    $return = array();

    // Exclude current group members
    $group_id = isset( $_GET[‘group_id’] ) ? wp_parse_id_list( $_GET[‘group_id’] ) : array();
    $group_member_query = new BP_Group_Member_Query( array(
    ‘group_id’ => $group_id,
    ‘per_page’ => 0, // show all
    ‘group_role’ => array( ‘member’, ‘mod’, ‘admin’, ),
    ‘populate_extras’ => false,
    ‘count_total’ => false,
    ) );

    $group_members = ! empty( $group_member_query->results ) ? wp_list_pluck( $group_member_query->results, ‘ID’ ) : array();

    $terms = isset( $_GET[‘term’] ) ? $_GET[‘term’] : ”;
    $users = get_users( array(
    ‘blog_id’ => false,
    ‘search’ => ‘*’ . $terms . ‘*’,
    ‘exclude’ => $group_members,
    ‘search_columns’ => array( ‘user_login’, ‘user_nicename’, ‘user_email’, ‘display_name’ ),
    ‘number’ => 10
    ) );

    foreach ( (array) $users as $user ) {
    $return[] = array(
    /* translators: 1: user_login, 2: user_email */
    ‘label’ => sprintf( __( ‘%1$s (%2$s)’ ), $user->user_login, $user->user_email ),
    ‘value’ => $user->user_login,

    On that very last “foreach” I think I want to change ‘label’ => sprintf( __( ‘%1$s (%2$s)’ ), $user->user_login, $user->user_email ) to reference display_name instead of email

    Can anyone confirm if this is true? Also, is there a template hierarchy that would allow me to load a modified php script in place of this one, or perhaps something like a child theme functions.php where I could unhook that function and attach my modified one?

    I apologize if this is an obvious thing… spent several hours and could not find an answer. Need some help from folks who know more about BP than I do. I appreciate your time in advance. For reals.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Profile photo of aces


    oops, misread the question….

    Profile photo of evanvolgas


    Hey, your answer turned me onto bp-custom though and it was helpful to read what you’d originally shared too. WordPress to BuddyPress… a bit different, but very cool stuff.

    For those interested, the problem was that the nonprofit had several usernames/emails identical to each other. The default “add new user” search in the groups admin area was for user_name and user_email… not helpful in this client’s case. aces responded with which, while not the right solution for this specific problem, turned me onto this, which is (or at least it works… is there ever the one right solution? not sure.”

    In any case, I created a bp-custom.php file and unhooked the original search function

    remove_action( ‘wp_ajax_bp_group_admin_member_autocomplete’, ‘bp_groups_admin_autocomplete_handler’ );

    Then I changed the autocomplete handler to show display_name and added the action back in

    add_action( ‘wp_ajax_bp_group_admin_member_autocomplete’, ‘mbb_groups_admin_autocomplete_handler’ );

    This one is solved. Turned out it was simple after all. @aces, thanks for sharing what you did. I read over the link you shared and saw the link to bp-custom, which somehow I didn’t find when I was looking into this earlier. I appreciate your help and it looks like the problem is solved :-)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display Name in Group Member Search — is there a functions.php equiv. in admin?’ is closed to new replies.
Skip to toolbar