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 Revision Module. |
11
|
|
|
* |
12
|
|
|
* @since 6.0.0 |
13
|
|
|
*/ |
14
|
|
|
class DeletePostsByRevisionModule extends PostsModule { |
15
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
16
|
5 |
|
protected function initialize() { |
17
|
5 |
|
$this->item_type = 'posts'; |
18
|
5 |
|
$this->field_slug = 'revisions'; |
19
|
5 |
|
$this->meta_box_slug = 'bd_posts_by_revision'; |
20
|
5 |
|
$this->action = 'delete_posts_by_revision'; |
21
|
5 |
|
$this->messages = array( |
22
|
5 |
|
'box_label' => __( 'By Post Revisions', 'bulk-delete' ), |
23
|
5 |
|
'confirm_deletion' => __( 'Are you sure you want to delete all the revisions based on the selected condition?', 'bulk-delete' ), |
24
|
5 |
|
'validation_error' => __( 'Please select the checkbox', 'bulk-delete' ), |
25
|
|
|
/* translators: 1 Number of posts deleted */ |
26
|
5 |
|
'deleted_one' => __( 'Deleted %d post revision', 'bulk-delete' ), |
27
|
|
|
/* translators: 1 Number of posts deleted */ |
28
|
5 |
|
'deleted_multiple' => __( 'Deleted %d post revisions', 'bulk-delete' ), |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
33
|
|
|
public function render() { |
34
|
|
|
global $wpdb; |
35
|
|
|
$revisions = $wpdb->get_var( "select count(*) from $wpdb->posts where post_type = 'revision'" ); |
36
|
|
|
?> |
37
|
|
|
<!-- Post Revisions start--> |
38
|
|
|
<h4><?php _e( 'Select the posts which you want to delete', 'bulk-delete' ); ?></h4> |
39
|
|
|
|
40
|
|
|
<fieldset class="options"> |
41
|
|
|
<table class="optiontable"> |
42
|
|
|
<tr> |
43
|
|
|
<td> |
44
|
|
|
<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>" value="revisions" type="checkbox" class="validate"> |
45
|
|
|
<label for="smbd_<?php echo esc_attr( $this->field_slug ); ?>"><?php _e( 'All Revisions', 'bulk-delete' ); ?> (<?php echo $revisions . ' '; _e( 'Revisions', 'bulk-delete' ); ?>)</label> |
46
|
|
|
</td> |
47
|
|
|
</tr> |
48
|
|
|
</table> |
49
|
|
|
<table class="optiontable"> |
50
|
|
|
<?php |
51
|
|
|
$this->render_filtering_table_header(); |
52
|
|
|
$this->render_restrict_settings(); |
53
|
|
|
$this->render_limit_settings( 'revisions' ); |
54
|
|
|
?> |
55
|
|
|
</table> |
56
|
|
|
</fieldset> |
57
|
|
|
<?php |
58
|
|
|
$this->render_submit_button(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
62
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
63
|
|
|
$options['revisions'] = bd_array_get( $request, 'smbd_' . $this->field_slug ); |
64
|
|
|
$options['force_delete'] = true; |
65
|
|
|
|
66
|
|
|
return $options; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
70
|
|
|
protected function append_to_js_array( $js_array ) { |
71
|
|
|
$js_array['validators'][ $this->action ] = 'validateCheckbox'; |
72
|
|
|
|
73
|
|
|
return $js_array; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
77
|
5 |
|
protected function build_query( $options ) { |
78
|
5 |
|
if ( 'revisions' === $options['revisions'] ) { |
79
|
|
|
return array( |
80
|
5 |
|
'post_type' => 'revision', |
81
|
|
|
'post_status' => 'inherit', |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|