Skip to content

Commit

Permalink
Find virtual users by name
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Feb 3, 2024
1 parent 4c9e78f commit e508a8b
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions includes/class-user-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,36 @@ public function add_virtual_subscriptions( $args = array() ) {
if ( isset( $args['meta_key'] ) && substr( $args['meta_key'], -9 ) === '_starred' ) {
$args['meta_key'] = 'starred';
}
$searches = array();

if ( isset( $args['search'] ) ) {
$args['search'] = str_replace( '*', '', $args['search'] );
// WP_Term_Query will add wildcarts before and after.
$args['search'] = trim( $args['search'], '*' );
$searches[] = $args;
$searches[] = array(
'meta_key' => 'display_name',
'meta_value' => $args['search'],
'meta_compare' => 'LIKE',
);
} else {
$searches[] = $args;
}

$term_query = new \WP_Term_Query(
array_merge(
array(
'taxonomy' => Subscription::TAXONOMY,
'hide_empty' => false,
),
$args
)
);
foreach ( $searches as $args ) {
$term_query = new \WP_Term_Query(
array_merge(
array(
'taxonomy' => Subscription::TAXONOMY,
'hide_empty' => false,
),
$args
)
);

foreach ( $term_query->get_terms() as $term ) {
$this->results[] = new Subscription( $term );
$this->total_users += 1;
foreach ( $term_query->get_terms() as $term ) {
$this->results[] = new Subscription( $term );
$this->total_users += 1;
}
}
}
public function sort( $field, $direction ) {
Expand Down

0 comments on commit e508a8b

Please sign in to comment.