Passed
Push — analysis-XZNdyg ( 545f48 )
by Sudar
70:39 queued 51s
created

DeleteCommentsByIPModule::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 16
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 27
rs 9.7333
1
<?php
2
3
namespace BulkWP\BulkDelete\Core\Comments\Modules;
4
5
use BulkWP\BulkDelete\Core\Comments\CommentsModule;
6
7
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
8
9
/**
10
 * Delete Comments by Author Module.
11
 *
12
 * @since 6.1.0
13
 */
14
class DeleteCommentsByIPModule extends CommentsModule {
15
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
16
	protected function initialize() {
17
		$this->item_type     = 'comments';
18
		$this->field_slug    = 'comments_by_ip';
19
		$this->meta_box_slug = 'bd_comments_by_ip';
20
		$this->action        = 'delete_comments_by_ip';
21
		$this->cron_hook     = 'do-bulk-delete-comments-by-ip';
22
		$this->scheduler_url = 'https://bulkwp.com/addons/scheduler-for-deleting-comments/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-sp';
23
		$this->messages      = array(
24
			'box_label'         => __( 'By IP Address', 'bulk-delete' ),
25
			'scheduled'         => __( 'The selected comments are scheduled for deletion', 'bulk-delete' ),
26
			'cron_label'        => __( 'Delete Comments By IP Address', 'bulk-delete' ),
27
			'confirm_deletion'  => __( 'Are you sure you want to delete all the comments from the selected condition?', 'bulk-delete' ),
28
			'confirm_scheduled' => __( 'Are you sure you want to schedule deletion for all the comments from the selected condition?', 'bulk-delete' ),
29
			'validation_error'  => __( 'Please enter valid IP Address based on which comments should be deleted', 'bulk-delete' ),
30
			/* translators: 1 Number of comments deleted */
31
			'deleted_one'       => __( 'Deleted %d comment with selected condition', 'bulk-delete' ),
32
			/* translators: 1 Number of comments deleted */
33
			'deleted_multiple'  => __( 'Deleted %d comments with selected condition', 'bulk-delete' ),
34
		);
35
	}
36
37
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
38
	public function render() {
39
		?>
40
		<!-- Pages start-->
41
		<h4><?php _e( 'Enter IP Address based on which you want to delete comments', 'bulk-delete' ); ?></h4>
42
43
		<fieldset class="options">
44
			<table class="optiontable">
45
				<tr>
46
					<td>
47
						<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_address" type="text" placeholder="<?php _e( 'IP Address', 'bulk-delete' ); ?>" class="validate">
48
					</td>
49
				</tr>				
50
			</table>
51
52
			<table class="optiontable">
53
				<?php
54
				$this->render_filtering_table_header();
55
				$this->render_restrict_settings();
56
				$this->render_delete_settings();
57
				$this->render_limit_settings();
58
				$this->render_cron_settings();
59
				?>
60
			</table>
61
		</fieldset>
62
63
		<?php
64
		$this->render_submit_button();
65
	}
66
67
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
68
	protected function append_to_js_array( $js_array ) {
69
		$js_array['validators'][ $this->action ] = 'validateTextbox';
70
71
		return $js_array;
72
	}
73
74
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
75
	protected function convert_user_input_to_options( $request, $options ) {
76
		$options['ip_address'] = sanitize_text_field( bd_array_get( $request, 'smbd_' . $this->field_slug . '_address', '' ) );
77
78
		return $options;
79
	}
80
81
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
82
	protected function build_query( $options ) {
83
		// TODO: IP address is not supported in WP_Comment_Query
84
		$query = array();
85
		if ( ! empty( $options['ip_address'] ) ) {
86
			$query['ip_address'] = array();
87
		}
88
89
		$date_query = $this->get_date_query( $options );
90
		if ( ! empty( $date_query ) ) {
91
			$query['date_query'] = $date_query;
92
		}
93
94
		return $query;
95
	}
96
}
97