| @@ -2,11 +2,11 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Charitable Events |
| 4 | 4 | * |
| 5 | 5 | * @package Charitable/Classes/Charitable_Cron |
| 6 | - * @version 1.1.0 | |
| 6 | + * @version 1.8.9.1 | |
| 7 | 7 | * @author David Bisset |
| 8 | - * @copyright Copyright (c) 2022, WP Charitable LLC | |
| 8 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 9 | 9 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | // Exit if accessed directly. |
| @@ -53,8 +53,9 @@ | ||
| 53 | 53 | * @since 1.1.0 |
| 54 | 54 | */ |
| 55 | 55 | private function __construct() { |
| 56 | 56 | add_action( 'charitable_daily_scheduled_events', array( $this, 'check_expired_campaigns' ) ); |
| 57 | + add_action( 'charitable_daily_scheduled_events', array( $this, 'cleanup_old_logs' ) ); | |
| 57 | 58 | } |
| 58 | 59 | |
| 59 | 60 | /** |
| 60 | 61 | * Schedule Charitable event hooks. |
| @@ -76,13 +77,14 @@ | ||
| 76 | 77 | /** |
| 77 | 78 | * Check for expired campaigns. |
| 78 | 79 | * |
| 79 | 80 | * @since 1.1.0 |
| 81 | + * @version 1.8.9.1 | |
| 80 | 82 | * |
| 81 | 83 | * @return void |
| 82 | 84 | */ |
| 83 | 85 | public function check_expired_campaigns() { |
| 84 | - $yesterday = date( 'Y-m-d H:i:s', strtotime( '-24 hours' ) ); | |
| 86 | + $yesterday = date( 'Y-m-d H:i:s', strtotime( '-24 hours' ) ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date | |
| 85 | 87 | |
| 86 | 88 | $args = array( |
| 87 | 89 | 'fields' => 'ids', |
| 88 | 90 | 'post_type' => Charitable::CAMPAIGN_POST_TYPE, |
| @@ -90,9 +92,9 @@ | ||
| 90 | 92 | 'post_status' => 'publish', |
| 91 | 93 | 'meta_query' => array( |
| 92 | 94 | array( |
| 93 | 95 | 'key' => '_campaign_end_date', |
| 94 | - 'value' => array( $yesterday, date( 'Y-m-d H:i:s' ) ), | |
| 96 | + 'value' => array( $yesterday, date( 'Y-m-d H:i:s' ) ), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date | |
| 95 | 97 | 'compare' => 'BETWEEN', |
| 96 | 98 | 'type' => 'datetime' |
| 97 | 99 | ) |
| 98 | 100 | ) |
| @@ -105,8 +107,38 @@ | ||
| 105 | 107 | } |
| 106 | 108 | |
| 107 | 109 | foreach ( $campaigns as $campaign_id ) { |
| 108 | 110 | do_action( 'charitable_campaign_end', $campaign_id ); |
| 111 | + } | |
| 112 | + } | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * Cleanup old log records based on retention setting. | |
| 116 | + * | |
| 117 | + * @since 1.8.11 | |
| 118 | + * | |
| 119 | + * @return void | |
| 120 | + */ | |
| 121 | + public function cleanup_old_logs() { | |
| 122 | + if ( ! class_exists( 'Charitable_Log' ) ) { | |
| 123 | + return; | |
| 124 | + } | |
| 125 | + | |
| 126 | + $days = Charitable_Log::get_retention_days(); | |
| 127 | + | |
| 128 | + /** | |
| 129 | + * Filter the number of days to retain log records. | |
| 130 | + * | |
| 131 | + * @since 1.8.11 | |
| 132 | + * | |
| 133 | + * @param int $days Number of days to retain. | |
| 134 | + */ | |
| 135 | + $days = apply_filters( 'charitable_logs_retention_days', $days ); | |
| 136 | + | |
| 137 | + $db = Charitable_Log::get_instance()->get_db(); | |
| 138 | + | |
| 139 | + if ( $db->table_exists() ) { | |
| 140 | + $db->delete_older_than( $days ); | |
| 109 | 141 | } |
| 110 | 142 | } |
| 111 | 143 | } |
| 112 | 144 | |