|
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 = 'by_name'; |
|
18
|
|
|
$this->meta_box_slug = 'bd_by_name'; |
|
19
|
|
|
$this->action = 'delete_terms_by_name'; |
|
20
|
|
|
$this->cron_hook = 'do-bulk-delete-term-name'; |
|
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 Name', 'bulk-delete' ), |
|
24
|
|
|
'scheduled' => __( 'The selected posts are scheduled for deletion', 'bulk-delete' ), |
|
25
|
|
|
'cron_label' => __( 'Delete Terms By Name', '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 $this->render_term_options(); ?> |
|
43
|
|
|
</table> |
|
44
|
|
|
|
|
45
|
|
|
<table class="optiontable"> |
|
46
|
|
|
<?php |
|
47
|
|
|
$this->render_have_post_settings(); |
|
48
|
|
|
?> |
|
49
|
|
|
</table> |
|
50
|
|
|
|
|
51
|
|
|
</fieldset> |
|
52
|
|
|
<?php |
|
53
|
|
|
$this->render_submit_button(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function filter_js_array( $js_array ) { |
|
57
|
|
|
$js_array['validators'][ $this->action ] = 'validatePostTypeSelect2'; |
|
58
|
|
|
$js_array['error_msg'][ $this->action ] = 'selectPostType'; |
|
59
|
|
|
$js_array['msg']['selectPostType'] = __( 'Please select at least one post type', 'bulk-delete' ); |
|
60
|
|
|
|
|
61
|
|
|
$js_array['dt_iterators'][] = '_' . $this->field_slug; |
|
62
|
|
|
|
|
63
|
|
|
return $js_array; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Process delete posts user inputs by category. |
|
68
|
|
|
* |
|
69
|
|
|
* @param array $request Request array. |
|
70
|
|
|
* @param array $options Options for deleting posts. |
|
71
|
|
|
* |
|
72
|
|
|
* @return array $options Inputs from user for posts that were need to delete |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
|
75
|
|
|
$options['taxonomy'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_taxonomy' ); |
|
76
|
|
|
$options['term_opt'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_term_opt' ); |
|
77
|
|
|
$options['term_text'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_term_text' ); |
|
78
|
|
|
$options['no_posts'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_no_posts' ); |
|
79
|
|
|
|
|
80
|
|
|
return $options; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Build query from delete options. |
|
85
|
|
|
* |
|
86
|
|
|
* @param array $options Delete options. |
|
87
|
|
|
* |
|
88
|
|
|
* @return array Query. |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function build_query( $options ) { |
|
91
|
|
|
$query = array(); |
|
92
|
|
|
|
|
93
|
|
|
if ( $options['term_opt'] == "equal_to" ) { |
|
|
|
|
|
|
94
|
|
|
$query['name__like'] = $options['term_text']; |
|
95
|
|
|
}else if ( $options['term_opt'] == "not_equal_to" ) { |
|
|
|
|
|
|
96
|
|
|
$query['name__like'] = ''; |
|
97
|
|
|
}else if ( $options['term_opt'] == "starts" ) { |
|
|
|
|
|
|
98
|
|
|
$query['name__like'] = ''; |
|
99
|
|
|
}else if ( $options['term_opt'] == "ends" ) { |
|
|
|
|
|
|
100
|
|
|
$query['name__like'] = ''; |
|
101
|
|
|
}else if ( $options['term_opt'] == "contains" ) { |
|
|
|
|
|
|
102
|
|
|
$query['name__like'] = ''; |
|
103
|
|
|
}else if ( $options['term_opt'] == "non_contains" ) { |
|
|
|
|
|
|
104
|
|
|
$query['name__like'] = ''; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if( isset($options['no_posts']) ){ |
|
108
|
|
|
$query['count'] = ''; |
|
109
|
|
|
} |
|
110
|
|
|
return $query; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Response message for deleting posts. |
|
115
|
|
|
* |
|
116
|
|
|
* @param int $items_deleted Total number of posts deleted. |
|
117
|
|
|
* |
|
118
|
|
|
* @return string Response message |
|
119
|
|
|
*/ |
|
120
|
|
|
protected function get_success_message( $items_deleted ) { |
|
121
|
|
|
/* translators: 1 Number of posts deleted */ |
|
122
|
|
|
return _n( 'Deleted %d post with the selected post category', 'Deleted %d posts with the selected post category', $items_deleted, 'bulk-delete' ); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
PHP provides two ways to mark string literals. Either with single quotes
'literal'or with double quotes"literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\') and the backslash (\\). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is ValueIf your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.