Skip to:
Content

BuddyPress.org

Opened 7 years ago

Closed 7 years ago

#7601 closed feature request (fixed)

Add user_id to $results array for easier filtering of autocompletes

Reported by: bradmkjr's profile bradmkjr Owned by: djpaul's profile djpaul
Milestone: 3.0 Priority: normal
Severity: normal Version:
Component: Members Keywords: dev-feedback
Cc:

Description

When trying to filter users in autocomplete, it would be better if user_id was included in the $results array, so a user lookup would not be required to get the user_id from the user_nicename

bp-core/classes/class-bp-members-suggestions.php

<?php
                foreach ( $user_query->results as $user ) {
                        $result        = new stdClass();
                        $result->ID    = $user->user_nicename;
                        $result->image = bp_core_fetch_avatar( array( 'html' => false, 'item_id' => $user->ID ) );
                        $result->name  = bp_core_get_user_displayname( $user->ID );

                        $results[] = $result;
                }

Could change to:

<?php
                foreach ( $user_query->results as $user ) {
                        $result        = new stdClass();
                        $result->ID    = $user->user_nicename;
                        $result->user_id    = $user->ID;
                        $result->image = bp_core_fetch_avatar( array( 'html' => false, 'item_id' => $user->ID ) );
                        $result->name  = bp_core_get_user_displayname( $user->ID );

                        $results[] = $result;
                }

Thank You

Change History (5)

#1 @DJPaul
7 years ago

  • Component changed from Core to Members
  • Keywords dev-feedback added
  • Milestone set to Under Consideration

On one hand, sure, I'm OK to add this. I looked into core's get_user_by( 'slug', ... ) and it does have a cache for look-ups by user_nicename, but I can understand the developer convenience of having the ID, given that most functions take user IDs.

On the other hand, this data is passed to bp_ajax_get_suggestions(), which is sent on page requests when authenticated and Friends is enabled and the user has friends. We'd be exposing user IDs, which I'm not *sure* we do anywhere else (or if we should stop doing that, I know we've had similar "complaints" about the user_nicename in the URL before).

Moving to a second opinion.

This ticket was mentioned in Slack in #buddypress by djpaul. View the logs.


7 years ago

This ticket was mentioned in Slack in #buddypress by djpaul. View the logs.


7 years ago

#4 @DJPaul
7 years ago

  • Milestone changed from Under Consideration to 3.0

#5 @djpaul
7 years ago

  • Owner set to djpaul
  • Resolution set to fixed
  • Status changed from new to closed

In 11760:

Members, Groups: add user ID to user autocomplete data.

Fixes #7601

Note: See TracTickets for help on using tickets.