Accept 'orderby=include' in `WP_User_Query`.
This lets the results of a user query be sorted manually by the value of the 'include' param. Props jipmoors. Fixes #30064. Built from https://develop.svn.wordpress.org/trunk@30016 git-svn-id: http://core.svn.wordpress.org/trunk@30016 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
823cfebeca
commit
be4bc9a7e1
|
@ -598,6 +598,13 @@ class WP_User_Query {
|
|||
$this->query_from = "FROM $wpdb->users";
|
||||
$this->query_where = "WHERE 1=1";
|
||||
|
||||
// Parse and sanitize 'include', for use by 'orderby' as well as 'include' below.
|
||||
if ( ! empty( $qv['include'] ) ) {
|
||||
$include = wp_parse_id_list( $qv['include'] );
|
||||
} else {
|
||||
$include = false;
|
||||
}
|
||||
|
||||
// sorting
|
||||
if ( isset( $qv['orderby'] ) ) {
|
||||
if ( in_array( $qv['orderby'], array('nicename', 'email', 'url', 'registered') ) ) {
|
||||
|
@ -621,6 +628,10 @@ class WP_User_Query {
|
|||
$orderby = 'ID';
|
||||
} elseif ( 'meta_value' == $qv['orderby'] ) {
|
||||
$orderby = "$wpdb->usermeta.meta_value";
|
||||
} else if ( 'include' === $qv['orderby'] && ! empty( $include ) ) {
|
||||
// Sanitized earlier.
|
||||
$include_sql = implode( ',', $include );
|
||||
$orderby = "FIELD( $wpdb->users.ID, $include_sql )";
|
||||
} else {
|
||||
$orderby = 'user_login';
|
||||
}
|
||||
|
@ -734,8 +745,9 @@ class WP_User_Query {
|
|||
$this->query_fields = 'DISTINCT ' . $this->query_fields;
|
||||
}
|
||||
|
||||
if ( ! empty( $qv['include'] ) ) {
|
||||
$ids = implode( ',', wp_parse_id_list( $qv['include'] ) );
|
||||
if ( ! empty( $include ) ) {
|
||||
// Sanitized earlier.
|
||||
$ids = implode( ',', $include );
|
||||
$this->query_where .= " AND $wpdb->users.ID IN ($ids)";
|
||||
} elseif ( ! empty( $qv['exclude'] ) ) {
|
||||
$ids = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.1-alpha-30015';
|
||||
$wp_version = '4.1-alpha-30016';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue