Completed
Push — 677-feature/add-wp-cli-support ( a6bca4...1a74d2 )
by Sudar
03:32
created

DeletePostsByStatusModule::prepare_cli_input()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 1
b 0
f 0
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 Status Module.
11
 *
12
 * @since 6.0.0
13
 */
14
class DeletePostsByStatusModule extends PostsModule {
15 19
	protected function initialize() {
16 19
		$this->item_type     = 'posts';
17 19
		$this->field_slug    = 'post_status';
18 19
		$this->meta_box_slug = 'bd_posts_by_status';
19 19
		$this->action        = 'delete_posts_by_status';
20 19
		$this->cron_hook     = 'do-bulk-delete-post-status';
21 19
		$this->scheduler_url = 'https://bulkwp.com/addons/scheduler-for-deleting-posts-by-status/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-sps';
22 19
		$this->messages      = array(
23 19
			'box_label'         => __( 'By Post Status', 'bulk-delete' ),
24 19
			'scheduled'         => __( 'The selected posts are scheduled for deletion', 'bulk-delete' ),
25 19
			'cron_label'        => __( 'Delete Post By Status', 'bulk-delete' ),
26 19
			'validation_error'  => __( 'Please select at least one post status from which posts should be deleted', 'bulk-delete' ),
27 19
			'confirm_deletion'  => __( 'Are you sure you want to delete all the posts from the selected post status?', 'bulk-delete' ),
28 19
			'confirm_scheduled' => __( 'Are you sure you want to schedule deletion of all the posts from the selected post status?', 'bulk-delete' ),
29
			/* translators: 1 Number of posts deleted */
30 19
			'deleted_one'       => __( 'Deleted %d post from the selected post status', 'bulk-delete' ),
31
			/* translators: 1 Number of posts deleted */
32 19
			'deleted_multiple'  => __( 'Deleted %d posts from the selected post status', 'bulk-delete' ),
33
		);
34
	}
35
36
	public function render() {
37
		?>
38
		<h4><?php _e( 'Select the post statuses from which you want to delete posts', 'bulk-delete' ); ?></h4>
39
40
		<fieldset class="options">
41
42
			<table class="optiontable">
43
				<?php $this->render_post_status(); ?>
44
			</table>
45
46
			<table class="optiontable">
47
				<?php
48
				$this->render_filtering_table_header();
49
				$this->render_restrict_settings();
50
				$this->render_exclude_sticky_settings();
51
				$this->render_delete_settings();
52
				$this->render_limit_settings();
53
				$this->render_cron_settings();
54
				?>
55
			</table>
56
57
		</fieldset>
58
59
		<?php
60
		$this->render_submit_button();
61
	}
62
63
	protected function convert_user_input_to_options( $request, $options ) {
64
		$options['post_status'] = array_map( 'sanitize_text_field', bd_array_get( $request, 'smbd_' . $this->field_slug, array() ) );
65
66
		return $options;
67
	}
68
69 19
	protected function build_query( $options ) {
70 19
		if ( empty( $options['post_status'] ) ) {
71
			return array();
72
		}
73
74
		$query = array(
75 19
			'post_status' => $options['post_status'],
76
		);
77
78 19
		return $query;
79
	}
80
81
	protected function get_non_standard_input_key_map() {
82
		$prefix = $this->get_ui_input_prefix();
83
84
		$prefix_without_underscore_at_end = substr( $prefix, 0, -1 );
85
86
		return [
87
			$prefix_without_underscore_at_end => $prefix . 'post_status',
88
		];
89
	}
90
91
	protected function prepare_cli_input( $input ) {
92
		// Handle multiple post status.
93
		$input['post_status'] = explode( ',', $input['post_status'] );
94
95
		return parent::prepare_cli_input( $input );
96
	}
97
}
98