Completed
Push — 50-feature/delete-blogs-in-mul... ( a42973 )
by
unknown
05:00
created

DeleteSitesByNameModule::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9332
1
<?php
2
3
namespace BulkWP\BulkDelete\Core\Sites\Modules;
4
5
use BulkWP\BulkDelete\Core\Sites\SitesModule;
6
7
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
8
9
/**
10
 * Delete Sites by Name.
11
 *
12
 * @since 6.2.0
13
 */
14
class DeleteSitesByNameModule extends SitesModule {
15
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
16
	protected function initialize() {
17
		$this->item_type     = 'sites';
18
		$this->field_slug    = 'sites_by_name';
19
		$this->meta_box_slug = 'bd_delete_sites_by_name';
20
		$this->action        = 'delete_sites_by_name';
21
		$this->messages      = array(
22
			'box_label'        => __( 'Delete Sites by Name', 'bulk-delete' ),
23
			'confirm_deletion' => __( 'Are you sure you want to delete all the sites based on the selected option?', 'bulk-delete' ),
24
			'validation_error' => __( 'Please enter the site name that should be deleted', 'bulk-delete' ),
25
			/* translators: 1 Number of sites deleted */
26
			'deleted_one'      => __( 'Deleted %d site with the selected options', 'bulk-delete' ),
27
			/* translators: 1 Number of sites deleted */
28
			'deleted_multiple' => __( 'Deleted %d sites with the selected options', 'bulk-delete' ),
29
		);
30
	}
31
32
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
33
	public function render() {
34
		?>
35
		<h4><?php _e( 'Enter the site name that you want to delete', 'bulk-delete' ); ?></h4>
36
		<fieldset class="options">
37
			<table class="optiontable">
38
				<tr><?php $this->render_taxonomy_dropdown(); ?></tr>
39
				<h4><?php _e( 'Choose your filtering options', 'bulk-delete' ); ?></h4>
40
				<tr>
41
					<td><?php _e( 'Delete Sites if the name ', 'bulk-delete' ); ?></td>
42
					<td><?php $this->render_string_operators_dropdown( 'stringy', array( '=', 'LIKE', 'STARTS_WITH', 'ENDS_WITH' ) ); ?></td>
43
					<td><input type="text" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_value" placeholder="<?php _e( 'Term Name', 'bulk-delete' ); ?>" class="validate"></td>
44
				</tr>
45
			</table>
46
		</fieldset>
47
48
		<?php
49
		$this->render_submit_button();
50
	}
51
52
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
53
	protected function append_to_js_array( $js_array ) {
54
		$js_array['validators'][ $this->action ] = 'validateTextbox';
55
56
		return $js_array;
57
	}
58
59
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
60
	protected function convert_user_input_to_options( $request, $options ) {
61
		$options['operator'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_operator' );
62
		$options['value']    = sanitize_text_field( bd_array_get( $request, 'smbd_' . $this->field_slug . '_value' ) );
63
64
		return $options;
65
	}
66
67
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
68
	protected function build_query( $options ) {
69
		// Left empty on purpose.
70
	}
71
}
72