forked from scribu/wp-lib-posts-to-posts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query-user.php
47 lines (32 loc) · 962 Bytes
/
query-user.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
class P2P_Query_User {
static function init() {
add_action( 'pre_user_query', array( __CLASS__, 'pre_user_query' ), 20 );
}
static function pre_user_query( $query ) {
global $wpdb;
$r = P2P_Query::create_from_qv( $query->query_vars, 'user' );
if ( is_wp_error( $r ) ) {
$query->_p2p_error = $r;
$query->query_where = " AND 1=0";
return;
}
if ( null === $r )
return;
list( $p2p_q, $query->query_vars ) = $r;
$map = array(
'fields' => 'query_fields',
'join' => 'query_from',
'where' => 'query_where',
'orderby' => 'query_orderby',
);
$clauses = array();
foreach ( $map as $clause => $key )
$clauses[$clause] = $query->$key;
$clauses = $p2p_q->alter_clauses( $clauses, "$wpdb->users.ID" );
if ( 0 !== strpos( $clauses['orderby'], 'ORDER BY ' ) )
$clauses['orderby'] = 'ORDER BY ' . $clauses['orderby'];
foreach ( $map as $clause => $key )
$query->$key = $clauses[ $clause ];
}
}