Skip to:
Content
Pages
Categories
Search
Top
Bottom

Autocomplete shows both names


  • metalhead
    Participant

    @aaronthomas1979

    I’m using this:
    define( 'BP_MESSAGES_AUTOCOMPLETE_ALL', true );
    to autocomplete entries for the user in the compose “To” field.

    The feature works great, but in the list it displays both the username and the display name (in parenthesis.) That is what I’d like to change. Can I hide one or the other, so it doesn’t show both names in the list?

    I can’t figure out the selector(s) for username and/or display name in this code. Any help with hiding (preferably the one in parenthesis,) or help on finding the documentation that could help me with this, will be appreciated.

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)

  • r-a-y
    Keymaster

    @r-a-y

    You’ll probably want to look at the bp_legacy_theme_ajax_messages_autocomplete_results() function and roll your own version.

    Something like:

    // Remove the default AJAX autocomplete hook.
    remove_action( 'wp_ajax_messages_autocomplete_results', 'bp_legacy_theme_ajax_messages_autocomplete_results' );
    
    // Add our own.
    add_action( 'wp_ajax_messages_autocomplete_results', 'my_messages_autocomplete_results' );
    
    function my_messages_autocomplete_results() {
    	// YOUR CUSTOM AJAX OUTPUT HERE
    }

    metalhead
    Participant

    @aaronthomas1979

    Thanks! That worked.

    One small problem that remains, is that I still have parenthesis wrapped around $user->name

    Here’s a chunk of the code:

    printf( '<span id="%s" href="#"></span><img src="%s" style="width: 15px">   %s (%s)' . "\n",  
                    esc_attr( 'link-' . $user->ID ),  
                    esc_url( $user->image ),  
                    esc_html(  ),  
                    esc_html( $user->ID )

    I deleted $user->name from the 3rd line, but if I delete the parenthesis, or the entire line, then the function stops working.

    Do you know how I can get the parenthesis out of there?


    r-a-y
    Keymaster

    @r-a-y

    Have you tried just removing the parenthesis in the <span> string?


    metalhead505
    Participant

    @metalhead505

    That worked. Thanks very much!


    metalhead
    Participant

    @aaronthomas1979

    Correction: What I meant was, I didn’t find any parentheses in the span tag, but I removed them from the %s, and it display the name without parentheses, but it crippled the function; without those parentheses, I click on a name from the list and the name gets printed with html code wrapped around it.

    Not a big deal – but let me know if you have any other suggestions. I will mess around with it some more and post back if I get it working.


    honoluluman
    Participant

    @honoluluman

    Hello, did you manage to find solution to this issue?

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.