Completed
Push — 272-feature/delete-user-post-m... ( f8ddd2...118da4 )
by Sudar
09:39 queued 05:57
created

DeletePagesByStatusModule::build_query()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
crap 2.0185
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace BulkWP\BulkDelete\Core\Pages\Modules;
4
5
use BulkWP\BulkDelete\Core\Pages\PagesModule;
6
7 1
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
8
9
/**
10
 * Delete Pages by Status Module.
11
 *
12
 * @since 6.0.0
13
 */
14
class DeletePagesByStatusModule extends PagesModule {
15 12
	protected function initialize() {
16 12
		$this->item_type     = 'pages';
17 12
		$this->field_slug    = 'pages';
18 12
		$this->meta_box_slug = 'bd_pages_by_status';
19 12
		$this->action        = 'delete_pages_by_status';
20 12
		$this->cron_hook     = 'do-bulk-delete-pages-by-status';
21 12
		$this->scheduler_url = 'http://bulkwp.com/addons/scheduler-for-deleting-pages-by-status/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-sp';
22 12
		$this->messages      = array(
23 12
			'box_label'  => __( 'By Page Status', 'bulk-delete' ),
24 12
			'scheduled'  => __( 'The selected pages are scheduled for deletion', 'bulk-delete' ),
25 12
			'cron_label' => __( 'Delete Pages By status', 'bulk-delete' ),
26
		);
27 12
	}
28
29
	public function render() {
30
		$post_statuses  = $this->get_post_statuses();
31
		$pages_count    = wp_count_posts( 'page' );
32
		?>
33
		<!-- Pages start-->
34
		<h4><?php _e( 'Select the status from which you want to delete pages', 'bulk-delete' ); ?></h4>
35
36
		<fieldset class="options">
37
			<table class="optiontable">
38
				<?php foreach ( $post_statuses as $post_status ) : ?>
39
				<tr>
40
					<td>
41
						<input name="smbd_page_status[]" id="smbd_<?php echo esc_attr( $post_status->name ); ?>"
42
							value="<?php echo esc_attr( $post_status->name ); ?>" type="checkbox">
43
44
						<label for="smbd_<?php echo esc_attr( $post_status->name ); ?>">
45
							<?php echo esc_html( $post_status->label ), ' '; ?>
46
							<?php if ( property_exists( $pages_count, $post_status->name ) ) : ?>
47
								(<?php echo absint( $pages_count->{ $post_status->name } ) . ' ', __( 'Posts', 'bulk-delete' ); ?>)
48
							<?php endif; ?>
49
						</label>
50
					</td>
51
				</tr>
52
			<?php endforeach; ?>
53
			</table>
54
55
			<table class="optiontable">
56
				<?php
57
				$this->render_filtering_table_header();
58
				$this->render_restrict_settings();
59
				$this->render_delete_settings();
60
				$this->render_limit_settings();
61
				$this->render_cron_settings();
62
				?>
63
			</table>
64
		</fieldset>
65
		<?php
66
		$this->render_submit_button();
67
	}
68
69
	protected function convert_user_input_to_options( $request, $options ) {
70
		$options['post_status'] = array_map( 'sanitize_text_field', bd_array_get( $request, 'smbd_page_status', array() ) );
0 ignored issues
show
Bug introduced by
array() of type array is incompatible with the type string expected by parameter $default of bd_array_get(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

70
		$options['post_status'] = array_map( 'sanitize_text_field', bd_array_get( $request, 'smbd_page_status', /** @scrutinizer ignore-type */ array() ) );
Loading history...
71
72
		return $options;
73
	}
74
75 12
	protected function build_query( $options ) {
76 12
		if ( empty( $options['post_status'] ) ) {
77
			return array();
78
		}
79
80
		$query = array(
81 12
			'post_type'   => 'page',
82 12
			'post_status' => $options['post_status'],
83
		);
84
85 12
		return $query;
86
	}
87
88
	protected function get_success_message( $items_deleted ) {
89
		/* translators: 1 Number of pages deleted */
90
		return _n( 'Deleted %d page with the selected page status', 'Deleted %d pages with the selected page status', $items_deleted, 'bulk-delete' );
91
	}
92
}
93