1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Utility class for deleting pages. |
4
|
|
|
* |
5
|
|
|
* @since 5.0 |
6
|
|
|
* |
7
|
|
|
* @author Sudar |
8
|
|
|
* |
9
|
|
|
* @package BulkDelete |
10
|
|
|
*/ |
11
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
12
|
|
|
|
13
|
|
|
class Bulk_Delete_Pages { |
14
|
|
|
/** |
15
|
|
|
* Render delete pages by page status box. |
16
|
|
|
* |
17
|
|
|
* @access public |
18
|
|
|
* @static |
19
|
|
|
* |
20
|
|
|
* @since 5.0 |
21
|
|
|
*/ |
22
|
|
|
public static function render_delete_pages_by_status_box() { |
23
|
|
|
if ( BD_Util::is_pages_box_hidden( Bulk_Delete::BOX_PAGE_STATUS ) ) { |
24
|
|
|
printf( __( 'This section just got enabled. Kindly <a href = "%1$s">refresh</a> the page to fully enable it.', 'bulk-delete' ), 'admin.php?page=' . Bulk_Delete::PAGES_PAGE_SLUG ); |
25
|
|
|
|
26
|
|
|
return; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$pages_count = wp_count_posts( 'page' ); |
30
|
|
|
$pages = $pages_count->publish; |
31
|
|
|
$page_drafts = $pages_count->draft; |
32
|
|
|
$page_future = $pages_count->future; |
33
|
|
|
$page_pending = $pages_count->pending; |
34
|
|
|
$page_private = $pages_count->private; |
35
|
|
|
?> |
36
|
|
|
<!-- Pages start--> |
37
|
|
|
<h4><?php _e( 'Select the status from which you want to delete pages', 'bulk-delete' ); ?></h4> |
38
|
|
|
|
39
|
|
|
<fieldset class="options"> |
40
|
|
|
<table class="optiontable"> |
41
|
|
|
<tr> |
42
|
|
|
<td> |
43
|
|
|
<input name="smbd_published_pages" value="published_pages" type="checkbox"> |
44
|
|
|
<label for="smbd_published_pages"><?php _e( 'All Published Pages', 'bulk-delete' ); ?> (<?php echo $pages . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label> |
45
|
|
|
</td> |
46
|
|
|
</tr> |
47
|
|
|
|
48
|
|
|
<tr> |
49
|
|
|
<td> |
50
|
|
|
<input name="smbd_draft_pages" value="draft_pages" type="checkbox"> |
51
|
|
|
<label for="smbd_draft_pages"><?php _e( 'All Draft Pages', 'bulk-delete' ); ?> (<?php echo $page_drafts . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label> |
52
|
|
|
</td> |
53
|
|
|
</tr> |
54
|
|
|
|
55
|
|
|
<tr> |
56
|
|
|
<td> |
57
|
|
|
<input name="smbd_future_pages" value="scheduled_pages" type="checkbox"> |
58
|
|
|
<label for="smbd_future_pages"><?php _e( 'All Scheduled Pages', 'bulk-delete' ); ?> (<?php echo $page_future . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label> |
59
|
|
|
</td> |
60
|
|
|
</tr> |
61
|
|
|
|
62
|
|
|
<tr> |
63
|
|
|
<td> |
64
|
|
|
<input name="smbd_pending_pages" value="pending_pages" type="checkbox"> |
65
|
|
|
<label for="smbd_pending_pages"><?php _e( 'All Pending Pages', 'bulk-delete' ); ?> (<?php echo $page_pending . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label> |
66
|
|
|
</td> |
67
|
|
|
</tr> |
68
|
|
|
|
69
|
|
|
<tr> |
70
|
|
|
<td> |
71
|
|
|
<input name="smbd_private_pages" value="private_pages" type="checkbox"> |
72
|
|
|
<label for="smbd_private_pages"><?php _e( 'All Private Pages', 'bulk-delete' ); ?> (<?php echo $page_private . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label> |
73
|
|
|
</td> |
74
|
|
|
</tr> |
75
|
|
|
</table> |
76
|
|
|
|
77
|
|
|
<table class="optiontable"> |
78
|
|
|
<?php |
79
|
|
|
bd_render_filtering_table_header(); |
80
|
|
|
bd_render_restrict_settings( 'pages', 'pages' ); |
81
|
|
|
bd_render_delete_settings( 'pages' ); |
82
|
|
|
bd_render_limit_settings( 'pages' ); |
83
|
|
|
bd_render_cron_settings( 'pages','http://bulkwp.com/addons/scheduler-for-deleting-pages-by-status/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-sp' ); |
84
|
|
|
?> |
85
|
|
|
</table> |
86
|
|
|
</fieldset> |
87
|
|
|
<?php |
88
|
|
|
bd_render_submit_button( 'delete_pages_by_status' ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Request handler for deleting pages by status. |
93
|
|
|
* |
94
|
|
|
* @since 5.0 |
95
|
|
|
*/ |
96
|
|
|
public static function do_delete_pages_by_status() { |
97
|
|
|
$delete_options = array(); |
98
|
|
|
$delete_options['restrict'] = array_get_bool( $_POST, 'smbd_pages_restrict', false ); |
99
|
|
|
$delete_options['limit_to'] = absint( array_get( $_POST, 'smbd_pages_limit_to', 0 ) ); |
100
|
|
|
$delete_options['force_delete'] = array_get_bool( $_POST, 'smbd_pages_force_delete', false ); |
101
|
|
|
|
102
|
|
|
$delete_options['date_op'] = array_get( $_POST, 'smbd_pages_op' ); |
103
|
|
|
$delete_options['days'] = absint( array_get( $_POST, 'smbd_pages_days' ) ); |
104
|
|
|
|
105
|
|
|
$delete_options['publish'] = array_get( $_POST, 'smbd_published_pages' ); |
106
|
|
|
$delete_options['drafts'] = array_get( $_POST, 'smbd_draft_pages' ); |
107
|
|
|
$delete_options['pending'] = array_get( $_POST, 'smbd_pending_pages' ); |
108
|
|
|
$delete_options['future'] = array_get( $_POST, 'smbd_future_pages' ); |
109
|
|
|
$delete_options['private'] = array_get( $_POST, 'smbd_private_pages' ); |
110
|
|
|
|
111
|
|
|
if ( 'true' == array_get( $_POST, 'smbd_pages_cron', 'false' ) ) { |
112
|
|
|
$freq = $_POST['smbd_pages_cron_freq']; |
113
|
|
|
$time = strtotime( $_POST['smbd_pages_cron_start'] ) - ( get_option( 'gmt_offset' ) * 60 * 60 ); |
114
|
|
|
|
115
|
|
|
if ( $freq == -1 ) { |
116
|
|
|
wp_schedule_single_event( $time, Bulk_Delete::CRON_HOOK_PAGES_STATUS, array( $delete_options ) ); |
117
|
|
|
} else { |
118
|
|
|
wp_schedule_event( $time, $freq , Bulk_Delete::CRON_HOOK_PAGES_STATUS, array( $delete_options ) ); |
119
|
|
|
} |
120
|
|
|
$msg = __( 'The selected pages are scheduled for deletion.', 'bulk-delete' ) . ' ' . |
121
|
|
|
sprintf( __( 'See the full list of <a href = "%s">scheduled tasks</a>' , 'bulk-delete' ), get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=' . Bulk_Delete::CRON_PAGE_SLUG ); |
122
|
|
|
} else { |
123
|
|
|
$deleted_count = self::delete_pages_by_status( $delete_options ); |
124
|
|
|
$msg = sprintf( _n( 'Deleted %d page', 'Deleted %d pages' , $deleted_count, 'bulk-delete' ), $deleted_count ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
add_settings_error( |
128
|
|
|
Bulk_Delete::PAGES_PAGE_SLUG, |
129
|
|
|
'deleted-cron', |
130
|
|
|
$msg, |
131
|
|
|
'updated' |
132
|
|
|
); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Bulk Delete pages. |
137
|
|
|
* |
138
|
|
|
* @since 5.0 |
139
|
|
|
* |
140
|
|
|
* @param array $delete_options |
141
|
|
|
* |
142
|
|
|
* @return int |
143
|
|
|
*/ |
144
|
|
|
public static function delete_pages_by_status( $delete_options ) { |
145
|
|
|
global $wp_query; |
146
|
|
|
|
147
|
|
|
// Backward compatibility code. Will be removed in Bulk Delete v6.0 |
148
|
|
|
if ( array_key_exists( 'page_op', $delete_options ) ) { |
149
|
|
|
$delete_options['date_op'] = $delete_options['page_op']; |
150
|
|
|
$delete_options['days'] = $delete_options['page_days']; |
151
|
|
|
} |
152
|
|
|
$delete_options = apply_filters( 'bd_delete_options', $delete_options ); |
153
|
|
|
|
154
|
|
|
$post_status = array(); |
155
|
|
|
|
156
|
|
|
// published pages |
157
|
|
|
if ( 'published_pages' == $delete_options['publish'] ) { |
158
|
|
|
$post_status[] = 'publish'; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
// Drafts |
162
|
|
|
if ( 'draft_pages' == $delete_options['drafts'] ) { |
163
|
|
|
$post_status[] = 'draft'; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
// Pending pages |
167
|
|
|
if ( 'pending_pages' == $delete_options['pending'] ) { |
168
|
|
|
$post_status[] = 'pending'; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
// Future pages |
172
|
|
|
if ( 'future_pages' == $delete_options['future'] ) { |
173
|
|
|
$post_status[] = 'future'; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
// Private pages |
177
|
|
|
if ( 'private_pages' == $delete_options['private'] ) { |
178
|
|
|
$post_status[] = 'private'; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
$options = array( |
182
|
|
|
'post_type' => 'page', |
183
|
|
|
'post_status' => $post_status, |
184
|
|
|
); |
185
|
|
|
|
186
|
|
|
$options = bd_build_query_options( $delete_options, $options ); |
187
|
|
|
$pages = $wp_query->query( $options ); |
188
|
|
|
foreach ( $pages as $page ) { |
189
|
|
|
wp_delete_post( $page->ID, $delete_options['force_delete'] ); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
return count( $pages ); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Filter JS Array and add validation hooks. |
197
|
|
|
* |
198
|
|
|
* @since 5.4 |
199
|
|
|
* @static |
200
|
|
|
* |
201
|
|
|
* @param array $js_array JavaScript Array |
202
|
|
|
* |
203
|
|
|
* @return array Modified JavaScript Array |
204
|
|
|
*/ |
205
|
|
|
public static function filter_js_array( $js_array ) { |
206
|
|
|
$js_array['dt_iterators'][] = '_pages'; |
207
|
|
|
|
208
|
|
|
return $js_array; |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
add_action( 'bd_delete_pages_by_status', array( 'Bulk_Delete_Pages', 'do_delete_pages_by_status' ) ); |
213
|
|
|
add_filter( 'bd_javascript_array', array( 'Bulk_Delete_Pages', 'filter_js_array' ) ); |
214
|
|
|
?> |
215
|
|
|
|