1
|
|
|
<?php |
2
|
|
|
namespace BulkWP\BulkDelete\Core\Metas\Modules; |
3
|
|
|
|
4
|
|
|
use BulkWP\BulkDelete\Core\Metas\MetasModule; |
5
|
|
|
|
6
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Delete Term Meta. |
10
|
|
|
* |
11
|
|
|
* @since 6.1.0 |
12
|
|
|
*/ |
13
|
|
|
class DeleteTermMetaModule extends MetasModule { |
14
|
|
|
/** |
15
|
|
|
* Initialize the Module. |
16
|
|
|
*/ |
17
|
|
|
protected function initialize() { |
18
|
|
|
$this->field_slug = 'meta_term'; |
19
|
|
|
$this->meta_box_slug = 'bd-meta-term'; |
20
|
|
|
$this->action = 'delete_meta_term'; |
21
|
|
|
$this->cron_hook = 'do-bulk-delete-term-meta'; |
22
|
|
|
$this->messages = array( |
23
|
|
|
'box_label' => __( 'Bulk Delete Term Meta', 'bulk-delete' ), |
24
|
|
|
'scheduled' => __( 'Term meta fields from the posts with the selected criteria are scheduled for deletion.', 'bulk-delete' ), |
25
|
|
|
'cron_label' => __( 'Delete Term Meta', 'bulk-delete' ), |
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Render the Modules. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function render() { |
35
|
|
|
?> |
36
|
|
|
<!-- Term Meta box start--> |
37
|
|
|
<fieldset class="options"> |
38
|
|
|
<?php |
39
|
|
|
$taxonomies = $this->get_taxonomies(); |
40
|
|
|
?> |
41
|
|
|
<h4><?php _e( 'Select the taxonomy whose term meta fields you want to delete', 'bulk-delete' ); ?></h4> |
42
|
|
|
<table class="optiontable"> |
43
|
|
|
<?php |
44
|
|
|
foreach ( $taxonomies as $taxonomy ) { |
45
|
|
|
?> |
46
|
|
|
<tr> |
47
|
|
|
<td> |
48
|
|
|
<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_taxonomy" value = "<?php echo $taxonomy; ?>" type = "radio" class = "smbd_<?php echo esc_attr( $this->field_slug ); ?>_taxonomy"> |
49
|
|
|
<label for="smbd_<?php echo esc_attr( $this->field_slug ); ?>_taxonomy"><?php echo $taxonomy; ?> </label> |
50
|
|
|
</td> |
51
|
|
|
</tr> |
52
|
|
|
<?php |
53
|
|
|
} |
54
|
|
|
?> |
55
|
|
|
</table> |
56
|
|
|
|
57
|
|
|
<h4><?php _e( 'Choose your term want to delete', 'bulk-delete' ); ?></h4> |
58
|
|
|
<table class="optiontable"> |
59
|
|
|
<tr> |
60
|
|
|
<td> |
61
|
|
|
<select class="enhanced-terms-dropdown" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_term"> |
62
|
|
|
<option>Choose Terms</option> |
63
|
|
|
</select> |
64
|
|
|
</td> |
65
|
|
|
</tr> |
66
|
|
|
</table> |
67
|
|
|
|
68
|
|
|
<h4><?php _e( 'Choose your term meta want to delete', 'bulk-delete' ); ?></h4> |
69
|
|
|
<table class="optiontable"> |
70
|
|
|
<tr> |
71
|
|
|
<td> |
72
|
|
|
<select class="enhanced-term-meta-dropdown" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_term_meta"> |
73
|
|
|
<option>Choose Term Meta</option> |
74
|
|
|
</select> |
75
|
|
|
|
76
|
|
|
<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_term_meta_option"> |
77
|
|
|
<option value="equal">Equal to</option> |
78
|
|
|
<option value="not_equal">Not equal to</option> |
79
|
|
|
</select> |
80
|
|
|
|
81
|
|
|
<input type="text" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_term_meta_value" /> |
82
|
|
|
</td> |
83
|
|
|
</tr> |
84
|
|
|
</table> |
85
|
|
|
|
86
|
|
|
<?php |
87
|
|
|
/** |
88
|
|
|
* Add more fields to the delete post meta field form. |
89
|
|
|
* This hook can be used to add more fields to the delete post meta field form. |
90
|
|
|
* |
91
|
|
|
* @since 5.4 |
92
|
|
|
*/ |
93
|
|
|
do_action( 'bd_delete_post_meta_form' ); |
94
|
|
|
?> |
95
|
|
|
|
96
|
|
|
</fieldset> |
97
|
|
|
|
98
|
|
|
<p> |
99
|
|
|
<button type="submit" name="bd_action" value="delete_meta_term" class="button-primary"><?php _e( 'Bulk Delete ', 'bulk-delete' ); ?>»</button> |
100
|
|
|
</p> |
101
|
|
|
<!-- Term Meta box end--> |
102
|
|
|
<?php |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Convert user input to bulkwp standard. |
107
|
|
|
* |
108
|
|
|
* @param array $request Request array. |
109
|
|
|
* @param array $options User options. |
110
|
|
|
* |
111
|
|
|
* @return array User options. |
112
|
|
|
*/ |
113
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
114
|
|
|
$options['term'] = esc_sql( bd_array_get( $request, 'smbd_' . $this->field_slug . '_term', 'term' ) ); |
115
|
|
|
|
116
|
|
|
$options['term_meta'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_term_meta', 'term_meta' ); |
117
|
|
|
$options['term_meta_value'] = esc_sql( bd_array_get( $request, 'smbd_' . $this->field_slug . '_term_meta_value', '' ) ); |
118
|
|
|
|
119
|
|
|
$options['term_meta_option'] = esc_sql( bd_array_get( $request, 'smbd_' . $this->field_slug . '_term_meta_option', '' ) ); |
120
|
|
|
|
121
|
|
|
return $options; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Delete action. |
126
|
|
|
* |
127
|
|
|
* @param array $options User options. |
128
|
|
|
*/ |
129
|
|
|
public function do_delete( $options ) { |
130
|
|
|
$count = 0; |
131
|
|
|
|
132
|
|
|
if ( $options['term_meta_option'] === 'equal' ) { |
133
|
|
|
$is_delete = delete_term_meta( $options['term'], $options['term_meta'], $options['term_meta_value'] ); |
134
|
|
|
if ( $is_delete ) { |
135
|
|
|
$count++; |
136
|
|
|
} |
137
|
|
|
} elseif ( $options['term_meta_option'] === 'not_equal' ) { |
138
|
|
|
$term_value = get_term_meta( $options['term'], $options['term_meta'], true ); |
139
|
|
|
if ( $term_value !== $options['term_meta_value'] ) { |
140
|
|
|
delete_term_meta( $options['term'], $options['term_meta'] ); |
141
|
|
|
$count++; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return $count; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Filter JS Array and add pro hooks. |
150
|
|
|
* |
151
|
|
|
* @param array $js_array JavaScript Array. |
152
|
|
|
* |
153
|
|
|
* @return array Modified JavaScript Array. |
154
|
|
|
*/ |
155
|
|
|
public function filter_js_array( $js_array ) { |
156
|
|
|
$js_array['dt_iterators'][] = '_' . $this->field_slug; |
157
|
|
|
$js_array['validators']['delete_meta_term'] = 'noValidation'; |
158
|
|
|
|
159
|
|
|
$js_array['pre_action_msg']['delete_meta_term'] = 'deleteTMWarning'; |
160
|
|
|
$js_array['msg']['deleteTMWarning'] = __( 'Are you sure you want to delete all the term meta fields?', 'bulk-delete' ); |
161
|
|
|
|
162
|
|
|
return $js_array; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Get Success Message. |
167
|
|
|
* |
168
|
|
|
* @param int $items_deleted Number of items that were deleted. |
169
|
|
|
* |
170
|
|
|
* @return string Success message. |
171
|
|
|
*/ |
172
|
|
|
protected function get_success_message( $items_deleted ) { |
173
|
|
|
/* translators: 1 Number of posts deleted */ |
174
|
|
|
return _n( 'Deleted %d term meta field', 'Deleted %d term meta field', $items_deleted, 'bulk-delete' ); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|