Completed
Push — 52-feature/delete-posts-by-no-... ( 78ba55...c53c0c )
by
unknown
14:02
created

DeletePostsByCommentsModule::build_query()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BulkWP\BulkDelete\Core\Posts\Modules;
4
5
use BulkWP\BulkDelete\Core\Posts\PostsModule;
6
7
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
8
9
/**
10
 * Delete Posts by Tag Module.
11
 *
12
 * @since 6.0.0
13
 */
14
class DeletePostsByCommentsModule extends PostsModule {
15
	/**
16
	 * Base parameters setup.
17
	 */
18
	protected function initialize() {
19
		$this->item_type     = 'posts';
20
		$this->field_slug    = 'comments';
21
		$this->meta_box_slug = 'bd_by_comments';
22
		$this->action        = 'delete_posts_by_comments';
23
		$this->cron_hook     = 'do-bulk-delete-comments';
24
		$this->scheduler_url = 'http://bulkwp.com/addons/scheduler-for-deleting-posts-by-comments/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-st';
25
		$this->messages      = array(
26
			'box_label'  => __( 'By Post Comments', 'bulk-delete' ),
27
			'scheduled'  => __( 'The selected posts are scheduled for deletion', 'bulk-delete' ),
28
			'cron_label' => __( 'Delete Post By Comments', 'bulk-delete' ),
29
		);
30
	}
31
32
	/**
33
	 * Render Delete posts by tag box.
34
	 */
35
	public function render() {
36
		?>
37
		<h4><?php _e( 'Select the no of comments that posts should have', 'bulk-delete' ); ?></h4>
38
39
		<!-- Tags start-->
40
		<fieldset class="options">
41
			<table class="optiontable">
42
				<tr>
43
					<td scope="row" colspan="2">
44
						<?php $this->render_tags_dropdown(); ?>
45
					</td>
46
				</tr>
47
			</table>
48
49
			<table class="optiontable">
50
				<?php
51
				$this->render_filtering_table_header();
52
				$this->render_restrict_settings();
53
				$this->render_delete_settings();
54
				$this->render_private_post_settings();
55
				$this->render_limit_settings();
56
				$this->render_cron_settings();
57
				?>
58
			</table>
59
		</fieldset>
60
<?php
61
		$this->render_submit_button();
62
	}
63
64
	/**
65
	 * Process delete posts user inputs by tag.
66
	 *
67
	 * @param array $request Request array.
68
	 * @param array $options Options for deleting posts.
69
	 *
70
	 * @return array $options  Inputs from user for posts that were need to delete
71
	 */
72
	protected function convert_user_input_to_options( $request, $options ) {
73
		$options['selected_tags'] = bd_array_get( $request, 'smbd_tags', array() );
74
		$options['private']       = bd_array_get( $request, 'smbd_tags_private', false );
75
76
		return $options;
77
	}
78
79
	protected function build_query( $options ) {
80
		$query = array();
81
82
		if ( in_array( 'all', $options['selected_tags'], true ) ) {
83
			$query['tag__not__in'] = array( 0 );
84
		} else {
85
			$query['tag__in'] = $options['selected_tags'];
86
		}
87
88
		return $query;
89
	}
90
91
	/**
92
	 * Response message for deleting posts.
93
	 *
94
	 * @param int $items_deleted count of items deleted.
95
	 *
96
	 * @return string Response message
97
	 */
98
	protected function get_success_message( $items_deleted ) {
99
		/* translators: 1 Number of posts deleted */
100
		return _n( 'Deleted %d post with the selected post tag', 'Deleted %d posts with the selected post tag', $items_deleted, 'bulk-delete' );
101
	}
102
}
103