Passed
Push — 595-fix/show-a-different-confi... ( 2078cd...41ad7f )
by
unknown
54:41
created

DeletePostsByStatusModule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 58.33%

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 65
ccs 21
cts 36
cp 0.5833
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 18 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 19
			'confirm_scheduled' => __( 'Are you sure you want to schedule deletion for 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 19
	}
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