Implement log cleanup cron job (woocommerce_cleanup_logs)

This commit is contained in:
Mike Jolley 2018-05-01 16:37:14 +01:00
parent d40b704cba
commit e8f3bac6c8
3 changed files with 18 additions and 1 deletions

View File

@ -352,6 +352,7 @@ class WC_Install {
wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' );
wp_clear_scheduled_hook( 'woocommerce_cleanup_sessions' );
wp_clear_scheduled_hook( 'woocommerce_cleanup_orders' );
wp_clear_scheduled_hook( 'woocommerce_cleanup_logs' );
wp_clear_scheduled_hook( 'woocommerce_geoip_updater' );
wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' );
@ -366,7 +367,8 @@ class WC_Install {
}
wp_schedule_event( time(), 'daily', 'woocommerce_cleanup_orders' );
wp_schedule_event( time(), 'twicedaily', 'woocommerce_cleanup_sessions' );
wp_schedule_event( time() + ( 3 * HOUR_IN_SECONDS ), 'daily', 'woocommerce_cleanup_logs' );
wp_schedule_event( time() + ( 6 * HOUR_IN_SECONDS ), 'twicedaily', 'woocommerce_cleanup_sessions' );
wp_schedule_event( strtotime( 'first tuesday of next month' ), 'monthly', 'woocommerce_geoip_updater' );
wp_schedule_event( time() + 10, apply_filters( 'woocommerce_tracker_event_recurrence', 'daily' ), 'woocommerce_tracker_send_event' );

View File

@ -1660,6 +1660,20 @@ function wc_get_logger() {
return $logger;
}
/**
* Trigger logging cleanup using the logging class.
*
* @since 3.4.0
*/
function wc_cleanup_logs() {
$logger = wc_get_logger();
if ( is_callable( array( $logger, 'clear_expired_logs' ) ) ) {
$logger->clear_expired_logs();
}
}
add_action( 'woocommerce_cleanup_logs', 'wc_cleanup_logs' );
/**
* Prints human-readable information about a variable.
*

View File

@ -16,6 +16,7 @@ wp_clear_scheduled_hook( 'woocommerce_scheduled_sales' );
wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' );
wp_clear_scheduled_hook( 'woocommerce_cleanup_sessions' );
wp_clear_scheduled_hook( 'woocommerce_cleanup_orders' );
wp_clear_scheduled_hook( 'woocommerce_cleanup_logs' );
wp_clear_scheduled_hook( 'woocommerce_geoip_updater' );
wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' );