Opened 15 years ago
Closed 14 years ago
#1699 closed enhancement (fixed)
add filters to the queries of function get_users()
Reported by: |
|
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)
Change History (16)
#3
@
15 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
@
15 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.
#6
@
15 years ago
Or maybe a filter on the pd.field id to search on ?
Anyway, I think this is an important thing !
#7
@
15 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...
#8
@
15 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
@
15 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
@
15 years ago
- Resolution set to wontfix
- Status changed from new to closed
Andy says that filtering this query is a no go.
#11
@
15 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.
Not sure if filtering the Sql statement itself is the best way to do this.