1
|
|
|
<?php |
2
|
|
|
namespace BulkWP\BulkDelete\Core\Pages\Metabox; |
3
|
|
|
|
4
|
|
|
use BulkWP\BulkDelete\Core\Pages\PagesMetabox; |
5
|
|
|
|
6
|
1 |
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Delete Pages by Status Metabox. |
10
|
|
|
* |
11
|
|
|
* @since 6.0.0 |
12
|
|
|
*/ |
13
|
|
|
class DeletePagesByStatusMetabox extends PagesMetabox { |
14
|
|
|
protected function initialize() { |
15
|
|
|
$this->item_type = 'pages'; |
16
|
|
|
$this->field_slug = 'pages'; |
17
|
|
|
$this->meta_box_slug = 'bd_pages_by_status'; |
18
|
|
|
$this->action = 'delete_pages_by_status'; |
19
|
|
|
$this->cron_hook = 'do-bulk-delete-pages-by-status'; |
20
|
|
|
$this->scheduler_url = 'http://bulkwp.com/addons/scheduler-for-deleting-pages-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 pages are scheduled for deletion', 'bulk-delete' ), |
24
|
|
|
); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function render() { |
28
|
|
|
$pages_count = wp_count_posts( 'page' ); |
29
|
|
|
$pages = $pages_count->publish; |
30
|
|
|
$page_drafts = $pages_count->draft; |
31
|
|
|
$page_future = $pages_count->future; |
32
|
|
|
$page_pending = $pages_count->pending; |
33
|
|
|
$page_private = $pages_count->private; |
34
|
|
|
?> |
35
|
|
|
<!-- Pages start--> |
36
|
|
|
<h4><?php _e( 'Select the status from which you want to delete pages', 'bulk-delete' ); ?></h4> |
37
|
|
|
|
38
|
|
|
<fieldset class="options"> |
39
|
|
|
<table class="optiontable"> |
40
|
|
|
<tr> |
41
|
|
|
<td> |
42
|
|
|
<input name="smbd_published_pages" value="published_pages" type="checkbox"> |
43
|
|
|
<label for="smbd_published_pages"><?php _e( 'All Published Pages', 'bulk-delete' ); ?> (<?php echo $pages . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label> |
44
|
|
|
</td> |
45
|
|
|
</tr> |
46
|
|
|
|
47
|
|
|
<tr> |
48
|
|
|
<td> |
49
|
|
|
<input name="smbd_draft_pages" value="draft_pages" type="checkbox"> |
50
|
|
|
<label for="smbd_draft_pages"><?php _e( 'All Draft Pages', 'bulk-delete' ); ?> (<?php echo $page_drafts . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label> |
51
|
|
|
</td> |
52
|
|
|
</tr> |
53
|
|
|
|
54
|
|
|
<tr> |
55
|
|
|
<td> |
56
|
|
|
<input name="smbd_future_pages" value="scheduled_pages" type="checkbox"> |
57
|
|
|
<label for="smbd_future_pages"><?php _e( 'All Scheduled Pages', 'bulk-delete' ); ?> (<?php echo $page_future . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label> |
58
|
|
|
</td> |
59
|
|
|
</tr> |
60
|
|
|
|
61
|
|
|
<tr> |
62
|
|
|
<td> |
63
|
|
|
<input name="smbd_pending_pages" value="pending_pages" type="checkbox"> |
64
|
|
|
<label for="smbd_pending_pages"><?php _e( 'All Pending Pages', 'bulk-delete' ); ?> (<?php echo $page_pending . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label> |
65
|
|
|
</td> |
66
|
|
|
</tr> |
67
|
|
|
|
68
|
|
|
<tr> |
69
|
|
|
<td> |
70
|
|
|
<input name="smbd_private_pages" value="private_pages" type="checkbox"> |
71
|
|
|
<label for="smbd_private_pages"><?php _e( 'All Private Pages', 'bulk-delete' ); ?> (<?php echo $page_private . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label> |
72
|
|
|
</td> |
73
|
|
|
</tr> |
74
|
|
|
</table> |
75
|
|
|
|
76
|
|
|
<table class="optiontable"> |
77
|
|
|
<?php |
78
|
|
|
$this->render_filtering_table_header(); |
79
|
|
|
$this->render_restrict_settings(); |
80
|
|
|
$this->render_delete_settings(); |
81
|
|
|
$this->render_limit_settings(); |
82
|
|
|
$this->render_cron_settings(); |
83
|
|
|
?> |
84
|
|
|
</table> |
85
|
|
|
</fieldset> |
86
|
|
|
<?php |
87
|
|
|
$this->render_submit_button(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
91
|
|
|
$options['publish'] = bd_array_get( $request, 'smbd_published_pages' ); |
92
|
|
|
$options['drafts'] = bd_array_get( $request, 'smbd_draft_pages' ); |
93
|
|
|
$options['pending'] = bd_array_get( $request, 'smbd_pending_pages' ); |
94
|
|
|
$options['future'] = bd_array_get( $request, 'smbd_future_pages' ); |
95
|
|
|
$options['private'] = bd_array_get( $request, 'smbd_private_pages' ); |
96
|
|
|
|
97
|
|
|
return $options; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function delete( $delete_options ) { |
101
|
|
|
global $wp_query; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Filter Delete options. |
105
|
|
|
* |
106
|
|
|
* @param array $delete_options Delete options. |
107
|
|
|
*/ |
108
|
|
|
$delete_options = apply_filters( 'bd_delete_options', $delete_options ); |
109
|
|
|
|
110
|
|
|
$post_status = array(); |
111
|
|
|
|
112
|
|
|
// published pages |
113
|
|
|
if ( 'published_pages' == $delete_options['publish'] ) { |
114
|
|
|
$post_status[] = 'publish'; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
// Drafts |
118
|
|
|
if ( 'draft_pages' == $delete_options['drafts'] ) { |
119
|
|
|
$post_status[] = 'draft'; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
// Pending pages |
123
|
|
|
if ( 'pending_pages' == $delete_options['pending'] ) { |
124
|
|
|
$post_status[] = 'pending'; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// Future pages |
128
|
|
|
if ( 'future_pages' == $delete_options['future'] ) { |
129
|
|
|
$post_status[] = 'future'; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
// Private pages |
133
|
|
|
if ( 'private_pages' == $delete_options['private'] ) { |
134
|
|
|
$post_status[] = 'private'; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$options = array( |
138
|
|
|
'post_type' => 'page', |
139
|
|
|
'post_status' => $post_status, |
140
|
|
|
); |
141
|
|
|
|
142
|
|
|
$options = bd_build_query_options( $delete_options, $options ); |
143
|
|
|
$pages = $wp_query->query( $options ); |
144
|
|
|
foreach ( $pages as $page ) { |
145
|
|
|
wp_delete_post( $page->ID, $delete_options['force_delete'] ); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
return count( $pages ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
protected function get_success_message( $items_deleted ) { |
152
|
|
|
/* translators: 1 Number of pages deleted */ |
153
|
|
|
return _n( 'Deleted %d page with the selected page status', 'Deleted %d pages with the selected page status', $items_deleted, 'bulk-delete' ); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|