|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\Posts\Modules; |
|
4
|
|
|
|
|
5
|
|
|
use BulkWP\BulkDelete\Core\Posts\PostsModule; |
|
6
|
|
|
|
|
7
|
|
|
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
|
|
|
protected function initialize() { |
|
16
|
|
|
$this->item_type = 'posts'; |
|
17
|
|
|
$this->field_slug = 'specific'; |
|
18
|
|
|
$this->meta_box_slug = 'bd_posts_by_url'; |
|
19
|
|
|
$this->action = 'delete_posts_by_url'; |
|
20
|
|
|
$this->messages = array( |
|
21
|
|
|
'box_label' => __( 'By URL', 'bulk-delete' ), |
|
22
|
|
|
); |
|
23
|
|
|
} |
|
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
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
|
49
|
|
|
$options['force_delete'] = bd_array_get_bool( $request, 'smbd_specific_force_delete', false ); |
|
50
|
|
|
|
|
51
|
|
|
$options['urls'] = preg_split( '/\r\n|\r|\n/', bd_array_get( $request, 'smdb_specific_pages_urls' ) ); |
|
52
|
|
|
|
|
53
|
|
|
return $options; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
protected function do_delete( $delete_options ) { |
|
57
|
|
|
$post_ids = array(); |
|
58
|
|
|
|
|
59
|
|
|
foreach ( $delete_options['urls'] as $url ) { |
|
60
|
|
|
if ( substr( $url, 0, 1 ) == '/' ) { |
|
61
|
|
|
$post_ids[] = url_to_postid( get_site_url() . $url ); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $this->delete_posts_by_id( $post_ids, $delete_options['force_delete'] ); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function get_success_message( $items_deleted ) { |
|
69
|
|
|
/* translators: 1 Number of pages deleted */ |
|
70
|
|
|
return _n( 'Deleted %d post with the selected post status', 'Deleted %d posts with the selected post status', $items_deleted, 'bulk-delete' ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
protected function build_query( $options ) { |
|
74
|
|
|
// Left empty on purpose. |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|