Display Name Autosuggest
-
I tried to reply back to @Matt post, but kept getting an error that “I already said that”. So sorry to start another topic but I thought this would be useful.
@Matt here is what I did and it works for me. I’m interested in expanding this in several ways, @djpaul suggested I post my success here. I’m not sure how to proceed in general with improving this further, but I will try to keep posting as I work out better solutions. I’d really like to break out from the labs at this point and create a stand alone plugin that handles @mention functionality exclusively but again I’m just learning the ropes.
Here is how I did it based off an add-in Daniel Bachhuber had created for author lookups in WordPress posts.
First add this to your theme’s function.php file:
function db_filter_user_query( &$user_query ) {
if ( is_object( $user_query ) )
$user_query->query_where = str_replace( “user_nicename LIKE”, “display_name LIKE”, $user_query->query_where );
return $user_query;
}Then here is the modified code from the bp-labs/beakers/class-bplabs-autosuggest.php file:
\
add_filter( ‘pre_user_query’, ‘db_filter_user_query’ );// Sanitise input
$search_query = implode( ”, (array) preg_replace( array( ‘|^https?
/|i’, ‘|*|’, ‘|@|’ ), ”, $_POST ) );
if ( empty( $search_query ) )
exit( ‘-1′ );$args = array(
‘count_total’ => false,
‘number’ => (int) $_POST,
‘search’ => “{$search_query}*”,
‘search_fields’ => ‘display_name’
);if ( !empty( $bp->loggedin_user->id ) )
$args = array( $bp->loggedin_user->id );if ( bp_is_username_compatibility_mode() ) {
$args = array( ‘ID’, ‘user_login’ );
$args = ‘user_login’;} else {
$args = array( ‘ID’, ‘display_name’ );
$args = ‘display_name’;
}$args = apply_filters( ‘bpl_mention_autosuggest_args’, $args );
// Search users
$user_search_results = get_users( $args );remove_filter( ‘pre_user_query’, ‘db_filter_user_query’ );
\
The forum ‘BP Labs’ is closed to new topics and replies.
