Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/03/2014 08:02:18 PM (10 years ago)
Author:
djpaul
Message:

at-mentions: overhaul the mentions implementation for Private Messages and Groups (admin) components.

Previously, these components had seperate implementations of username auto-suggestions, which weren't
reusable outside of where they'd been built, nor easily extended by developers, or other plugins.
This change creates a central API for auto-suggestions, currently only for usernames, but easily
extensible for other kinds of auto-suggestions in the future (i.e. group names, or #hashtags).

See #3278

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-admin.php

    r8485 r8557  
    985985
    986986    // Bail if user user shouldn't be here, or is a large network
    987     if ( ! current_user_can( 'bp_moderate' ) || ( is_multisite() && wp_is_large_network( 'users' ) ) )
     987    if ( ! current_user_can( 'bp_moderate' ) || ( is_multisite() && wp_is_large_network( 'users' ) ) ) {
    988988        wp_die( -1 );
    989 
    990     $return = array();
    991 
    992     // Exclude current group members
    993     $group_id = isset( $_GET['group_id'] ) ? wp_parse_id_list( $_GET['group_id'] ) : array();
    994     $group_member_query = new BP_Group_Member_Query( array(
    995         'group_id'        => $group_id,
    996         'per_page'        => 0, // show all
    997         'group_role'      => array( 'member', 'mod', 'admin', ),
    998         'populate_extras' => false,
    999         'count_total'     => false,
     989    }
     990
     991    $term     = isset( $_GET['term'] )     ? sanitize_text_field( $_GET['term'] ) : '';
     992    $group_id = isset( $_GET['group_id'] ) ? absint( $_GET['group_id'] )          : 0;
     993
     994    if ( ! $term || ! $group_id ) {
     995        wp_die( -1 );
     996    }
     997
     998    $suggestions = bp_core_get_suggestions( array(
     999        'group_id' => -$group_id,  // A negative value will exclude this group's members from the suggestions.
     1000        'limit'    => 10,
     1001        'term'     => $term,
     1002        'type'     => 'members',
    10001003    ) );
    10011004
    1002     $group_members = ! empty( $group_member_query->results ) ? wp_list_pluck( $group_member_query->results, 'ID' ) : array();
    1003 
    1004     $terms = isset( $_GET['term'] ) ? $_GET['term'] : '';
    1005     $users = bp_core_get_users( array(
    1006         'type'            => 'alphabetical',
    1007         'search_terms'    => $terms,
    1008         'exclude'         => $group_members,
    1009         'per_page'        => 10,
    1010         'populate_extras' => false
    1011     ) );
    1012 
    1013     foreach ( (array) $users['users'] as $user ) {
    1014         $return[] = array(
    1015             /* translators: 1: user_login, 2: user_email */
    1016             'label' => sprintf( __( '%1$s (%2$s)', 'buddypress' ), bp_is_username_compatibility_mode() ? $user->user_login : $user->user_nicename, $user->user_email ),
    1017             'value' => $user->user_nicename,
    1018         );
    1019     }
    1020 
    1021     wp_die( json_encode( $return ) );
     1005    $matches = array();
     1006
     1007    if ( $suggestions && ! is_wp_error( $suggestions ) ) {
     1008        foreach ( $suggestions as $user ) {
     1009
     1010            $matches[] = array(
     1011                // translators: 1: user_login, 2: user_email
     1012                'label' => sprintf( __( '%1$s (%2$s)', 'buddypress' ), $user->name, $user->ID ),
     1013                'value' => $user->ID,
     1014            );
     1015        }
     1016    }
     1017
     1018    wp_die( json_encode( $matches ) );
    10221019}
    10231020add_action( 'wp_ajax_bp_group_admin_member_autocomplete', 'bp_groups_admin_autocomplete_handler' );
Note: See TracChangeset for help on using the changeset viewer.