diff --git a/assets/js/wp-bulk-delete-admin.js b/assets/js/wp-bulk-delete-admin.js index 9e6100b..fa89f0d 100644 --- a/assets/js/wp-bulk-delete-admin.js +++ b/assets/js/wp-bulk-delete-admin.js @@ -321,4 +321,39 @@ timeFormat: 'HH:mm:ss' }); }); + + jQuery(document).ready(function(){ + jQuery("#user_who_has_no_order").change(function() { + if( jQuery( "#user_who_has_no_order" ).is( ":checked" ) ) { + var selectedRoles = []; + jQuery( "input[name='delete_user_roles[]']:checked" ).each(function(){ + selectedRoles.push( jQuery(this).val() ); + }); + if( selectedRoles.length > 1 || ( selectedRoles.length === 1 && selectedRoles[0] !== "customer" ) ) { + alert('The "User Who Has No order" option only works with the Customer role.'); + } + jQuery( "input[name='delete_user_roles[]']" ).each(function() { + if( jQuery(this).val() !== "customer" ) { + jQuery(this).prop( "checked", false ); + } + }); + } + }); + jQuery( "input[name='delete_user_roles[]']" ).change(function() { + var userWhoHasNoOrderChecked = jQuery( "#user_who_has_no_order" ).is( ":checked" ); + if( userWhoHasNoOrderChecked ){ + if (jQuery(this).val() === "customer") { + jQuery("input[name='delete_user_roles[]']").each(function() { + if (jQuery(this).val() !== "customer") { + jQuery(this).prop("checked", false); + } + }); + } else { + alert('The "User Who Has No order" option only works with the Customer role.'); + jQuery('#user_who_has_no_order').prop( 'checked', false ); + } + } + }); + }); + })( jQuery ); diff --git a/includes/class-delete-api.php b/includes/class-delete-api.php index 2812423..d471f6b 100644 --- a/includes/class-delete-api.php +++ b/includes/class-delete-api.php @@ -52,6 +52,7 @@ public function get_delete_posts_ids( $data = array() ) { $delete_end_date = isset( $data['delete_end_date'] ) ? esc_sql( $data['delete_end_date'] ) : ''; $delete_authors = isset( $data['delete_authors'] ) ? array_map( 'intval', $data['delete_authors'] ) : array(); $delete_type = isset( $data['delete_type'] ) ? $data['delete_type'] : 'trash'; + $post_media = isset( $data['post_media'] ) ? $data['post_media'] : 'no'; $limit_post = !empty( $data['limit_post'] ) ? absint( $data['limit_post'] ) : '10000'; $date_type = isset( $data['date_type'] ) ? esc_sql( $data['date_type'] ) : 'custom_date'; $input_days = isset( $data['input_days'] ) ? esc_sql( $data['input_days'] ) : ''; @@ -159,7 +160,7 @@ public function get_delete_posts_ids( $data = array() ) { * @param array $data Posts Id. * @return array | deleted posts count. */ - public function do_delete_posts( $post_ids = array(), $force_delete = false, $custom_query = null ) { + public function do_delete_posts( $post_ids = array(), $force_delete = false, $item = array(), $custom_query = null ) { global $wpdb; $post_delete_count = 0; @@ -170,6 +171,15 @@ public function do_delete_posts( $post_ids = array(), $force_delete = false, $cu } if( ! empty( $post_ids ) && count( $post_ids ) > 0 ) { + + $post_attechment_id = get_post_meta( $post_id, '_thumbnail_id', true ); + $attechment_ids = $wpdb->get_col( "SELECT post_id FROM $wpdb->postmeta WHERE meta_value = $post_attechment_id" ); + if( isset( $item['post_media'] ) && $item['post_media'] === 'yes' ){ + if( count( $attechment_ids ) <= 1 ){ + wp_delete_attachment( $post_attechment_id, $force_delete ); + } + } + if( $custom_query == 'custom_query' ){ $all_posts = implode( ",",$post_ids ); $wpdb->query( "DELETE p,pt,pm FROM " . $wpdb->posts . " p LEFT JOIN " . $wpdb->term_relationships . " pt ON pt.object_id = p.ID LEFT JOIN " . $wpdb->postmeta . " pm ON pm.post_id = p.ID WHERE p.ID IN ({$all_posts})" ); @@ -460,6 +470,10 @@ public function run_cleanup( $cleanuptype = '' ){ * @return array | Users Id. */ public function get_delete_user_ids( $data = array() ){ + if( wpbd_is_pro() && class_exists( 'WPBD_Delete_API_Pro', false ) ){ + $wpbdpro = new WPBD_Delete_API_Pro(); + return $wpbdpro->get_delete_user_ids( $data ); + } global $wpdb; if( empty( $data['delete_user_roles'] ) && ( $data['user_meta_key'] == '' || $data['user_meta_value'] == '' ) ){ diff --git a/includes/delele-posts-form-functions.php b/includes/delele-posts-form-functions.php index 1e5cfad..5a35c94 100644 --- a/includes/delele-posts-form-functions.php +++ b/includes/delele-posts-form-functions.php @@ -81,8 +81,7 @@ function xt_delete_posts_form_process( $data ) { if ( $data['delete_type'] === 'permenant' ) { $force_delete = true; } - - $post_count = wpbulkdelete()->api->do_delete_posts( $post_ids, $force_delete, $custom_query ); + $post_count = wpbulkdelete()->api->do_delete_posts( $post_ids, $force_delete, $data, $custom_query ); return array( 'status' => 1, 'messages' => array( sprintf( esc_html__( '%d Record deleted successfully.', 'wp-bulk-delete' ), $post_count) @@ -762,6 +761,8 @@ function wpbd_render_common_form(){ wpbd_render_form_delete_type(); + wpbd_render_form_delete_media(); + wpbd_render_limit_post(); wpbd_render_delete_time(); @@ -784,4 +785,30 @@ function wpbd_get_timezone_string() { $tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins ); return $tz_offset; +} + +/** + * Render Delete Post Media. + * + * @since 1.0 + * @return void + */ +function wpbd_render_form_delete_media(){ + ?> + + + + + + + + + + + + + + + + + + + : + + +
+ +

+ +

+ + + + YYYY-MM-DD" msgstr "" -#: includes/delele-posts-form-functions.php:398 +#: includes/delele-posts-form-functions.php:397 msgid "This option will work well with Scheduled Delete, which will help to delete posts of the selected option from the scheduled run date." msgstr "" -#: includes/delele-posts-form-functions.php:416 +#: includes/delele-posts-form-functions.php:415 msgid "Post Modified :" msgstr "" -#: includes/delele-posts-form-functions.php:423 +#: includes/delele-posts-form-functions.php:422 msgid "posted between" msgstr "" -#: includes/delele-posts-form-functions.php:433 +#: includes/delele-posts-form-functions.php:432 msgid "Set the modified date interval for items to delete, or leave these fields blank to select all posts. The dates must be specified in the following format: YYYY-MM-DD" msgstr "" -#: includes/delele-posts-form-functions.php:451 +#: includes/delele-posts-form-functions.php:450 msgid "Post Content Count :" msgstr "" -#: includes/delele-posts-form-functions.php:454 +#: includes/delele-posts-form-functions.php:453 msgid "Delete Post with Content Count Limit" msgstr "" -#: includes/delele-posts-form-functions.php:456 +#: includes/delele-posts-form-functions.php:455 msgid "Less Then." msgstr "" -#: includes/delele-posts-form-functions.php:457 +#: includes/delele-posts-form-functions.php:456 msgid "Greater Then." msgstr "" -#: includes/delele-posts-form-functions.php:460 +#: includes/delele-posts-form-functions.php:459 msgid "Character Limit" msgstr "" -#: includes/delele-posts-form-functions.php:478 +#: includes/delele-posts-form-functions.php:477 msgid "If Post Title Contains :" msgstr "" -#: includes/delele-posts-form-functions.php:482 -#: includes/delele-posts-form-functions.php:497 +#: includes/delele-posts-form-functions.php:481 +#: includes/delele-posts-form-functions.php:496 msgid "Then" msgstr "" -#: includes/delele-posts-form-functions.php:484 -#: includes/delele-posts-form-functions.php:499 +#: includes/delele-posts-form-functions.php:483 +#: includes/delele-posts-form-functions.php:498 msgid "Delete It." msgstr "" -#: includes/delele-posts-form-functions.php:485 -#: includes/delele-posts-form-functions.php:500 +#: includes/delele-posts-form-functions.php:484 +#: includes/delele-posts-form-functions.php:499 msgid "Don't delete It." msgstr "" -#: includes/delele-posts-form-functions.php:493 +#: includes/delele-posts-form-functions.php:492 msgid "If Post Content Contains :" msgstr "" -#: includes/delele-posts-form-functions.php:519 +#: includes/delele-posts-form-functions.php:518 msgid "Post Delete Type :" msgstr "" -#: includes/delele-posts-form-functions.php:523 +#: includes/delele-posts-form-functions.php:522 msgid "Move to Trash" msgstr "" -#: includes/delele-posts-form-functions.php:525 +#: includes/delele-posts-form-functions.php:524 msgid "Delete permanently" msgstr "" -#: includes/delele-posts-form-functions.php:541 +#: includes/delele-posts-form-functions.php:540 msgid "Authors :" msgstr "" -#: includes/delele-posts-form-functions.php:580 -#: includes/delele-users-form-functions.php:223 +#: includes/delele-posts-form-functions.php:579 +#: includes/delele-users-form-functions.php:224 msgid "Limit :" msgstr "" -#: includes/delele-posts-form-functions.php:585 +#: includes/delele-posts-form-functions.php:584 msgid "Set the limit over post delete. It will delete only first limit posts. This option will help you in case of you have lots of posts to delete and script timeout." msgstr "" -#: includes/delele-posts-form-functions.php:602 +#: includes/delele-posts-form-functions.php:601 msgid "Custom fields settings :" msgstr "" -#: includes/delele-posts-form-functions.php:605 +#: includes/delele-posts-form-functions.php:604 msgid "Custom Fields Key" msgstr "" -#: includes/delele-posts-form-functions.php:629 +#: includes/delele-posts-form-functions.php:628 msgid "Cleanup Posts :" msgstr "" -#: includes/delele-posts-form-functions.php:635 +#: includes/delele-posts-form-functions.php:634 msgid "Revisions (%d Revisions)" msgstr "" -#: includes/delele-posts-form-functions.php:642 +#: includes/delele-posts-form-functions.php:641 msgid "Trash (Deleted Posts) (%d Trash)" msgstr "" -#: includes/delele-posts-form-functions.php:649 +#: includes/delele-posts-form-functions.php:648 msgid "Auto Drafts (%d Auto Drafts)" msgstr "" -#: includes/delele-posts-form-functions.php:667 +#: includes/delele-posts-form-functions.php:666 msgid "Delete Time :" msgstr "" -#: includes/delele-posts-form-functions.php:671 +#: includes/delele-posts-form-functions.php:670 msgid "Delete now" msgstr "" -#: includes/delele-posts-form-functions.php:673 +#: includes/delele-posts-form-functions.php:672 msgid "Schedule delete at" msgstr "" -#: includes/delele-posts-form-functions.php:676 +#: includes/delele-posts-form-functions.php:675 msgid "repeat" msgstr "" -#: includes/delele-posts-form-functions.php:682 +#: includes/delele-posts-form-functions.php:681 msgid "Timezone: (%s)" msgstr "" -#: includes/delele-posts-form-functions.php:683 +#: includes/delele-posts-form-functions.php:682 msgid "Scheduled delete runs using cron and backgroud process. So, its useful for delete huge number of records and repeatative delete." msgstr "" -#: includes/delele-posts-form-functions.php:701 +#: includes/delele-posts-form-functions.php:700 msgid "Don't repeat" msgstr "" -#: includes/delele-posts-form-functions.php:704 +#: includes/delele-posts-form-functions.php:703 msgid "10 Minutes" msgstr "" -#: includes/delele-posts-form-functions.php:707 +#: includes/delele-posts-form-functions.php:706 msgid "30 Minutes" msgstr "" -#: includes/delele-posts-form-functions.php:710 +#: includes/delele-posts-form-functions.php:709 msgid "Once Hourly" msgstr "" -#: includes/delele-posts-form-functions.php:713 +#: includes/delele-posts-form-functions.php:712 msgid "Twice Daily" msgstr "" -#: includes/delele-posts-form-functions.php:716 +#: includes/delele-posts-form-functions.php:715 msgid "Once Daily" msgstr "" -#: includes/delele-posts-form-functions.php:719 +#: includes/delele-posts-form-functions.php:718 msgid "Once Weekly" msgstr "" -#: includes/delele-posts-form-functions.php:722 +#: includes/delele-posts-form-functions.php:721 msgid "Once a Month" msgstr "" -#: includes/delele-posts-form-functions.php:726 +#: includes/delele-posts-form-functions.php:725 msgid "Save it as " msgstr "" -#: includes/delele-posts-form-functions.php:727 +#: includes/delele-posts-form-functions.php:726 msgid "eg: Daily Post Delete" msgstr "" -#: includes/delele-posts-form-functions.php:744 +#: includes/delele-posts-form-functions.php:743 msgid "Filter your posts :" msgstr "" +#: includes/delele-posts-form-functions.php:800 +msgid "Delete Post Featured image :" +msgstr "" + +#: includes/delele-posts-form-functions.php:805 +msgid "It enables the removal of the featured image of the post, if the image is a featured image of multiple posts, it will not be removed. and If the image is being used in a place other than the featured image, it will be deleted." +msgstr "" + #: includes/delele-terms-form-functions.php:52 msgid "%d Term(s) deleted successfully." msgstr "" @@ -1067,68 +1075,80 @@ msgstr "" msgid "Select the post taxonomy whose terms you want to delete." msgstr "" -#: includes/delele-users-form-functions.php:36 +#: includes/delele-users-form-functions.php:37 msgid "Please select user role or add usermeta key and value." msgstr "" -#: includes/delele-users-form-functions.php:59 +#: includes/delele-users-form-functions.php:60 msgid "%d User(s) deleted successfully." msgstr "" -#: includes/delele-users-form-functions.php:109 +#: includes/delele-users-form-functions.php:110 msgid "Select the user roles from which you want to delete users." msgstr "" -#: includes/delele-users-form-functions.php:130 +#: includes/delele-users-form-functions.php:131 msgid "User Meta Key" msgstr "" -#: includes/delele-users-form-functions.php:153 -#: includes/delele-users-form-functions.php:156 +#: includes/delele-users-form-functions.php:154 +#: includes/delele-users-form-functions.php:157 msgid "User Email" msgstr "" -#: includes/delele-users-form-functions.php:177 +#: includes/delele-users-form-functions.php:178 msgid "User Registration Date :" msgstr "" -#: includes/delele-users-form-functions.php:180 +#: includes/delele-users-form-functions.php:181 msgid "Delete Users which are" msgstr "" -#: includes/delele-users-form-functions.php:183 +#: includes/delele-users-form-functions.php:184 msgid "registered within last" msgstr "" -#: includes/delele-users-form-functions.php:190 +#: includes/delele-users-form-functions.php:191 msgid "registered between custom" msgstr "" -#: includes/delele-users-form-functions.php:200 +#: includes/delele-users-form-functions.php:201 msgid "Set the reigration date interval for users to delete ( only delete users register between these dates ) or leave these fields blank to select all users. The dates must be specified in the following format: YYYY-MM-DD" msgstr "" -#: includes/delele-users-form-functions.php:205 +#: includes/delele-users-form-functions.php:206 msgid "This option will work well with Scheduled Delete, which will help to delete users of the selected option from the scheduled run date." msgstr "" -#: includes/delele-users-form-functions.php:228 +#: includes/delele-users-form-functions.php:229 msgid "Set the limit over user delete. It will delete only first limited users. This option will help you in case of you have lots of users to delete and script timeout." msgstr "" -#: includes/delele-users-form-functions.php:245 +#: includes/delele-users-form-functions.php:246 msgid "Assign deleted user's data to" msgstr "" -#: includes/delele-users-form-functions.php:250 -#: includes/delele-users-form-functions.php:254 +#: includes/delele-users-form-functions.php:251 +#: includes/delele-users-form-functions.php:255 msgid "Select User" msgstr "" -#: includes/delele-users-form-functions.php:260 +#: includes/delele-users-form-functions.php:261 msgid "Select user to whom you want to assign deleted user's data." msgstr "" +#: includes/delele-users-form-functions.php:279 +msgid "User Who Has No order" +msgstr "" + +#: includes/delele-users-form-functions.php:285 +msgid "Delete WooCommerce Customer Who has no Order" +msgstr "" + +#: includes/delele-users-form-functions.php:288 +msgid "Select users who have no order in WooCommerce ( it's only for the customer role )" +msgstr "" + #: wp-bulk-delete.php:75 #: wp-bulk-delete.php:82 msgid "Cheatin’ huh?"