|
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 = 'by_post_count'; |
|
18
|
|
|
$this->meta_box_slug = 'bd_by_post_count'; |
|
19
|
|
|
$this->action = 'delete_terms_by_post_count'; |
|
20
|
|
|
$this->cron_hook = 'do-bulk-delete-term-post-count'; |
|
21
|
|
|
$this->scheduler_url = 'http://bulkwp.com/addons/scheduler-for-deleting-posts-by-category/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-sc'; |
|
22
|
|
|
$this->messages = array( |
|
23
|
|
|
'box_label' => __( 'By Terms by Post Count', 'bulk-delete' ), |
|
24
|
|
|
'scheduled' => __( 'The selected posts 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', '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
|
|
|
return $query; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Response message for deleting posts. |
|
105
|
|
|
* |
|
106
|
|
|
* @param int $items_deleted Total number of posts deleted. |
|
107
|
|
|
* |
|
108
|
|
|
* @return string Response message |
|
109
|
|
|
*/ |
|
110
|
|
|
protected function get_success_message( $items_deleted ) { |
|
111
|
|
|
/* translators: 1 Number of posts deleted */ |
|
112
|
|
|
return _n( 'Deleted %d term with the selected options', 'Deleted %d terms with the selected options', $items_deleted, 'bulk-delete' ); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|