Changeset 3450846
- Timestamp:
- 01/31/2026 07:00:10 AM (2 months ago)
- Location:
- smart-bulk-content-remover
- Files:
-
- 16 added
- 4 edited
-
tags/1.1 (added)
-
tags/1.1/assets (added)
-
tags/1.1/assets/css (added)
-
tags/1.1/assets/css/custom.css (added)
-
tags/1.1/assets/images (added)
-
tags/1.1/assets/images/close.svg (added)
-
tags/1.1/assets/images/loader.svg (added)
-
tags/1.1/assets/js (added)
-
tags/1.1/assets/js/custom.js (added)
-
tags/1.1/assets/js/jquery.validate.min.js (added)
-
tags/1.1/includes (added)
-
tags/1.1/includes/class-smart-bulk-content-remover.php (added)
-
tags/1.1/languages (added)
-
tags/1.1/readme.txt (added)
-
tags/1.1/smart-bulk-content-remover.php (added)
-
tags/1.1/uninstall.php (added)
-
trunk/assets/js/custom.js (modified) (1 diff)
-
trunk/includes/class-smart-bulk-content-remover.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/smart-bulk-content-remover.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
smart-bulk-content-remover/trunk/assets/js/custom.js
r3358949 r3450846 985 985 jQuery(function($) { 986 986 987 $('#abdfw-page-schedule-form').on('submit', function(e){ 988 e.preventDefault(); 989 990 var $message = $('#abdfw_page_schedule_message'); 991 $message.text(''); 992 993 $.post(abdfw_ajax_object.ajaxurl, { 994 action: 'abdfw_save_page_cleanup_schedule', 995 nonce: $('#abdfw_page_schedule_nonce').val(), 996 enabled: $('#abdfw_page_schedule_enabled').is(':checked') ? 1 : 0, 997 frequency: $('#abdfw_page_schedule_frequency').val(), 998 time: $('#abdfw_page_schedule_time').val(), 999 status: $('#abdfw_page_schedule_status').val(), 1000 author: $('#abdfw_page_schedule_author').val(), 1001 search: $('#abdfw_page_schedule_search').val(), 1002 from: $('#abdfw_page_schedule_from').val(), 1003 to: $('#abdfw_page_schedule_to').val(), 1004 permanent: $('#abdfw_page_schedule_permanent').is(':checked') ? 1 : 0 1005 }, function (res) { 1006 var msg = ''; 1007 if (res.success) { 1008 msg = res.data.message || 'Schedule saved.'; 1009 if (res.data.next_run) { 1010 msg += ' Next run: ' + res.data.next_run; 1011 } 1012 $message 1013 .removeClass('error') 1014 .addClass('success') 1015 .text(msg) 1016 .fadeIn(); 1017 } else { 1018 $message 1019 .removeClass('success') 1020 .addClass('error') 1021 .text('Error saving schedule.') 1022 .fadeIn(); 1023 } 1024 // Hide message after 3 seconds 1025 setTimeout(function () { 1026 $message.fadeOut(); 1027 }, 3000); 1028 }); 1029 }); 1030 987 1031 function abdfw_loadPages() { 988 1032 $('#abdfw-page-list').html('<p>Loading…</p>'); -
smart-bulk-content-remover/trunk/includes/class-smart-bulk-content-remover.php
r3387224 r3450846 12 12 add_action('admin_menu', array($this, 'abdfw_add_admin_menu')); 13 13 add_filter( 'plugin_action_links_' . ABDFW_PLUGIN_BASENAME, array( $this, 'abdfwp_add_settings_link' ) ); 14 add_filter( 'cron_schedules', array( $this, 'abdfw_add_cron_schedules' ) ); 15 add_action( 'init', array( $this, 'abdfw_maybe_schedule_page_cleanup' ) ); 16 add_action( 'abdfw_run_scheduled_page_cleanup', array( $this, 'abdfw_run_scheduled_page_cleanup' ) ); 14 17 } 15 18 … … 60 63 add_action( 'wp_ajax_abdfw_load_comments', [ $this, 'abdfw_load_comments' ] ); 61 64 add_action( 'wp_ajax_abdfw_delete_comments', [ $this, 'abdfw_delete_comments' ] ); 65 66 // page schedule 67 add_action( 'wp_ajax_abdfw_save_page_cleanup_schedule', [ $this, 'abdfw_save_page_cleanup_schedule' ] ); 62 68 63 69 } … … 198 204 </form> 199 205 </div> 206 207 <?php 208 $page_schedule = get_option( 'abdfw_page_cleanup_schedule', [] ); 209 $schedule_enabled = ! empty( $page_schedule['enabled'] ); 210 $schedule_frequency = $page_schedule['frequency'] ?? 'daily'; 211 $schedule_time = $page_schedule['time'] ?? '02:00'; 212 $schedule_status = $page_schedule['status'] ?? ''; 213 $schedule_author = isset( $page_schedule['author'] ) ? (int) $page_schedule['author'] : 0; 214 $schedule_from = $page_schedule['from'] ?? ''; 215 $schedule_to = $page_schedule['to'] ?? ''; 216 $schedule_search = $page_schedule['search'] ?? ''; 217 $schedule_permanent = ! empty( $page_schedule['permanent'] ); 218 $next_run = wp_next_scheduled( 'abdfw_run_scheduled_page_cleanup' ); 219 $schedule_authors = get_users( [ 220 'capability' => 'edit_posts', 221 ] ); 222 ?> 223 224 <div class="abdfw-page-schedule"> 225 <h2><?php esc_html_e( 'Schedule Automatic Cleanup', 'smart-bulk-content-remover' ); ?></h2> 226 <form id="abdfw-page-schedule-form"> 227 <?php wp_nonce_field( 'abdfw_page_schedule', 'abdfw_page_schedule_nonce' ); ?> 228 <table class="form-table"> 229 <tr> 230 <th><?php esc_html_e( 'Enable Schedule', 'smart-bulk-content-remover' ); ?></th> 231 <td> 232 <label class="abdfw_switch" for="abdfw_page_schedule_enabled"> 233 <input type="checkbox" id="abdfw_page_schedule_enabled" <?php checked( $schedule_enabled ); ?> /> 234 <span class="abdfw_slider abdfw_round"></span> 235 </label> 236 </td> 237 </tr> 238 <tr> 239 <th><label for="abdfw_page_schedule_frequency"><?php esc_html_e( 'Frequency', 'smart-bulk-content-remover' ); ?></label></th> 240 <td> 241 <select id="abdfw_page_schedule_frequency"> 242 <option value="daily" <?php selected( $schedule_frequency, 'daily' ); ?>><?php esc_html_e( 'Daily', 'smart-bulk-content-remover' ); ?></option> 243 <option value="weekly" <?php selected( $schedule_frequency, 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'smart-bulk-content-remover' ); ?></option> 244 <option value="monthly" <?php selected( $schedule_frequency, 'monthly' ); ?>><?php esc_html_e( 'Monthly', 'smart-bulk-content-remover' ); ?></option> 245 </select> 246 </td> 247 </tr> 248 <tr> 249 <th><label for="abdfw_page_schedule_time"><?php esc_html_e( 'Run Time', 'smart-bulk-content-remover' ); ?></label></th> 250 <td> 251 <input type="time" id="abdfw_page_schedule_time" value="<?php echo esc_attr( $schedule_time ); ?>" /> 252 <p class="description"><?php esc_html_e( 'Uses site timezone.', 'smart-bulk-content-remover' ); ?></p> 253 </td> 254 </tr> 255 <tr> 256 <th><label for="abdfw_page_schedule_status"><?php esc_html_e( 'Status', 'smart-bulk-content-remover' ); ?></label></th> 257 <td> 258 <select id="abdfw_page_schedule_status"> 259 <option value="" <?php selected( $schedule_status, '' ); ?>><?php esc_html_e( 'All Statuses', 'smart-bulk-content-remover' ); ?></option> 260 <option value="publish" <?php selected( $schedule_status, 'publish' ); ?>><?php esc_html_e( 'Published', 'smart-bulk-content-remover' ); ?></option> 261 <option value="draft" <?php selected( $schedule_status, 'draft' ); ?>><?php esc_html_e( 'Draft', 'smart-bulk-content-remover' ); ?></option> 262 <option value="pending" <?php selected( $schedule_status, 'pending' ); ?>><?php esc_html_e( 'Pending', 'smart-bulk-content-remover' ); ?></option> 263 <option value="trash" <?php selected( $schedule_status, 'trash' ); ?>><?php esc_html_e( 'Trash', 'smart-bulk-content-remover' ); ?></option> 264 </select> 265 </td> 266 </tr> 267 <tr> 268 <th><label for="abdfw_page_schedule_author"><?php esc_html_e( 'Author', 'smart-bulk-content-remover' ); ?></label></th> 269 <td> 270 <select id="abdfw_page_schedule_author"> 271 <option value="" <?php selected( $schedule_author, 0 ); ?>><?php esc_html_e( 'All Authors', 'smart-bulk-content-remover' ); ?></option> 272 <?php foreach ( $schedule_authors as $a ) : ?> 273 <option value="<?php echo esc_attr( $a->ID ); ?>" <?php selected( $schedule_author, $a->ID ); ?>><?php echo esc_html( $a->display_name ); ?></option> 274 <?php endforeach; ?> 275 </select> 276 </td> 277 </tr> 278 <tr> 279 <th><label for="abdfw_page_schedule_search"><?php esc_html_e( 'Title Contains', 'smart-bulk-content-remover' ); ?></label></th> 280 <td> 281 <input type="text" id="abdfw_page_schedule_search" value="<?php echo esc_attr( $schedule_search ); ?>" /> 282 </td> 283 </tr> 284 <tr> 285 <th><?php esc_html_e( 'Date Range', 'smart-bulk-content-remover' ); ?></th> 286 <td> 287 <label for="abdfw_page_schedule_from"><?php esc_html_e( 'From:', 'smart-bulk-content-remover' ); ?></label> 288 <input type="date" id="abdfw_page_schedule_from" value="<?php echo esc_attr( $schedule_from ); ?>" /> 289 <label for="abdfw_page_schedule_to"><?php esc_html_e( 'To:', 'smart-bulk-content-remover' ); ?></label> 290 <input type="date" id="abdfw_page_schedule_to" value="<?php echo esc_attr( $schedule_to ); ?>" /> 291 </td> 292 </tr> 293 <tr> 294 <th><?php esc_html_e( 'Delete Mode', 'smart-bulk-content-remover' ); ?></th> 295 <td> 296 <label> 297 <input type="checkbox" id="abdfw_page_schedule_permanent" <?php checked( $schedule_permanent ); ?> /> 298 <?php esc_html_e( 'Permanently Delete (skip Trash)', 'smart-bulk-content-remover' ); ?> 299 </label> 300 </td> 301 </tr> 302 </table> 303 <p> 304 <button type="submit" class="button button-primary"><?php esc_html_e( 'Save Schedule', 'smart-bulk-content-remover' ); ?></button> 305 <span id="abdfw_page_schedule_message" class="abdfw-status"></span> 306 </p> 307 <?php if ( $next_run ) : ?> 308 <p class="description"> 309 <?php echo esc_html( sprintf( __( 'Next run: %s', 'smart-bulk-content-remover' ), date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $next_run ) ) ); ?> 310 </p> 311 <?php endif; ?> 312 </form> 313 </div> 200 314 201 315 <!-- Advance page delete html --> … … 2419 2533 wp_send_json_success( [ 'message' => 'Selected pages deleted.' ] ); 2420 2534 } 2535 2536 /** 2537 * Add custom cron schedules. 2538 */ 2539 public function abdfw_add_cron_schedules( $schedules ) { 2540 if ( ! isset( $schedules['weekly'] ) ) { 2541 $schedules['weekly'] = [ 2542 'interval' => 7 * DAY_IN_SECONDS, 2543 'display' => __( 'Once Weekly', 'smart-bulk-content-remover' ), 2544 ]; 2545 } 2546 2547 if ( ! isset( $schedules['monthly'] ) ) { 2548 $schedules['monthly'] = [ 2549 'interval' => 30 * DAY_IN_SECONDS, 2550 'display' => __( 'Once Monthly', 'smart-bulk-content-remover' ), 2551 ]; 2552 } 2553 2554 return $schedules; 2555 } 2556 2557 /** 2558 * Ensure schedule exists on load. 2559 */ 2560 public function abdfw_maybe_schedule_page_cleanup() { 2561 $settings = get_option( 'abdfw_page_cleanup_schedule', [] ); 2562 if ( empty( $settings['enabled'] ) ) { 2563 return; 2564 } 2565 2566 if ( ! wp_next_scheduled( 'abdfw_run_scheduled_page_cleanup' ) ) { 2567 $this->abdfw_reschedule_page_cleanup( $settings ); 2568 } 2569 } 2570 2571 /** 2572 * Save schedule settings and re-schedule cron. 2573 */ 2574 public function abdfw_save_page_cleanup_schedule() { 2575 if ( ! current_user_can( 'manage_options' ) ) { 2576 wp_send_json_error( [ 'message' => __( 'Permission denied.', 'smart-bulk-content-remover' ) ] ); 2577 } 2578 2579 check_ajax_referer( 'abdfw_page_schedule', 'nonce' ); 2580 2581 $enabled = ! empty( $_POST['enabled'] ); 2582 $frequency = sanitize_key( $_POST['frequency'] ?? 'daily' ); 2583 if ( ! in_array( $frequency, [ 'daily', 'weekly', 'monthly' ], true ) ) { 2584 $frequency = 'daily'; 2585 } 2586 2587 $time = sanitize_text_field( $_POST['time'] ?? '02:00' ); 2588 if ( ! preg_match( '/^\d{2}:\d{2}$/', $time ) ) { 2589 $time = '02:00'; 2590 } 2591 2592 $status = sanitize_key( $_POST['status'] ?? '' ); 2593 if ( ! in_array( $status, [ 'publish', 'draft', 'pending', 'trash', '' ], true ) ) { 2594 $status = ''; 2595 } 2596 2597 $author = absint( $_POST['author'] ?? 0 ); 2598 $from = sanitize_text_field( $_POST['from'] ?? '' ); 2599 $to = sanitize_text_field( $_POST['to'] ?? '' ); 2600 $search = sanitize_text_field( $_POST['search'] ?? '' ); 2601 $permanent = ! empty( $_POST['permanent'] ); 2602 2603 $settings = [ 2604 'enabled' => $enabled ? 1 : 0, 2605 'frequency' => $frequency, 2606 'time' => $time, 2607 'status' => $status, 2608 'author' => $author, 2609 'from' => $from, 2610 'to' => $to, 2611 'search' => $search, 2612 'permanent' => $permanent ? 1 : 0, 2613 ]; 2614 2615 update_option( 'abdfw_page_cleanup_schedule', $settings ); 2616 $this->abdfw_reschedule_page_cleanup( $settings ); 2617 2618 $next_run = wp_next_scheduled( 'abdfw_run_scheduled_page_cleanup' ); 2619 $next_run_str = $next_run ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $next_run ) : ''; 2620 2621 wp_send_json_success( [ 2622 'message' => __( 'Schedule saved.', 'smart-bulk-content-remover' ), 2623 'next_run' => $next_run_str, 2624 ] ); 2625 } 2626 2627 /** 2628 * Schedule or clear cron event. 2629 */ 2630 private function abdfw_reschedule_page_cleanup( $settings ) { 2631 wp_clear_scheduled_hook( 'abdfw_run_scheduled_page_cleanup' ); 2632 2633 if ( empty( $settings['enabled'] ) ) { 2634 return; 2635 } 2636 2637 $timestamp = $this->abdfw_get_next_run_timestamp( $settings['time'] ?? '02:00' ); 2638 $recurrence = $settings['frequency'] ?? 'daily'; 2639 wp_schedule_event( $timestamp, $recurrence, 'abdfw_run_scheduled_page_cleanup' ); 2640 } 2641 2642 /** 2643 * Compute next run timestamp from time-of-day. 2644 */ 2645 private function abdfw_get_next_run_timestamp( $time ) { 2646 $timezone = wp_timezone(); 2647 $now = new DateTime( 'now', $timezone ); 2648 $run = DateTime::createFromFormat( 'H:i', $time, $timezone ); 2649 2650 if ( ! $run ) { 2651 $run = clone $now; 2652 $run->setTime( 2, 0 ); 2653 } 2654 2655 $run->setDate( (int) $now->format( 'Y' ), (int) $now->format( 'm' ), (int) $now->format( 'd' ) ); 2656 2657 if ( $run->getTimestamp() <= $now->getTimestamp() ) { 2658 $run->modify( '+1 day' ); 2659 } 2660 2661 return $run->getTimestamp(); 2662 } 2663 2664 /** 2665 * Cron: run scheduled page cleanup. 2666 */ 2667 public function abdfw_run_scheduled_page_cleanup() { 2668 $settings = get_option( 'abdfw_page_cleanup_schedule', [] ); 2669 if ( empty( $settings['enabled'] ) ) { 2670 return; 2671 } 2672 2673 $args = [ 2674 'post_type' => 'page', 2675 'posts_per_page' => -1, 2676 's' => sanitize_text_field( $settings['search'] ?? '' ), 2677 'post_status' => ! empty( $settings['status'] ) ? sanitize_key( $settings['status'] ) : [ 'publish', 'draft', 'pending', 'trash' ], 2678 'fields' => 'ids', 2679 ]; 2680 2681 $author = absint( $settings['author'] ?? 0 ); 2682 if ( $author ) { 2683 $args['author'] = $author; 2684 } 2685 2686 $date_query = []; 2687 if ( ! empty( $settings['from'] ) ) { 2688 $date_query['after'] = sanitize_text_field( $settings['from'] ); 2689 } 2690 if ( ! empty( $settings['to'] ) ) { 2691 $date_query['before'] = sanitize_text_field( $settings['to'] ); 2692 } 2693 if ( $date_query ) { 2694 $args['date_query'] = [ array_merge( $date_query, [ 'inclusive' => true ] ) ]; 2695 } 2696 2697 $pages = get_posts( $args ); 2698 if ( empty( $pages ) ) { 2699 return; 2700 } 2701 2702 $permanent = ! empty( $settings['permanent'] ); 2703 foreach ( $pages as $id ) { 2704 if ( $permanent ) { 2705 wp_delete_post( $id, true ); 2706 } else { 2707 wp_trash_post( $id ); 2708 } 2709 } 2710 } 2421 2711 2422 2712 -
smart-bulk-content-remover/trunk/readme.txt
r3443451 r3450846 5 5 Requires at least: 4.7 6 6 Tested up to: 6.9 7 Stable tag: 1. 07 Stable tag: 1.1 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 146 146 147 147 == Changelog == 148 = 1.1 = 149 * Added new feature Schedule Automatic Cleanup for pages 148 150 149 151 = 1.0 = -
smart-bulk-content-remover/trunk/smart-bulk-content-remover.php
r3387224 r3450846 3 3 Plugin Name: Smart Bulk Delete & Content Cleaner for WordPress 4 4 Description: Smartly remove posts, pages, custom types, media and comments in bulk. Save time, declutter your site and streamline content management. 5 Version: 1. 05 Version: 1.1 6 6 Author: Kirtikumar Solanki 7 7 Text Domain: smart-bulk-content-remover … … 13 13 if ( ! defined( 'ABSPATH' ) ) { die(); } 14 14 15 if ( ! defined( 'ABDFW_VERSION' ) ) { define('ABDFW_VERSION', '1. 0'); }15 if ( ! defined( 'ABDFW_VERSION' ) ) { define('ABDFW_VERSION', '1.1'); } 16 16 17 17 if ( ! defined( 'ABDFW_PLUGIN_PATH' ) ) { define('ABDFW_PLUGIN_PATH', plugin_dir_path( __FILE__ )); } … … 30 30 function abdfw_deactivate() { 31 31 // Deactivation code here, like cleaning up options or temporary data 32 if ( function_exists( 'wp_clear_scheduled_hook' ) ) { 33 wp_clear_scheduled_hook( 'abdfw_run_scheduled_page_cleanup' ); 34 } 32 35 } 33 36 register_deactivation_hook(__FILE__, 'abdfw_deactivate');
Note: See TracChangeset
for help on using the changeset viewer.