|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\Posts\Metabox; |
|
4
|
|
|
|
|
5
|
|
|
use BulkWP\BulkDelete\Core\Posts\PostsMetabox; |
|
6
|
|
|
|
|
7
|
1 |
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Delete Posts by Status Metabox. |
|
11
|
|
|
* |
|
12
|
|
|
* @since 6.0.0 |
|
13
|
|
|
*/ |
|
14
|
|
|
class DeletePostsByStatusMetabox extends PostsMetabox { |
|
15
|
11 |
|
protected function initialize() { |
|
16
|
11 |
|
$this->item_type = 'posts'; |
|
17
|
11 |
|
$this->field_slug = 'post_status'; |
|
18
|
11 |
|
$this->meta_box_slug = 'bd_posts_by_status'; |
|
19
|
11 |
|
$this->action = 'delete_posts_by_status'; |
|
20
|
11 |
|
$this->cron_hook = 'do-bulk-delete-post-by-status'; |
|
21
|
11 |
|
$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
|
11 |
|
$this->messages = array( |
|
23
|
11 |
|
'box_label' => __( 'By Post Status', 'bulk-delete' ), |
|
24
|
11 |
|
'scheduled' => __( 'The selected posts are scheduled for deletion', 'bulk-delete' ), |
|
25
|
|
|
); |
|
26
|
11 |
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function render() { |
|
29
|
|
|
$post_statuses = $this->get_post_statuses(); |
|
30
|
|
|
$post_count = wp_count_posts(); |
|
31
|
|
|
?> |
|
32
|
|
|
<h4><?php _e( 'Select the post statuses from which you want to delete posts', 'bulk-delete' ); ?></h4> |
|
33
|
|
|
|
|
34
|
|
|
<fieldset class="options"> |
|
35
|
|
|
<table class="optiontable"> |
|
36
|
|
|
|
|
37
|
|
|
<?php foreach ( $post_statuses as $post_status ) : ?> |
|
38
|
|
|
<tr> |
|
39
|
|
|
<td> |
|
40
|
|
|
<input name="smbd_post_status[]" id="smbd_<?php echo esc_attr( $post_status->name ); ?>" |
|
41
|
|
|
value="<?php echo esc_attr( $post_status->name ); ?>" type="checkbox"> |
|
42
|
|
|
|
|
43
|
|
|
<label for="smbd_<?php echo esc_attr( $post_status->name ); ?>"> |
|
44
|
|
|
<?php echo esc_html( $post_status->label ), ' '; ?> |
|
45
|
|
|
<?php if ( property_exists( $post_count, $post_status->name ) ) : ?> |
|
46
|
|
|
(<?php echo absint( $post_count->{ $post_status->name } ) . ' ', __( 'Posts', 'bulk-delete' ); ?>) |
|
47
|
|
|
<?php endif; ?> |
|
48
|
|
|
</label> |
|
49
|
|
|
</td> |
|
50
|
|
|
</tr> |
|
51
|
|
|
<?php endforeach; ?> |
|
52
|
|
|
|
|
53
|
|
|
<?php $sticky_post_count = count( get_option( 'sticky_posts' ) ); ?> |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
<tr> |
|
56
|
|
|
<td> |
|
57
|
|
|
<input name="smbd_sticky" id="smbd_sticky" value="on" type="checkbox"> |
|
58
|
|
|
<label for="smbd_sticky"> |
|
59
|
|
|
<?php echo __( 'All Sticky Posts', 'bulk-delete' ), ' '; ?> |
|
60
|
|
|
(<?php echo absint( $sticky_post_count ), ' ', __( 'Posts', 'bulk-delete' ); ?>) |
|
61
|
|
|
<?php echo '<strong>', __( 'Note', 'bulk-delete' ), '</strong>: ', __( 'The date filter will not work for sticky posts', 'bulk-delete' ); ?> |
|
62
|
|
|
</label> |
|
63
|
|
|
</td> |
|
64
|
|
|
</tr> |
|
65
|
|
|
|
|
66
|
|
|
</table> |
|
67
|
|
|
|
|
68
|
|
|
<table class="optiontable"> |
|
69
|
|
|
<?php |
|
70
|
|
|
$this->render_filtering_table_header(); |
|
71
|
|
|
$this->render_restrict_settings(); |
|
72
|
|
|
$this->render_delete_settings(); |
|
73
|
|
|
$this->render_limit_settings(); |
|
74
|
|
|
$this->render_cron_settings(); |
|
75
|
|
|
?> |
|
76
|
|
|
</table> |
|
77
|
|
|
|
|
78
|
|
|
</fieldset> |
|
79
|
|
|
<?php |
|
80
|
|
|
$this->render_submit_button(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
|
84
|
|
|
$options['post_status'] = array_map( 'sanitize_text_field', bd_array_get( $request, 'smbd_post_status', array() ) ); |
|
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
$options['delete-sticky-posts'] = bd_array_get_bool( $request, 'smbd_sticky', false ); |
|
87
|
|
|
|
|
88
|
|
|
return $options; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
11 |
|
/** |
|
92
|
11 |
|
* Delete Sticky post in addition to posts by status. |
|
93
|
11 |
|
* |
|
94
|
|
|
* @param array $options Delete options. |
|
95
|
11 |
|
* |
|
96
|
|
|
* @return int Number of posts deleted. |
|
97
|
11 |
|
*/ |
|
98
|
|
|
public function delete( $options ) { |
|
99
|
|
|
$posts_deleted = parent::delete( $options ); |
|
100
|
|
|
|
|
101
|
11 |
|
if ( isset( $options['delete-sticky-posts'] ) ) { |
|
102
|
|
|
$posts_deleted += $this->delete_sticky_posts( $options['force_delete'] ); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $posts_deleted; |
|
106
|
11 |
|
} |
|
107
|
11 |
|
|
|
108
|
|
|
protected function build_query( $options ) { |
|
109
|
|
|
if ( empty( $options['post_status'] ) ) { |
|
110
|
11 |
|
return array(); |
|
111
|
|
|
} |
|
112
|
11 |
|
|
|
113
|
11 |
|
$query = array( |
|
114
|
11 |
|
'post_status' => $options['post_status'], |
|
115
|
|
|
'post__not_in' => get_option( 'sticky_posts' ), |
|
116
|
|
|
); |
|
117
|
11 |
|
|
|
118
|
|
|
return $query; |
|
119
|
11 |
|
} |
|
120
|
|
|
|
|
121
|
|
|
protected function get_success_message( $items_deleted ) { |
|
122
|
|
|
/* translators: 1 Number of pages deleted */ |
|
123
|
|
|
return _n( 'Deleted %d post with the selected post status', 'Deleted %d posts with the selected post status', $items_deleted, 'bulk-delete' ); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|