AuthorRole.php
1.06 KB
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
47
48
49
50
51
52
53
54
55
<?php
namespace ACP\Search\Comparison\Post;
use AC;
use ACP\Search\Comparison;
use ACP\Search\Comparison\Values;
use ACP\Search\Helper\Sql\ComparisonFactory;
use ACP\Search\Operators;
use ACP\Search\Query\Bindings;
use ACP\Search\Value;
class AuthorRole extends Comparison implements Values {
public function __construct() {
$operators = new Operators( [
Operators::EQ,
] );
parent::__construct( $operators );
}
protected function create_query_bindings( $operator, Value $value ) {
global $wpdb;
$user_ids = get_users( [
'fields' => 'ids',
'role' => $value->get_value(),
] );
$where = ComparisonFactory::create(
$wpdb->posts . '.post_author',
Operators::IN,
new Value( $user_ids )
)->prepare();
$bindings = new Bindings();
$bindings->where( $where );
return $bindings;
}
public function get_values() {
$options = [];
foreach ( wp_roles()->roles as $key => $role ) {
$options[ $key ] = translate_user_role( $role['name'] );
}
asort( $options );
return AC\Helper\Select\Options::create_from_array( $options );
}
}