Skip to:
Content

BuddyPress.org

Opened 13 years ago

Closed 12 years ago

#1699 closed enhancement (fixed)

add filters to the queries of function get_users()

Reported by: grosbouff's profile grosbouff Owned by:
Milestone: 1.5 Priority: minor
Severity: Version:
Component: Core Keywords: has-patch needs-testing
Cc:

Description

Hi, I think you should add filters to the queries done by function get_users() :

eg. with my plugin bp-real-names :

when you search a user by "word", the core query looks like :

SELECT COUNT(DISTINCT u.ID) FROM wp_users u LEFT JOIN wp_usermeta um ON um.user_id = u.ID LEFT JOIN wp_bp_xprofile_data pd ON u.ID = pd.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pd.field_id = 1 AND pd.value LIKE '%%admin%%' ORDER BY pd.value ASC

but I need to be able to change this to

SELECT COUNT(DISTINCT u.ID) FROM wp_users u LEFT JOIN wp_usermeta um ON um.user_id = u.ID LEFT JOIN wp_bp_xprofile_data pd ON u.ID = pd.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pd.field_id = 4 AND pd.value LIKE '%%Smith%%' ORDER BY pd.value ASC

This is not possible actually as I see...

Attachments (3)

get_users.patch (1.1 KB) - added by johnjamesjacoby 13 years ago.
One of these things is not like the others
add_missing_get_users_qry_filter.diff (1.2 KB) - added by MrMaz 13 years ago.
add_missing_get_users_qry_filter2.diff (1.2 KB) - added by MrMaz 13 years ago.

Download all attachments as: .zip

Change History (16)

#1 @DJPaul
13 years ago

  • Milestone changed from 1.2 to 1.2.1

Not sure if filtering the Sql statement itself is the best way to do this.

#2 @grosbouff
13 years ago

Then have you an idea of how I could to this ?

#3 @apeatling
13 years ago

I'm not going to filter queries since this is outside of the scope of the API. If you start letting plugins filter queries then it's going to get messy to provide compatibility moving forwards. You need to work at a higher level than this. I'm open to suggestions.

#4 @DJPaul
13 years ago

do_action on the result of this query, passed by reference? It's called in a few places so it would be better to have such a thing in this function.

#5 @DJPaul
13 years ago

Or parameters to the various loops doing the same sort of thing?

#6 @grosbouff
13 years ago

Or maybe a filter on the pd.field id to search on ?

Anyway, I think this is an important thing !

#7 @grosbouff
13 years ago

I thought a little about this and i think that the good solution would be to filter an array with the field names & field values to check.

$datas_to_get = apply_filters('bp_core_xprofile_fields_to_get',array([1]=>'%%admin%%'));

or something like this...

@johnjamesjacoby
13 years ago

One of these things is not like the others

#8 @johnjamesjacoby
13 years ago

  • Keywords has-patch added

get_users is the only query that doesn't have a filter on it. Patch attached with possible addition of filters.

#9 @MrMaz
13 years ago

  • Milestone changed from 1.2.1 to 1.2
  • Priority changed from major to minor
  • Type changed from enhancement to defect

This is a defect. All other "loop" queries in the same class are filtered.

#10 @MrMaz
13 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

Andy says that filtering this query is a no go.

#11 @MrMaz
13 years ago

  • Keywords has-patch removed
  • Milestone changed from 1.2 to Future Release
  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • Type changed from defect to enhancement

I just had an idea about how to solve this member sorting issue. Its not complete but wanted to get my thoughts out there so maybe someone can run with it.

Instead of trying to create a complicated filtering system to allow developers to control the query, why not just have a dedicated xprofile field in the db table that the query sorts on, the contents of which are filterable when a record is saved.

For instance the query might always sort on the xprofile field 'OrderBy'. The contents of this field for each member will be written every time the profile data is saved, but passed through a filter so the developer can supply whatever string they want. This allows them to control the sort order of that particular member without touching the query.

This idea needs refining, but there might be something there.

#12 @cnorris23
12 years ago

  • Component set to Core
  • Keywords has-patch needs-testing added

#13 @DJPaul
12 years ago

  • Milestone changed from Future Release to 1.3
  • Resolution set to fixed
  • Status changed from reopened to closed

Trunk already has this kind of filter in place, so closing ticket

Note: See TracTickets for help on using tickets.