Completed
Push — 221-show-built-in-taxonomies ( d543fc...754779 )
by Sudar
10:38 queued 07:17
created

DeletePagesByStatusModule::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 61
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 25
nc 1
nop 0
dl 0
loc 61
ccs 0
cts 15
cp 0
crap 2
rs 9.5147
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 6
	protected function initialize() {
16 6
		$this->item_type     = 'pages';
17 6
		$this->field_slug    = 'pages';
18 6
		$this->meta_box_slug = 'bd_pages_by_status';
19 6
		$this->action        = 'delete_pages_by_status';
20 6
		$this->cron_hook     = 'do-bulk-delete-pages-by-status';
21 6
		$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 6
		$this->messages      = array(
23 6
			'box_label'  => __( 'By Page Status', 'bulk-delete' ),
24 6
			'scheduled'  => __( 'The selected pages are scheduled for deletion', 'bulk-delete' ),
25 6
			'cron_label' => __( 'Delete Pages By status', 'bulk-delete' ),
26
		);
27 6
	}
28
29
	public function render() {
30
		$pages_count  = wp_count_posts( 'page' );
31
		$pages        = $pages_count->publish;
32
		$page_drafts  = $pages_count->draft;
33
		$page_future  = $pages_count->future;
34
		$page_pending = $pages_count->pending;
35
		$page_private = $pages_count->private;
36
		?>
37
		<!-- Pages start-->
38
		<h4><?php _e( 'Select the status from which you want to delete pages', 'bulk-delete' ); ?></h4>
39
40
		<fieldset class="options">
41
			<table class="optiontable">
42
				<tr>
43
					<td>
44
						<input name="smbd_published_pages" value="published_pages" type="checkbox">
45
						<label for="smbd_published_pages"><?php _e( 'All Published Pages', 'bulk-delete' ); ?> (<?php echo $pages . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label>
46
					</td>
47
				</tr>
48
49
				<tr>
50
					<td>
51
						<input name="smbd_draft_pages" value="draft_pages" type="checkbox">
52
						<label for="smbd_draft_pages"><?php _e( 'All Draft Pages', 'bulk-delete' ); ?> (<?php echo $page_drafts . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label>
53
					</td>
54
				</tr>
55
56
				<tr>
57
					<td>
58
						<input name="smbd_future_pages" value="scheduled_pages" type="checkbox">
59
						<label for="smbd_future_pages"><?php _e( 'All Scheduled Pages', 'bulk-delete' ); ?> (<?php echo $page_future . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label>
60
					</td>
61
				</tr>
62
63
				<tr>
64
					<td>
65
						<input name="smbd_pending_pages" value="pending_pages" type="checkbox">
66
						<label for="smbd_pending_pages"><?php _e( 'All Pending Pages', 'bulk-delete' ); ?> (<?php echo $page_pending . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label>
67
					</td>
68
				</tr>
69
70
				<tr>
71
					<td>
72
						<input name="smbd_private_pages" value="private_pages" type="checkbox">
73
						<label for="smbd_private_pages"><?php _e( 'All Private Pages', 'bulk-delete' ); ?> (<?php echo $page_private . ' '; _e( 'Pages', 'bulk-delete' ); ?>)</label>
74
					</td>
75
				</tr>
76
			</table>
77
78
			<table class="optiontable">
79
				<?php
80
				$this->render_filtering_table_header();
81
				$this->render_restrict_settings();
82
				$this->render_delete_settings();
83
				$this->render_limit_settings();
84
				$this->render_cron_settings();
85
				?>
86
			</table>
87
		</fieldset>
88
		<?php
89
		$this->render_submit_button();
90
	}
91
92
	protected function convert_user_input_to_options( $request, $options ) {
93
		$options['publish'] = bd_array_get( $request, 'smbd_published_pages' );
94
		$options['drafts']  = bd_array_get( $request, 'smbd_draft_pages' );
95
		$options['pending'] = bd_array_get( $request, 'smbd_pending_pages' );
96
		$options['future']  = bd_array_get( $request, 'smbd_future_pages' );
97
		$options['private'] = bd_array_get( $request, 'smbd_private_pages' );
98
99
		return $options;
100
	}
101
102 6
	protected function build_query( $options ) {
103 6
		$post_status = array();
104
105
		// published pages
106 6
		if ( 'published_pages' == $options['publish'] ) {
107 5
			$post_status[] = 'publish';
108
		}
109
110
		// Drafts
111 6
		if ( 'draft_pages' == $options['drafts'] ) {
112 5
			$post_status[] = 'draft';
113
		}
114
115
		// Pending pages
116 6
		if ( 'pending_pages' == $options['pending'] ) {
117
			$post_status[] = 'pending';
118
		}
119
120
		// Future pages
121 6
		if ( 'future_pages' == $options['future'] ) {
122
			$post_status[] = 'future';
123
		}
124
125
		// Private pages
126 6
		if ( 'private_pages' == $options['private'] ) {
127 1
			$post_status[] = 'private';
128
		}
129
130
		$query = array(
131 6
			'post_type'   => 'page',
132 6
			'post_status' => $post_status,
133
		);
134
135 6
		return $query;
136
	}
137
138
	protected function get_success_message( $items_deleted ) {
139
		/* translators: 1 Number of pages deleted */
140
		return _n( 'Deleted %d page with the selected page status', 'Deleted %d pages with the selected page status', $items_deleted, 'bulk-delete' );
141
	}
142
}
143