Passed
Push — dev/6.0.1 ( 5b55be )
by Sudar
04:46
created

DeletePostsByStatusModule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 64
ccs 20
cts 35
cp 0.5714
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A build_query() 0 10 2
A initialize() 0 17 1
A render() 0 25 1
A convert_user_input_to_options() 0 4 1
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 = 'http://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
			/* translators: 1 Number of posts deleted */
29 19
			'deleted_one'      => __( 'Deleted %d post from the selected post status', 'bulk-delete' ),
30
			/* translators: 1 Number of posts deleted */
31 19
			'deleted_multiple' => __( 'Deleted %d posts from the selected post status', 'bulk-delete' ),
32
		);
33 19
	}
34
35
	public function render() {
36
		?>
37
		<h4><?php _e( 'Select the post statuses from which you want to delete posts', 'bulk-delete' ); ?></h4>
38
39
		<fieldset class="options">
40
41
			<table class="optiontable">
42
				<?php $this->render_post_status(); ?>
43
			</table>
44
45
			<table class="optiontable">
46
				<?php
47
				$this->render_filtering_table_header();
48
				$this->render_restrict_settings();
49
				$this->render_exclude_sticky_settings();
50
				$this->render_delete_settings();
51
				$this->render_limit_settings();
52
				$this->render_cron_settings();
53
				?>
54
			</table>
55
56
		</fieldset>
57
58
		<?php
59
		$this->render_submit_button();
60
	}
61
62
	protected function convert_user_input_to_options( $request, $options ) {
63
		$options['post_status'] = array_map( 'sanitize_text_field', bd_array_get( $request, 'smbd_' . $this->field_slug, array() ) );
64
65
		return $options;
66
	}
67
68 19
	protected function build_query( $options ) {
69 19
		if ( empty( $options['post_status'] ) ) {
70
			return array();
71
		}
72
73
		$query = array(
74 19
			'post_status' => $options['post_status'],
75
		);
76
77 19
		return $query;
78
	}
79
}
80