|
1
|
|
|
<?php |
|
2
|
|
|
namespace BulkWP\BulkDelete\Core\Posts\Metabox; |
|
3
|
|
|
|
|
4
|
|
|
use BulkWP\BulkDelete\Core\Posts\PostsMetabox; |
|
5
|
|
|
|
|
6
|
1 |
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Delete Posts by Status Metabox. |
|
10
|
|
|
* |
|
11
|
|
|
* @since 6.0.0 |
|
12
|
|
|
*/ |
|
13
|
|
|
class DeletePostsByStatusMetabox extends PostsMetabox { |
|
14
|
|
|
protected function initialize() { |
|
15
|
|
|
$this->item_type = 'posts'; |
|
16
|
|
|
$this->field_slug = 'posts'; |
|
17
|
|
|
$this->meta_box_slug = 'bd_posts_by_status'; |
|
18
|
|
|
$this->action = 'delete_posts_by_status'; |
|
19
|
|
|
$this->cron_hook = 'do-bulk-delete-posts-by-status'; |
|
20
|
|
|
$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-sp'; |
|
21
|
|
|
$this->messages = array( |
|
22
|
|
|
'box_label' => __( 'By Page Status', 'bulk-delete' ), |
|
23
|
|
|
'scheduled' => __( 'The selected posts are scheduled for deletion', 'bulk-delete' ), |
|
24
|
|
|
); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function render() { |
|
28
|
|
|
$post_statuses = $this->get_post_statuses(); |
|
|
|
|
|
|
29
|
|
|
$post_count = wp_count_posts(); |
|
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
|
|
|
<table class="optiontable"> |
|
35
|
|
|
|
|
36
|
|
|
<?php foreach ( $post_statuses as $post_status ) : ?> |
|
37
|
|
|
<tr> |
|
38
|
|
|
<td> |
|
39
|
|
|
<input name="smbd_post_status[]" id="smbd_<?php echo esc_attr( $post_status->name ); ?>" |
|
40
|
|
|
value="<?php echo esc_attr( $post_status->name ); ?>" type="checkbox"> |
|
41
|
|
|
|
|
42
|
|
|
<label for="smbd_<?php echo esc_attr( $post_status->name ); ?>"> |
|
43
|
|
|
<?php echo esc_html( $post_status->label ), ' '; ?> |
|
44
|
|
|
<?php if ( property_exists( $post_count, $post_status->name ) ) : ?> |
|
45
|
|
|
(<?php echo absint( $post_count->{ $post_status->name } ) . ' ', __( 'Posts', 'bulk-delete' ); ?>) |
|
46
|
|
|
<?php endif; ?> |
|
47
|
|
|
</label> |
|
48
|
|
|
</td> |
|
49
|
|
|
</tr> |
|
50
|
|
|
<?php endforeach; ?> |
|
51
|
|
|
|
|
52
|
|
|
<?php $sticky_post_count = count( get_option( 'sticky_posts' ) ); ?> |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
<tr> |
|
55
|
|
|
<td> |
|
56
|
|
|
<input name="smbd_sticky" id="smbd_sticky" value="on" type="checkbox"> |
|
57
|
|
|
<label for="smbd_sticky"> |
|
58
|
|
|
<?php echo __( 'All Sticky Posts', 'bulk-delete' ), ' '; ?> |
|
59
|
|
|
(<?php echo absint( $sticky_post_count ), ' ', __( 'Posts', 'bulk-delete' ); ?>) |
|
60
|
|
|
<?php echo '<strong>', __( 'Note', 'bulk-delete' ), '</strong>: ', __( 'The date filter will not work for sticky posts', 'bulk-delete' ); ?> |
|
61
|
|
|
</label> |
|
62
|
|
|
</td> |
|
63
|
|
|
</tr> |
|
64
|
|
|
|
|
65
|
|
|
</table> |
|
66
|
|
|
|
|
67
|
|
|
<table class="optiontable"> |
|
68
|
|
|
<?php |
|
69
|
|
|
$this->render_filtering_table_header(); |
|
70
|
|
|
$this->render_restrict_settings(); |
|
71
|
|
|
$this->render_delete_settings(); |
|
72
|
|
|
$this->render_limit_settings(); |
|
73
|
|
|
$this->render_cron_settings(); |
|
74
|
|
|
?> |
|
75
|
|
|
</table> |
|
76
|
|
|
|
|
77
|
|
|
</fieldset> |
|
78
|
|
|
<?php |
|
79
|
|
|
$this->render_submit_button( 'delete_posts_by_status' ); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
|
83
|
|
|
$options['publish'] = bd_array_get( $request, 'smbd_published_pages' ); |
|
84
|
|
|
$options['drafts'] = bd_array_get( $request, 'smbd_draft_pages' ); |
|
85
|
|
|
$options['pending'] = bd_array_get( $request, 'smbd_pending_pages' ); |
|
86
|
|
|
$options['future'] = bd_array_get( $request, 'smbd_future_pages' ); |
|
87
|
|
|
$options['private'] = bd_array_get( $request, 'smbd_private_pages' ); |
|
88
|
|
|
|
|
89
|
|
|
return $options; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function delete( $delete_options ) { |
|
93
|
|
|
global $wp_query; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Filter Delete options. |
|
97
|
|
|
* |
|
98
|
|
|
* @param array $delete_options Delete options. |
|
99
|
|
|
*/ |
|
100
|
|
|
$delete_options = apply_filters( 'bd_delete_options', $delete_options ); |
|
101
|
|
|
|
|
102
|
|
|
$post_status = array(); |
|
103
|
|
|
|
|
104
|
|
|
// published pages |
|
105
|
|
|
if ( 'published_pages' == $delete_options['publish'] ) { |
|
106
|
|
|
$post_status[] = 'publish'; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
// Drafts |
|
110
|
|
|
if ( 'draft_pages' == $delete_options['drafts'] ) { |
|
111
|
|
|
$post_status[] = 'draft'; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
// Pending pages |
|
115
|
|
|
if ( 'pending_pages' == $delete_options['pending'] ) { |
|
116
|
|
|
$post_status[] = 'pending'; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
// Future pages |
|
120
|
|
|
if ( 'future_pages' == $delete_options['future'] ) { |
|
121
|
|
|
$post_status[] = 'future'; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
// Private pages |
|
125
|
|
|
if ( 'private_pages' == $delete_options['private'] ) { |
|
126
|
|
|
$post_status[] = 'private'; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$options = array( |
|
130
|
|
|
'post_type' => 'page', |
|
131
|
|
|
'post_status' => $post_status, |
|
132
|
|
|
); |
|
133
|
|
|
|
|
134
|
|
|
$options = bd_build_query_options( $delete_options, $options ); |
|
135
|
|
|
$pages = $wp_query->query( $options ); |
|
136
|
|
|
foreach ( $pages as $page ) { |
|
137
|
|
|
wp_delete_post( $page->ID, $delete_options['force_delete'] ); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
return count( $pages ); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
protected function get_success_message( $items_deleted ) { |
|
144
|
|
|
/* translators: 1 Number of pages deleted */ |
|
145
|
|
|
return _n( 'Deleted %d page with the selected page status', 'Deleted %d pages with the selected page status', $items_deleted, 'bulk-delete' ); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.