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 URL Module. |
11
|
|
|
* |
12
|
|
|
* @since 6.0.0 |
13
|
|
|
*/ |
14
|
|
|
class DeletePostsByURLModule extends PostsModule { |
15
|
9 |
|
protected function initialize() { |
16
|
9 |
|
$this->item_type = 'posts'; |
17
|
9 |
|
$this->field_slug = 'specific'; |
18
|
9 |
|
$this->meta_box_slug = 'bd_posts_by_url'; |
19
|
9 |
|
$this->action = 'delete_posts_by_url'; |
20
|
9 |
|
$this->messages = array( |
21
|
9 |
|
'box_label' => __( 'By URL', 'bulk-delete' ), |
22
|
|
|
); |
23
|
9 |
|
} |
24
|
|
|
|
25
|
|
|
public function render() { ?> |
26
|
|
|
<!-- URLs start--> |
27
|
|
|
<h4><?php _e( 'Delete posts and pages that have the following Permalink', 'bulk-delete' ); ?></h4> |
28
|
|
|
|
29
|
|
|
<fieldset class="options"> |
30
|
|
|
<table class="optiontable"> |
31
|
|
|
<tr> |
32
|
|
|
<td scope="row" colspan="2"> |
33
|
|
|
<label for="smdb_specific_pages"><?php _e( 'Enter one post url (not post ids) per line', 'bulk-delete' ); ?></label> |
34
|
|
|
<br> |
35
|
|
|
<textarea id="smdb_specific_pages_urls" name="smdb_specific_pages_urls" rows="5" columns="80"></textarea> |
36
|
|
|
</td> |
37
|
|
|
</tr> |
38
|
|
|
|
39
|
|
|
<?php $this->render_filtering_table_header(); ?> |
40
|
|
|
<?php $this->render_delete_settings(); ?> |
41
|
|
|
|
42
|
|
|
</table> |
43
|
|
|
</fieldset> |
44
|
|
|
<?php |
45
|
|
|
$this->render_submit_button(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function filter_js_array( $js_array ) { |
49
|
|
|
$js_array['validators'][ $this->action ] = 'validateUrl'; |
50
|
|
|
$js_array['error_msg'][ $this->action ] = 'enterUrl'; |
51
|
|
|
$js_array['pre_action_msg'][ $this->action ] = 'deletePostsByURLWarning'; |
52
|
|
|
|
53
|
|
|
$js_array['msg']['enterUrl'] = __( 'Please enter at least one post url', 'bulk-delete' ); |
54
|
|
|
$js_array['msg']['deletePostsByURLWarning'] = __( 'Are you sure you want to delete all the posts based on the entered url?', 'bulk-delete' ); |
55
|
|
|
|
56
|
|
|
return $js_array; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
60
|
|
|
$options['force_delete'] = bd_array_get_bool( $request, 'smbd_specific_force_delete', false ); |
61
|
|
|
|
62
|
|
|
$options['urls'] = preg_split( '/\r\n|\r|\n/', bd_array_get( $request, 'smdb_specific_pages_urls' ) ); |
63
|
|
|
|
64
|
|
|
return $options; |
65
|
|
|
} |
66
|
|
|
|
67
|
9 |
|
protected function do_delete( $delete_options ) { |
68
|
9 |
|
$post_ids = array(); |
69
|
|
|
|
70
|
9 |
|
foreach ( $delete_options['urls'] as $url ) { |
71
|
9 |
|
if ( substr( $url, 0, 1 ) === '/' ) { |
72
|
|
|
$url = get_site_url() . $url; |
73
|
|
|
} |
74
|
|
|
|
75
|
9 |
|
$post_id = url_to_postid( $url ); |
76
|
|
|
|
77
|
9 |
|
if ( $post_id > 0 ) { |
78
|
7 |
|
$post_ids[] = $post_id; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
9 |
|
return $this->delete_posts_by_id( $post_ids, $delete_options['force_delete'] ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
protected function get_success_message( $items_deleted ) { |
86
|
|
|
/* translators: 1 Number of pages deleted */ |
87
|
|
|
return _n( 'Deleted %d post with the selected post status', 'Deleted %d posts with the selected post status', $items_deleted, 'bulk-delete' ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
protected function build_query( $options ) { |
91
|
|
|
// Left empty on purpose. |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|