1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\Terms\Modules; |
4
|
|
|
|
5
|
|
|
use BulkWP\BulkDelete\Core\Terms\TermsModule; |
6
|
|
|
|
7
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Delete Terms by Post Count. |
11
|
|
|
* |
12
|
|
|
* @since 6.0.0 |
13
|
|
|
*/ |
14
|
|
|
class DeleteTermsByPostCountModule extends TermsModule { |
15
|
|
|
protected function initialize() { |
16
|
|
|
$this->item_type = 'terms'; |
17
|
|
|
$this->field_slug = 'terms_by_post_count'; |
18
|
|
|
$this->meta_box_slug = 'bd_delete_terms_by_post_count'; |
19
|
|
|
$this->action = 'delete_terms_by_post_count'; |
20
|
|
|
$this->cron_hook = 'do-bulk-delete-term-by-post-count'; |
21
|
|
|
$this->scheduler_url = ''; |
22
|
|
|
$this->messages = array( |
23
|
|
|
'box_label' => __( 'Delete Terms by Post Count', 'bulk-delete' ), |
24
|
|
|
'scheduled' => __( 'The selected terms are scheduled for deletion', 'bulk-delete' ), |
25
|
|
|
'cron_label' => __( 'Delete Terms By Post Count', 'bulk-delete' ), |
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Render Delete terms by postfix and prefix box. |
31
|
|
|
*/ |
32
|
|
|
public function render() { |
33
|
|
|
?> |
34
|
|
|
<!-- Category Start--> |
35
|
|
|
<h4><?php _e( 'Select the taxonomy from which you want to delete terms', 'bulk-delete' ); ?></h4> |
36
|
|
|
<fieldset class="options"> |
37
|
|
|
<table class="optiontable"> |
38
|
|
|
<?php $this->render_taxonomy_dropdown(); ?> |
39
|
|
|
</table> |
40
|
|
|
|
41
|
|
|
<h4><?php _e( 'Select the post type', 'bulk-delete' ); ?></h4> |
42
|
|
|
<table class="optiontable"> |
43
|
|
|
<?php $this->render_post_type_dropdown(); ?> |
44
|
|
|
</table> |
45
|
|
|
|
46
|
|
|
<table class="optiontable"> |
47
|
|
|
<?php $this->render_term_options(); ?> |
48
|
|
|
</table> |
49
|
|
|
|
50
|
|
|
</fieldset> |
51
|
|
|
<?php |
52
|
|
|
$this->render_submit_button(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function filter_js_array( $js_array ) { |
56
|
|
|
$js_array['validators'][ $this->action ] = 'validatePostTypeSelect2'; |
57
|
|
|
$js_array['error_msg'][ $this->action ] = 'selectPostType'; |
58
|
|
|
$js_array['msg']['selectPostType'] = __( 'Please select at least one post type', 'bulk-delete' ); |
59
|
|
|
|
60
|
|
|
$js_array['dt_iterators'][] = '_' . $this->field_slug; |
61
|
|
|
|
62
|
|
|
return $js_array; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Process delete posts user inputs by category. |
67
|
|
|
* |
68
|
|
|
* @param array $request Request array. |
69
|
|
|
* @param array $options Options for deleting posts. |
70
|
|
|
* |
71
|
|
|
* @return array $options Inputs from user for posts that were need to delete |
72
|
|
|
*/ |
73
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
74
|
|
|
$options['taxonomy'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_taxonomy' ); |
75
|
|
|
$options['post_type'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_post_type' ); |
76
|
|
|
$options['term_opt'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_term_opt' ); |
77
|
|
|
$options['term_text'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_term_text' ); |
78
|
|
|
|
79
|
|
|
return $options; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Build query from delete options. |
84
|
|
|
* |
85
|
|
|
* @param array $options Delete options. |
86
|
|
|
* |
87
|
|
|
* @return array Query. |
88
|
|
|
*/ |
89
|
|
|
protected function build_query( $options ) { |
90
|
|
|
$query = array(); |
91
|
|
|
$taxonomy = $options['taxonomy']; |
92
|
|
|
$post_type = $options['post_type']; |
|
|
|
|
93
|
|
|
$term_opt = $options['term_opt']; |
|
|
|
|
94
|
|
|
$term_text = $options['term_text']; |
95
|
|
|
|
96
|
|
|
if( isset( $term_text ) ){ |
97
|
|
|
$query['taxonomy'] = $taxonomy; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$term_ids = $this->term_count_query( $options ); |
101
|
|
|
$query['include'] = $term_ids; |
102
|
|
|
|
103
|
|
|
return $query; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Response message for deleting posts. |
108
|
|
|
* |
109
|
|
|
* @param int $items_deleted Total number of posts deleted. |
110
|
|
|
* |
111
|
|
|
* @return string Response message |
112
|
|
|
*/ |
113
|
|
|
protected function get_success_message( $items_deleted ) { |
114
|
|
|
/* translators: 1 Number of posts deleted */ |
115
|
|
|
return _n( 'Deleted %d term with the selected options', 'Deleted %d terms with the selected options', $items_deleted, 'bulk-delete' ); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|