1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\Posts\Modules; |
4
|
|
|
|
5
|
|
|
use BulkWP\BulkDelete\Core\Posts\PostsModule; |
6
|
|
|
|
7
|
1 |
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Delete Posts by Sticky Post. |
11
|
|
|
* |
12
|
|
|
* @since 6.0.0 |
13
|
|
|
*/ |
14
|
|
|
class DeletePostsByStickyPostModule extends PostsModule { |
15
|
|
|
/** |
16
|
|
|
* Base parameters setup. |
17
|
|
|
*/ |
18
|
1 |
|
protected function initialize() { |
19
|
1 |
|
$this->item_type = 'posts'; |
20
|
1 |
|
$this->field_slug = 'sticky_post'; |
21
|
1 |
|
$this->meta_box_slug = 'bd_by_sticky_post'; |
22
|
1 |
|
$this->action = 'delete_posts_by_sticky_post'; |
23
|
1 |
|
$this->messages = array( |
24
|
1 |
|
'box_label' => __( 'By Sticky Post', 'bulk-delete' ), |
25
|
|
|
); |
26
|
1 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Render Delete posts by tag box. |
30
|
|
|
*/ |
31
|
|
|
public function render() { |
32
|
|
|
if ( ! $this->are_sticky_post_present() ) : ?> |
33
|
|
|
<h4> |
34
|
|
|
<?php _e( 'There are no sticky post present in this WordPress installation.', 'bulk-delete' ); ?> |
35
|
|
|
</h4> |
36
|
|
|
<?php return; ?> |
37
|
|
|
<?php endif; ?> |
|
|
|
|
38
|
|
|
|
39
|
|
|
<h4><?php _e( 'Select the sticky post from which you want to delete', 'bulk-delete' ); ?></h4> |
40
|
|
|
|
41
|
|
|
<!-- Tags start--> |
42
|
|
|
<fieldset class="options"> |
43
|
|
|
<table class="optiontable"> |
44
|
|
|
<tr> |
45
|
|
|
<td scope="row" colspan="2"> |
46
|
|
|
<?php $this->render_sticky_post_dropdown(); ?> |
47
|
|
|
</td> |
48
|
|
|
</tr> |
49
|
|
|
</table> |
50
|
|
|
|
51
|
|
|
<table class="optiontable"> |
52
|
|
|
<?php |
53
|
|
|
$this->render_filtering_table_header(); |
54
|
|
|
$this->render_sticky_settings(); |
55
|
|
|
$this->render_delete_settings(); |
56
|
|
|
?> |
57
|
|
|
</table> |
58
|
|
|
</fieldset> |
59
|
|
|
<?php |
60
|
|
|
$this->render_submit_button(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Process delete posts user inputs by sticky_post. |
65
|
|
|
* |
66
|
|
|
* @param array $request Request array. |
67
|
|
|
* @param array $options Options for deleting posts. |
68
|
|
|
* |
69
|
|
|
* @return array $options Inputs from user for posts that were need to delete |
70
|
|
|
*/ |
71
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
72
|
|
|
$options['selected_posts'] = bd_array_get( $request, 'smbd_sticky_post' ); |
73
|
|
|
|
74
|
|
|
$options['sticky_option'] = bd_array_get( $request, 'smbd_sticky_post_sticky_option' ); |
75
|
|
|
|
76
|
|
|
return $options; |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
protected function build_query( $options ) { |
80
|
1 |
|
$query = array(); |
81
|
|
|
|
82
|
1 |
|
if( $options['sticky_option'] == 'hide' ){ |
83
|
1 |
|
foreach( $options['selected_posts'] as $post ){ |
84
|
1 |
|
unstick_post($post); |
85
|
|
|
} |
86
|
|
|
}else{ |
87
|
|
|
if ( in_array( 'all', $options['selected_posts'], true ) ) { |
88
|
|
|
$query['post__in'] = get_option( 'sticky_posts' ); |
89
|
|
|
} else { |
90
|
|
|
$query['post__in'] = $options['selected_posts']; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $query; |
94
|
|
|
} |
95
|
1 |
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Response message for deleting posts. |
99
|
|
|
* |
100
|
|
|
* @param int $items_deleted count of items deleted. |
101
|
|
|
* |
102
|
|
|
* @return string Response message |
103
|
|
|
*/ |
104
|
|
|
protected function get_success_message( $items_deleted ) { |
105
|
|
|
/* translators: 1 Number of posts deleted */ |
106
|
|
|
return _n( 'Deleted %d sticky post', 'Deleted %d sticky posts', $items_deleted, 'bulk-delete' ); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.