PluginProbe
Bulk Delete / trunk
Bulk Delete vtrunk
6.12 trunk 0.2 0.3 0.4 0.6 0.7 0.8 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.2.1 2.2.2 3.0 3.1 All 64 releases
bulk-delete / include / Core / Posts / Modules / DeletePostsByCommentsModule.php

DeletePostsByCommentsModule.php in Bulk Delete trunk, at include/Core/Posts/Modules/DeletePostsByCommentsModule.php

129 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 Comments Module.
11 *
12 * @since 6.0.0
13 */
14 class DeletePostsByCommentsModule extends PostsModule {
15 /**
16 * Base parameters setup.
17 */
18 protected function initialize() {
19 $this->item_type = 'posts';
20 $this->field_slug = 'comments';
21 $this->meta_box_slug = 'bd_by_comments';
22 $this->action = 'delete_posts_by_comments';
23 $this->cron_hook = 'do-bulk-delete-posts-by-comments';
24 $this->scheduler_url = 1;
25 $this->messages = array(
26 'box_label' => __( 'By Comment count', 'bulk-delete' ),
27 'scheduled' => __( 'The selected posts are scheduled for deletion', 'bulk-delete' ),
28 'cron_label' => __( 'Delete Post By Comments', 'bulk-delete' ),
29 'confirm_deletion' => __( 'Are you sure you want to delete all the posts based on the selected comment count setting?', 'bulk-delete' ),
30 'confirm_scheduled' => __( 'Are you sure you want to schedule the deletion of all the posts based on the selected comment count setting?', 'bulk-delete' ),
31 'validation_error' => __( 'Please enter the comments count based on which posts should be deleted. A valid comment count will be greater than or equal to zero', 'bulk-delete' ),
32 /* translators: 1 Number of posts deleted */
33 'deleted_one' => __( 'Deleted %d post from the selected post type and post status', 'bulk-delete' ),
34 /* translators: 1 Number of posts deleted */
35 'deleted_multiple' => __( 'Deleted %d posts from the selected post type and post status', 'bulk-delete' ),
36 );
37 }
38
39 /**
40 * Render Delete posts by comments box.
41 */
42 public function render() {
43 ?>
44 <h4><?php esc_html_e( 'Delete Posts based on the number of comments', 'bulk-delete' ); ?></h4>
45
46 <!-- Comments start-->
47 <fieldset class="options">
48 <table class="optiontable">
49 <tr>
50 <td scope="row" colspan="2">
51 <?php esc_html_e( 'Delete posts that have comments', 'bulk-delete' ); ?>
52 </td>
53 <td>
54 <?php $this->render_number_comparison_operators(); ?>
55 </td>
56 <td>
57 <input type="number" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_count_value"
58 id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_count_value" placeholder="Comments Count" min="0" class="comments_count_num">
59 </td>
60 </tr>
61 </table>
62
63 <table class="optiontable">
64 <?php
65 $this->render_filtering_table_header();
66 $this->render_restrict_settings();
67 $this->render_delete_settings();
68 $this->render_private_post_settings();
69 $this->render_limit_settings();
70 $this->render_cron_settings();
71 ?>
72 </table>
73 </fieldset>
74 <?php
75 $this->render_submit_button();
76 }
77
78 /**
79 * Process delete posts, user inputs by comments count.
80 *
81 * @param array $request Request array.
82 * @param array $options Options for deleting posts.
83 *
84 * @return array $options Inputs from user for posts that were need to be deleted.
85 */
86 protected function convert_user_input_to_options( $request, $options ) {
87 $options['operator'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_operator' );
88 $options['comment_count'] = absint( bd_array_get( $request, 'smbd_' . $this->field_slug . '_count_value' ) );
89
90 return $options;
91 }
92
93 /**
94 * Build the Query from user input.
95 *
96 * @param array $options User Input.
97 *
98 * @return array $query Query Params.
99 */
100 protected function build_query( $options ) {
101 $query = array();
102
103 $query['comment_count'] = array(
104 'compare' => $options['operator'],
105 'value' => $options['comment_count'],
106 );
107
108 return $query;
109 }
110
111 protected function append_to_js_array( $js_array ) {
112 $js_array['validators'][ $this->action ] = 'validateCommentsCount';
113
114 return $js_array;
115 }
116
117 /**
118 * Response message for deleting posts.
119 *
120 * @param int $items_deleted count of items deleted.
121 *
122 * @return string Response message
123 */
124 protected function get_success_message( $items_deleted ) {
125 /* translators: 1 Number of posts deleted */
126 return _n( 'Deleted %d post with the selected comments count', 'Deleted %d posts with the selected comments count', $items_deleted, 'bulk-delete' );
127 }
128 }
129