PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / trunk
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce vtrunk
2.15.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 All 62 releases
hurrytimer / includes / IP_Log_Manager.php

IP_Log_Manager.php in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce trunk, at includes/IP_Log_Manager.php

54 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Hurrytimer;
3
4 class IP_Log_Manager {
5
6 const CLEANUP_ACTION = 'hurrytimer_evergreen_daily_cleanup';
7 private $table;
8
9 public function __construct() {
10 global $wpdb;
11 $this->table = "{$wpdb->prefix}hurrytimer_evergreen";
12
13 if ( $this->has_entries() ) {
14 add_action( 'wp', array( $this, 'schedule_daily_cleanup' ) );
15 }else{
16 $this->unschedule_cleanup();
17 }
18 }
19
20 public function schedule_daily_cleanup() {
21 if ( ! wp_next_scheduled( self::CLEANUP_ACTION ) ) {
22 wp_schedule_event( time(), 'daily', self::CLEANUP_ACTION );
23 }
24 }
25
26 public function cleanup_ip_logs() {
27 global $wpdb;
28
29 $current_time = current_time( 'mysql' );
30
31 $query = $wpdb->prepare(
32 "DELETE FROM {$this->table} WHERE destroy_at < %s",
33 $current_time
34 );
35
36 // Run the query
37 $wpdb->query( $query );
38 }
39
40 public function has_entries() {
41 global $wpdb;
42
43 $result = $wpdb->get_var( "SELECT COUNT(*) FROM {$this->table}");
44
45 return ( $result > 0 );
46 }
47
48 public function unschedule_cleanup() {
49 wp_clear_scheduled_hook( self::CLEANUP_ACTION );
50 }
51
52 }
53
54