PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.2.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.2.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / includes / classes / log-cleanup.php

log-cleanup.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.2.0, at includes/classes/log-cleanup.php

45 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace StoreEngine\Classes;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 class LogCleanup {
9
10 /**
11 * main cleanup logic
12 */
13 public static function execute_cleanup() {
14 global $wpdb;
15 $table = $wpdb->prefix . 'storeengine_logs';
16
17 // admin setting
18 $settings = get_option( 'storeengine_log_settings',[
19 'retention_days' => 30,
20 'cleanup_statuses' => [ 'success' ]
21 ] );
22
23 $days = (int) ( $settings['retention_days'] ?? 30 );
24 $statuses = $settings['cleanup_statuses'] ?? [ 'success' ];
25
26 if ( $days <= 0 || empty( $statuses ) || ! is_array( $statuses ) ) {
27 return;
28 }
29
30 // date calculation — UTC, matching the UTC timestamps the logger writes.
31 $threshold_date = gmdate( 'Y-m-d H:i:s', time() - ( $days * DAY_IN_SECONDS ) );
32
33 // SQL query — table via %i identifier placeholder, all values via prepare().
34 $placeholders = implode( ',', array_fill( 0, count( $statuses ), '%s' ) );
35
36 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- Dynamic IN() list on a custom StoreEngine log table: %i identifier + every value (%s) bound through prepare(); $placeholders holds only literal "%s" tokens. The static analyzer cannot count the array_merge() replacement args.
37 $wpdb->query(
38 $wpdb->prepare(
39 "DELETE FROM %i WHERE date < %s AND status IN ($placeholders)",
40 array_merge( [ $table, $threshold_date ], $statuses )
41 )
42 );
43 // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
44 }
45 }