1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\Terms\QueryOverriders; |
4
|
|
|
|
5
|
|
|
use BulkWP\BulkDelete\Core\Base\BaseQueryOverrider; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Overrides query that is used for retrieving terms. |
9
|
|
|
* |
10
|
|
|
* @since 6.1.0 |
11
|
|
|
*/ |
12
|
|
|
class DeleteTermsQueryOverrider extends BaseQueryOverrider { |
13
|
|
|
/** |
14
|
|
|
* Comparison operator. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $operator; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The value that should be compared. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $db_column_value; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The db column name that should be compared. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $db_column_name; |
33
|
|
|
|
34
|
28 |
|
public function load() { |
35
|
28 |
|
add_action( 'parse_term_query', array( $this, 'parse_query' ) ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Parse the query and retrieve the values. |
40
|
|
|
* |
41
|
|
|
* @param array $query WP_Comment_Query arguments. |
42
|
|
|
*/ |
43
|
28 |
|
public function parse_query( $query ) { |
44
|
28 |
|
if ( isset( $query->query_vars['bd_operator'], $query->query_vars['bd_value'], $query->query_vars['bd_column_name'] ) ) { |
45
|
28 |
|
$this->operator = $query->query_vars['bd_operator']; |
46
|
28 |
|
$this->db_column_value = $query->query_vars['bd_value']; |
47
|
28 |
|
$this->db_column_name = $query->query_vars['bd_column_name']; |
48
|
|
|
|
49
|
28 |
|
add_filter( 'terms_clauses', array( $this, 'filter_where' ) ); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Modify the where clause. |
55
|
|
|
* |
56
|
|
|
* @param array $clauses Term clauses. |
57
|
|
|
* |
58
|
|
|
* @return array Modified term clauses. |
59
|
|
|
*/ |
60
|
28 |
|
public function filter_where( $clauses ) { |
61
|
28 |
|
if ( 'name' === $this->db_column_name ) { |
62
|
16 |
|
$this->db_column_value = "'" . $this->db_column_value . "'"; |
63
|
|
|
} |
64
|
28 |
|
$clauses['where'] .= sprintf( ' AND %s %s %s ', esc_sql( $this->db_column_name ), esc_sql( $this->operator ), $this->db_column_value ); |
|
|
|
|
65
|
|
|
|
66
|
28 |
|
$this->remove_where_filter(); |
67
|
|
|
|
68
|
28 |
|
return $clauses; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Remove the where filter. |
73
|
|
|
*/ |
74
|
28 |
|
public function remove_where_filter() { |
75
|
28 |
|
remove_filter( 'terms_clauses', array( $this, 'filter_where' ) ); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|