Passed
Push — 178-feature/delete-terms--by-p... ( c87316 )
by Rajan
09:43
created

DeleteTermsByPostfixAndPrefixModule::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 0
dl 0
loc 23
ccs 0
cts 15
cp 0
crap 2
rs 9.0856
c 0
b 0
f 0
1
<?php
2
3
namespace BulkWP\BulkDelete\Core\Terms\Modules;
4
5
use BulkWP\BulkDelete\Core\Terms\TermsModule;
6
7
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
8
9
/**
10
 * Delete Terms by Postfix and Prefix.
11
 *
12
 * @since 6.0.0
13
 */
14
class DeleteTermsByPostfixAndPrefixModule extends TermsModule {
15
	protected function initialize() {
16
		$this->item_type     = 'terms';
17
		$this->field_slug    = 'postfix_prefix';
18
		$this->meta_box_slug = 'bd_by_postfix_prefix';
19
		$this->action        = 'delete_terms_by_postfix_prefix';
20
		$this->cron_hook     = 'do-bulk-delete-term-postfix-prefix';
21
		$this->scheduler_url = 'http://bulkwp.com/addons/scheduler-for-deleting-posts-by-category/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-sc';
22
		$this->messages      = array(
23
			'box_label'  => __( 'By Terms by Postfix Prefix', 'bulk-delete' ),
24
			'scheduled'  => __( 'The selected posts are scheduled for deletion', 'bulk-delete' ),
25
			'cron_label' => __( 'Delete Terms By Postfix Prefix', 'bulk-delete' ),
26
		);
27
	}
28
29
	/**
30
	 * Render Delete terms by postfix and prefix box.
31
	 */
32
	public function render() {
33
		?>
34
		<!-- Category Start-->
35
		<h4><?php _e( 'Select the taxonomy from which you want to delete', 'bulk-delete' ); ?></h4>
36
		<fieldset class="options">
37
			<table class="optiontable">
38
				<?php $this->render_taxonomy_dropdown(); ?>
39
			</table>
40
41
			<table class="optiontable">
42
				<?php
43
				$this->render_filtering_table_header();
44
				$this->render_restrict_settings();
45
				$this->render_delete_settings();
46
				$this->render_private_post_settings();
47
				$this->render_limit_settings();
48
				$this->render_cron_settings();
49
				?>
50
			</table>
51
52
		</fieldset>
53
		<?php
54
		$this->render_submit_button();
55
	}
56
57
	/**
58
	 * Process delete posts user inputs by category.
59
	 *
60
	 * @param array $request Request array.
61
	 * @param array $options Options for deleting posts.
62
	 *
63
	 * @return array $options  Inputs from user for posts that were need to delete
64
	 */
65
	protected function convert_user_input_to_options( $request, $options ) {
66
		$options['post_type']     = bd_array_get( $request, 'smbd_' . $this->field_slug . '_post_type', 'post' );
67
		$options['selected_cats'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_category' );
68
		$options['private']       = bd_array_get_bool( $request, 'smbd_' . $this->field_slug . '_private', false );
69
70
		return $options;
71
	}
72
73
	/**
74
	 * Build query from delete options.
75
	 *
76
	 * @param array $options Delete options.
77
	 *
78
	 * @return array Query.
79
	 */
80
	protected function build_query( $options ) {
81
		$query = array();
82
83
		if ( in_array( 'all', $options['selected_cats'], true ) ) {
84
			$query['category__not__in'] = array( 0 );
85
		} else {
86
			$query['category__in'] = $options['selected_cats'];
87
		}
88
89
		return $query;
90
	}
91
92
	/**
93
	 * Response message for deleting posts.
94
	 *
95
	 * @param int $items_deleted Total number of posts deleted.
96
	 *
97
	 * @return string Response message
98
	 */
99
	protected function get_success_message( $items_deleted ) {
100
		/* translators: 1 Number of posts deleted */
101
		return _n( 'Deleted %d post with the selected post category', 'Deleted %d posts with the selected post category', $items_deleted, 'bulk-delete' );
102
	}
103
}
104