Skip to:
Content

BuddyPress.org

Changeset 3364


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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-messages.php

    r3357 r3364  
    1111                define ( 'BP_MESSAGES_SLUG', 'messages' );
    1212
    13         /* For internal identification */
     13        // For internal identification
    1414        $bp->messages->id = 'messages';
    1515
     
    2020        $bp->messages->format_notification_function = 'messages_format_notifications';
    2121
    22         /* Register this in the active components array */
     22        // Register this in the active components array
    2323        $bp->active_components[$bp->messages->slug] = $bp->messages->id;
     24
     25        // Include all members in the To: autocomplete?
     26        $bp->messages->autocomplete_all = defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ) ? true : false;
    2427
    2528        do_action( 'messages_setup_globals' );
  • 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.