Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/06/2010 05:54:55 PM (16 years ago)
Author:
boonebgorges
Message:

Allows admins to allow message Componse To: autocomplete to include all members of the site. Fixes #2419, props r-a-y for the initial patch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r3353 r3364  
    537537add_action( 'wp_ajax_messages_delete', 'bp_dtheme_ajax_messages_delete' );
    538538
    539 /* AJAX autocomplete your friends names on the compose screen */
     539/**
     540 * bp_dtheme_ajax_messages_autocomplete_results()
     541 *
     542 * AJAX handler for autocomplete. Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined
     543 *
     544 * @global object $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     545 * @return none
     546 */
    540547function bp_dtheme_ajax_messages_autocomplete_results() {
    541548        global $bp;
    542549
     550        // Include everyone in the autocomplete, or just friends?
     551        if ( $bp->messages->slug == $bp->current_component )
     552                $autocomplete_all = $bp->messages->autocomplete_all;
     553       
    543554        $friends = false;
    544555
    545         // Get the friend ids based on the search terms
    546         if ( function_exists( 'friends_search_friends' ) )
    547                 $friends = friends_search_friends( $_GET['q'], $bp->loggedin_user->id, $_GET['limit'], 1 );
    548 
    549         $friends = apply_filters( 'bp_friends_autocomplete_list', $friends, $_GET['q'], $_GET['limit'] );
    550 
    551         if ( $friends['friends'] ) {
    552                 foreach ( (array)$friends['friends'] as $user_id ) {
     556        $limit = $_GET['limit'] ? $_GET['limit'] : apply_filters( 'bp_autocomplete_max_results', 10 );
     557
     558        // Get the user ids based on the search terms
     559        if ( $autocomplete_all ) {
     560                $users = BP_Core_User::search_users( $_GET['q'], $limit, $pag_page );
     561               
     562                if ( !empty( $users['users'] ) ) {
     563                        // Build an array with the correct format
     564                        $user_ids = array();
     565                        foreach( $users['users'] as $user ) {
     566                                if ( $user->id != $bp->loggedin_user->id )
     567                                        $user_ids[] = $user->id;
     568                        }
     569                       
     570                        $user_ids = apply_filters( 'bp_core_autocomplete_ids', $user_ids, $_GET['q'], $limit );
     571                }
     572        } else {
     573                if ( function_exists( 'friends_search_friends' ) ) {
     574                        $users = friends_search_friends( $_GET['q'], $bp->loggedin_user->id, $limit, 1 );
     575                       
     576                        // Keeping the bp_friends_autocomplete_list filter for backward compatibility
     577                        $users = apply_filters( 'bp_friends_autocomplete_list', $users, $_GET['q'], $limit );
     578                       
     579                        if ( !empty( $users['friends'] ) )
     580                                $user_ids = apply_filters( 'bp_friends_autocomplete_ids', $users['friends'], $_GET['q'], $limit );
     581                }
     582        }
     583       
     584
     585        if ( $user_ids ) {
     586                foreach ( $user_ids as $user_id ) {
    553587                        $ud = get_userdata($user_id);
    554588                        $username = $ud->user_login;
Note: See TracChangeset for help on using the changeset viewer.