Skip to:
Content
Pages
Categories
Search
Top
Bottom

Making autocomplete work for all users

  • We have a very small member base (160 users) and we all know each other in the real world. As such, “Friends” doesn’t do much for us. All it does is allow you to filter your stream and autocomplete names when composing a private message. Since we only have 160 users and we all know each other, if would be great if autocomplete worked for ALL members… not just your the people on your friend list. I know you can type the username and it will work… but then you have to remember or look up usernames. And there’s no feedback that you remembered and typed the name correctly. I’d like to fix that.

    The autocomplete code starts at line 539 in /buddypress/bp-themes/bp-default/_inc/ajax.php. On line 547 you see that a local $friends variable is declared and uses an existing function (friends_search_friends()) to populate this variable with an array of all your friends. It should be a simple matter of setting $friends to be an array of ALL users rather than just your friends, but I can’t figure it out. Does anyone have any ideas? I’m sure this would be useful for any site with a small user base.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I’m getting closer! I got it working by changing one line in the search_friends function. This function is found inside the BP_Friends_Friendship class in the bp-friends-classes.php file. This change will break all other friend searches but at least I got the autocomplete working so that it searches on ALL members instead of just your friends. Now I just have to figure out how to do it within my theme instead of with core hacking.

    Here’s the change:

    Line 154 of bp-friends-classes.php
    change: $fids = implode( ‘,’, $friend_ids );
    to: $fids = implode( ‘,’, $wpdb->get_col( “SELECT $wpdb->users.ID FROM $wpdb->users”) );

    So basically… I’m just feeding the SQL query (a few lines down in the function) a list of ALL user ids instead of only friend ids.

    I solved this but only in a fashion. My solution is not update-proof. All I did was copy/paste/modify the relevant functions into my functions.php file.

    Relevant functions (copy into child theme’s functions.php file):
    – search_friends() in /plugins/buddypress/bp-friends/bp-friends-classes.php
    – bp_dtheme_ajax_messages_autocomplete_results() from /plugins/buddypress/bp-themes/bp-default/_inc/ajax.php

    Changes (in child theme’s functions.php file):
    – renamed both functions (make sure to change all references within the code as well)
    – changed $fids = implode( ‘,’, $friend_ids ); to $fids = implode( ‘,’, $wpdb->get_col( “SELECT $wpdb->users.ID FROM $wpdb->users”) );
    – commented out the action hook from parent ajax.php file.

    If someone knows a smarter way to do this… or at least a way to do it without having to hack the ajax.php parent file… let me know. Nothing I did in my child theme would remove that function. Nothing! Argh. At least the hack is simple. Just commenting out a single line at the bottom of the ajax.php file. I can deal with that.

    p.s. This inglorious hack also depends on having the pointless (for us) “Friends” feature enabled. Oh well.

    any fixes for this currently being worked on??


    r-a-y
    Keymaster

    @r-a-y

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Making autocomplete work for all users’ is closed to new replies.
Skip to toolbar