|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\Posts\Modules; |
|
4
|
|
|
|
|
5
|
|
|
use BulkWP\BulkDelete\Core\Posts\PostsModule; |
|
6
|
|
|
|
|
7
|
1 |
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Delete Posts by Status Module. |
|
11
|
|
|
* |
|
12
|
|
|
* @since 6.0.0 |
|
13
|
|
|
*/ |
|
14
|
|
|
class DeletePostsByStatusModule extends PostsModule { |
|
15
|
19 |
|
protected function initialize() { |
|
16
|
19 |
|
$this->item_type = 'posts'; |
|
17
|
19 |
|
$this->field_slug = 'post_status'; |
|
18
|
19 |
|
$this->meta_box_slug = 'bd_posts_by_status'; |
|
19
|
19 |
|
$this->action = 'delete_posts_by_status'; |
|
20
|
19 |
|
$this->cron_hook = 'do-bulk-delete-post-status'; |
|
21
|
19 |
|
$this->scheduler_url = 'http://bulkwp.com/addons/scheduler-for-deleting-posts-by-status/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-sps'; |
|
22
|
19 |
|
$this->messages = array( |
|
23
|
19 |
|
'box_label' => __( 'By Post Status', 'bulk-delete' ), |
|
24
|
19 |
|
'scheduled' => __( 'The selected posts are scheduled for deletion', 'bulk-delete' ), |
|
25
|
19 |
|
'cron_label' => __( 'Delete Post By Status', 'bulk-delete' ), |
|
26
|
|
|
); |
|
27
|
19 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function render() { |
|
30
|
|
|
?> |
|
31
|
|
|
<h4><?php _e( 'Select the post statuses from which you want to delete posts', 'bulk-delete' ); ?></h4> |
|
32
|
|
|
|
|
33
|
|
|
<fieldset class="options"> |
|
34
|
|
|
|
|
35
|
|
|
<table class="optiontable"> |
|
36
|
|
|
<?php $this->render_post_status(); ?> |
|
37
|
|
|
</table> |
|
38
|
|
|
|
|
39
|
|
|
<table class="optiontable"> |
|
40
|
|
|
<?php |
|
41
|
|
|
$this->render_filtering_table_header(); |
|
42
|
|
|
$this->render_restrict_settings(); |
|
43
|
|
|
$this->render_exclude_sticky_settings(); |
|
44
|
|
|
$this->render_delete_settings(); |
|
45
|
|
|
$this->render_limit_settings(); |
|
46
|
|
|
$this->render_cron_settings(); |
|
47
|
|
|
?> |
|
48
|
|
|
</table> |
|
49
|
|
|
|
|
50
|
|
|
</fieldset> |
|
51
|
|
|
|
|
52
|
|
|
<?php |
|
53
|
|
|
$this->render_submit_button(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
|
57
|
|
|
protected function append_to_js_array( $js_array ) { |
|
58
|
|
|
$js_array['error_msg'][ $this->action ] = 'selectPostStatus'; |
|
59
|
|
|
$js_array['pre_action_msg'][ $this->action ] = 'postStatusWarning'; |
|
60
|
|
|
|
|
61
|
|
|
$js_array['msg']['selectPostStatus'] = __( 'Please select at least one post status from which posts should be deleted', 'bulk-delete' ); |
|
62
|
|
|
$js_array['msg']['postStatusWarning'] = __( 'Are you sure you want to delete all the posts from the selected post status?', 'bulk-delete' ); |
|
63
|
|
|
|
|
64
|
|
|
return $js_array; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
|
68
|
|
|
$options['post_status'] = array_map( 'sanitize_text_field', bd_array_get( $request, 'smbd_' . $this->field_slug, array() ) ); |
|
69
|
|
|
|
|
70
|
|
|
return $options; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
protected function build_query( $options ) { |
|
74
|
|
|
if ( empty( $options['post_status'] ) ) { |
|
75
|
19 |
|
return array(); |
|
76
|
19 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
$query = array( |
|
79
|
|
|
'post_status' => $options['post_status'], |
|
80
|
|
|
); |
|
81
|
19 |
|
|
|
82
|
|
|
return $query; |
|
83
|
|
|
} |
|
84
|
19 |
|
|
|
85
|
|
|
protected function get_success_message( $items_deleted ) { |
|
86
|
|
|
/* translators: 1 Number of pages deleted */ |
|
87
|
|
|
return _n( 'Deleted %d post from the selected post status', 'Deleted %d posts from selected post status', $items_deleted, 'bulk-delete' ); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|