diff --git a/assets/js/src/bulk-delete.js b/assets/js/src/bulk-delete.js
index 7f6c232e7..ee54ce72f 100644
--- a/assets/js/src/bulk-delete.js
+++ b/assets/js/src/bulk-delete.js
@@ -62,6 +62,46 @@ jQuery(document).ready(function () {
}
}
+ /**
+ * Toggle the date fields.
+ */
+ function toggle_date_filter(el) {
+ if ( 2 === jQuery("#smbd" + el + "_op").prop('selectedIndex') ) {
+ // Enable and display published on date.
+ jQuery("#smbd" + el + "_pub_date").prop('disabled', false);
+ jQuery("#smbd" + el + "_pub_date").show();
+ // Disable and hide other fields.
+ jQuery("#smbd" + el + "_pub_date_start").prop('disabled', true);
+ jQuery("#smbd" + el + "_pub_date_start").hide();
+ jQuery("#smbd" + el + "_pub_date_end").prop('disabled', true);
+ jQuery("#smbd" + el + "_pub_date_end").hide();
+ jQuery("#smbd" + el + "_days").prop('disabled', true);
+ jQuery("#smbd" + el + "_days_box").hide();
+ } else if ( 3 === jQuery( "#smbd" + el + "_op" ).prop('selectedIndex') ){
+ // Enable and display between date boxes.
+ jQuery("#smbd" + el + "_pub_date_start").prop('disabled', false);
+ jQuery("#smbd" + el + "_pub_date_start").show();
+ jQuery("#smbd" + el + "_pub_date_end").prop('disabled', false);
+ jQuery("#smbd" + el + "_pub_date_end").show();
+ // Disable and hide other fields.
+ jQuery("#smbd" + el + "_days").prop('disabled', true);
+ jQuery("#smbd" + el + "_days_box").hide();
+ jQuery("#smbd" + el + "_pub_date").prop('disabled', true);
+ jQuery("#smbd" + el + "_pub_date").hide();
+ } else {
+ // Enable and display day box.
+ jQuery("#smbd" + el + "_days").prop('disabled', false);
+ jQuery("#smbd" + el + "_days_box").show();
+ // Disable and hide other fields.
+ jQuery("#smbd" + el + "_pub_date").prop('disabled', true);
+ jQuery("#smbd" + el + "_pub_date").hide();
+ jQuery("#smbd" + el + "_pub_date_start").prop('disabled', true);
+ jQuery("#smbd" + el + "_pub_date_start").hide();
+ jQuery("#smbd" + el + "_pub_date_end").prop('dsiabled', true);
+ jQuery("#smbd" + el + "_pub_date_end").hide();
+ }
+ }
+
/**
* Toggle limit restrict fields
*/
@@ -148,6 +188,16 @@ jQuery(document).ready(function () {
timeFormat: 'HH:mm:ss'
});
+ jQuery('#smbd' + value + '_pub_date').datepicker( { dateFormat: 'yy-mm-dd' } );
+
+ jQuery('#smbd' + value + '_pub_date_start').datepicker( { dateFormat: 'yy-mm-dd' } );
+
+ jQuery('#smbd' + value + '_pub_date_end').datepicker( { dateFormat: 'yy-mm-dd' } );
+
+ jQuery('#smbd' + value + '_op').change(function () {
+ toggle_date_filter(value);
+ });
+
jQuery('#smbd' + value + '_restrict').change(function () {
toggle_date_restrict(value);
});
diff --git a/include/Core/Base/Mixin/Renderer.php b/include/Core/Base/Mixin/Renderer.php
index c5fe95d39..0518e7eea 100644
--- a/include/Core/Base/Mixin/Renderer.php
+++ b/include/Core/Base/Mixin/Renderer.php
@@ -629,7 +629,25 @@ protected function render_filtering_table_header() {
* Render restrict settings.
*/
protected function render_restrict_settings() {
- bd_render_restrict_settings( $this->field_slug, $this->item_type );
+ $slug = $this->field_slug;
+ $item = $this->item_type;
+ ?>
+
+
+
+
+
+
+
+
+
+ |
+ field_slug . '_exclude_sticky', false );
$options['force_delete'] = bd_array_get_bool( $request, 'smbd_' . $this->field_slug . '_force_delete', false );
- $options['date_op'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_op' );
- $options['days'] = absint( bd_array_get( $request, 'smbd_' . $this->field_slug . '_days' ) );
+ $options['date_op'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_op' );
+ $options['days'] = absint( bd_array_get( $request, 'smbd_' . $this->field_slug . '_days' ) );
+ $options['pub_date'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_pub_date' );
+ $options['pub_date_start'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_pub_date_start' );
+ $options['pub_date_end'] = bd_array_get( $request, 'smbd_' . $this->field_slug . '_pub_date_end' );
return $options;
}
diff --git a/include/util/query.php b/include/util/query.php
index eb1ccf119..dda50bc44 100644
--- a/include/util/query.php
+++ b/include/util/query.php
@@ -52,6 +52,25 @@ function bd_build_query_options( $delete_options, $options = array() ) {
$delete_options['date_op'] => "{$delete_options['days']} day ago",
),
);
+ } elseif ( '=' === $delete_options['date_op'] ) {
+ $published_date = getdate( strtotime( $delete_options['pub_date'] ) );
+ $options['date_query'] = [
+ [
+ 'year' => $published_date['year'],
+ 'month' => $published_date['mon'],
+ 'day' => $published_date['mday'],
+ ],
+ ];
+ } elseif ( 'between' === $delete_options['date_op'] ) {
+ $published_date_start = date( 'Y-m-d', strtotime( $delete_options['pub_date_start'] ) );
+ $published_date_end = date( 'Y-m-d', strtotime( $delete_options['pub_date_end'] ) );
+ $options['date_query'] = [
+ [
+ 'after' => $published_date_start,
+ 'before' => $published_date_end,
+ 'inclusive' => true,
+ ],
+ ];
}
}
diff --git a/tests/wp-unit/include/Core/Posts/Modules/DeletePostsByCommentsModuleTest.php b/tests/wp-unit/include/Core/Posts/Modules/DeletePostsByCommentsModuleTest.php
index f0633043c..953afc07f 100644
--- a/tests/wp-unit/include/Core/Posts/Modules/DeletePostsByCommentsModuleTest.php
+++ b/tests/wp-unit/include/Core/Posts/Modules/DeletePostsByCommentsModuleTest.php
@@ -280,6 +280,72 @@ public function provide_data_to_test_posts_deletion_by_comments_count_with_less_
'available_posts' => 15,
),
),
+ // (+ve Case) Deletes few posts for the given comment count with less than operator and given published date and post type/status.
+ array(
+ array(
+ array(
+ 'posts' => 15,
+ 'comments' => 5,
+ 'post_type' => 'post',
+ 'post_status' => 'publish',
+ ),
+ array(
+ 'posts' => 10,
+ 'comments' => 7,
+ 'post_type' => 'order',
+ 'post_status' => 'publish',
+ ),
+ ),
+ array(
+ 'operator' => '<',
+ 'comment_count' => 10,
+ 'selected_post_type' => 'order|publish',
+ 'limit_to' => 0,
+ 'restrict' => true,
+ 'date_op' => '=',
+ 'pub_date' => date( 'Y-m-d' ),
+ 'force_delete' => true,
+ ),
+ array(
+ 'deleted_posts' => 10,
+ 'trashed_posts' => 0,
+ 'available_posts' => 15,
+ ),
+ ),
+ // (+ve Case) Deletes few posts for the given comment count with less than operator and given published date and post type/status.
+ array(
+ array(
+ array(
+ 'posts' => 15,
+ 'comments' => 5,
+ 'post_type' => 'post',
+ 'post_status' => 'publish',
+ 'published_date' => date( 'Y-m-d h:i:s', strtotime( '-4 day' ) ),
+ ),
+ array(
+ 'posts' => 10,
+ 'comments' => 7,
+ 'post_type' => 'post',
+ 'post_status' => 'publish',
+ ),
+ ),
+ array(
+ 'operator' => '<',
+ 'comment_count' => 10,
+ 'selected_post_type' => 'post|publish',
+ 'limit_to' => 0,
+ 'restrict' => true,
+ 'date_op' => 'between',
+ 'pub_date_start' => date( 'Y-m-d', strtotime( '-5 day') ),
+ 'pub_date_end' => date( 'Y-m-d', strtotime( '-3 day' ) ),
+ 'force_delete' => true,
+ ),
+ array(
+ 'deleted_posts' => 15,
+ 'trashed_posts' => 0,
+ 'available_posts' => 10,
+ ),
+ ),
);
}
@@ -303,11 +369,15 @@ public function test_posts_can_be_deleted_by_posts_count( $setup, $operations, $
if ( ! array_key_exists( 'post_status', $element ) ) {
$element['post_status'] = 'publish';
}
+ if ( ! array_key_exists( 'published_date', $element ) ) {
+ $element['published_date'] = date( 'Y-m-d' );
+ }
$post_ids = $this->factory->post->create_many(
$element['posts'],
array(
'post_type' => $element['post_type'],
'post_status' => $element['post_status'],
+ 'post_date' => $element['published_date'],
)
);
foreach ( $post_ids as $post_id ) {