bp_groups_admin_autocomplete_handler()
AJAX handler for group member autocomplete requests.
Description
Source
File: bp-groups/bp-groups-admin.php
function bp_groups_admin_autocomplete_handler() { // Bail if user user shouldn't be here, or is a large network. if ( ! bp_current_user_can( 'bp_moderate' ) || bp_is_large_install() ) { wp_die( -1 ); } $term = isset( $_GET['term'] ) ? sanitize_text_field( $_GET['term'] ) : ''; $group_id = isset( $_GET['group_id'] ) ? absint( $_GET['group_id'] ) : 0; if ( ! $term || ! $group_id ) { wp_die( -1 ); } $suggestions = bp_core_get_suggestions( array( 'group_id' => -$group_id, // A negative value will exclude this group's members from the suggestions. 'limit' => 10, 'term' => $term, 'type' => 'members', ) ); $matches = array(); if ( $suggestions && ! is_wp_error( $suggestions ) ) { foreach ( $suggestions as $user ) { $matches[] = array( // Translators: 1: user_login, 2: user_email. 'label' => sprintf( __( '%1$s (%2$s)', 'buddyboss' ), $user->name, $user->ID ), 'value' => $user->ID, ); } } wp_die( json_encode( $matches ) ); }
Changelog
Version | Description |
---|---|
BuddyPress 1.7.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.