Passed
Push — analysis-8AOO2l ( 192129 )
by Sudar
30:45 queued 15:47
created

DeletePagesByStatusModule::append_to_js_array()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 10
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
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
	protected function initialize() {
16
		$this->item_type     = 'pages';
17
		$this->field_slug    = 'page_status';
18
		$this->meta_box_slug = 'bd_pages_by_status';
19
		$this->action        = 'delete_pages_by_status';
20
		$this->cron_hook     = 'do-bulk-delete-pages-by-status';
21
		$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
		$this->messages      = array(
23
			'box_label'  => __( 'By Page Status', 'bulk-delete' ),
24
			'scheduled'  => __( 'The selected pages are scheduled for deletion', 'bulk-delete' ),
25
			'cron_label' => __( 'Delete Pages By status', 'bulk-delete' ),
26
		);
27
	}
28
29
	public function render() {
30
		?>
31
		<!-- Pages start-->
32
		<h4><?php _e( 'Select the post statuses from which you want to delete pages', 'bulk-delete' ); ?></h4>
33
34
		<fieldset class="options">
35
			<table class="optiontable">
36
				<?php $this->render_post_status( 'page' ); ?>
37
			</table>
38
39
			<table class="optiontable">
40
				<?php
41
				$this->render_filtering_table_header();
42
				$this->render_restrict_settings();
43
				$this->render_delete_settings();
44
				$this->render_limit_settings();
45
				$this->render_cron_settings();
46
				?>
47
			</table>
48
		</fieldset>
49
50
		<?php
51
		$this->render_submit_button();
52
	}
53
54
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
55
	protected function append_to_js_array( $js_array ) {
56
		$js_array['error_msg'][ $this->action ]      = 'selectPagePostStatus';
57
		$js_array['pre_action_msg'][ $this->action ] = 'pagePostStatusWarning';
58
59
		$js_array['msg']['selectPagePostStatus']  = __( 'Please select at least one post status from which pages should be deleted', 'bulk-delete' );
60
		$js_array['msg']['pagePostStatusWarning'] = __( 'Are you sure you want to delete all the pages from the selected post status?', 'bulk-delete' );
61
62
		return $js_array;
63
	}
64
65
	protected function convert_user_input_to_options( $request, $options ) {
66
		$options['post_status'] = array_map( 'sanitize_text_field', bd_array_get( $request, 'smbd_page_status', array() ) );
67
68
		return $options;
69
	}
70
71
	protected function build_query( $options ) {
72
		if ( empty( $options['post_status'] ) ) {
73
			return array();
74
		}
75
76
		$query = array(
77
			'post_type'   => 'page',
78
			'post_status' => $options['post_status'],
79
		);
80
81
		return $query;
82
	}
83
84
	protected function get_success_message( $items_deleted ) {
85
		/* translators: 1 Number of pages deleted */
86
		return _n( 'Deleted %d page from the selected post status', 'Deleted %d pages from the selected post status', $items_deleted, 'bulk-delete' );
87
	}
88
}
89