display-conditions
5 months ago
front
2 days ago
helpers
1 month ago
metas
3 months ago
multisite
5 months ago
palettes
3 years ago
provider
1 month ago
providers
2 days ago
templates
3 years ago
update
5 months ago
class-hustle-admin-page-abstract.php
1 month ago
class-hustle-auth-token.php
5 months ago
class-hustle-condition-factory.php
6 years ago
class-hustle-cross-sell.php
10 months ago
class-hustle-dashboard-admin.php
1 month ago
class-hustle-data.php
1 month ago
class-hustle-db.php
2 years ago
class-hustle-installer.php
4 years ago
class-hustle-meta.php
3 years ago
class-hustle-module-admin.php
1 month ago
class-hustle-module-collection.php
5 months ago
class-hustle-module-fields.php
3 months ago
class-hustle-module-page-abstract.php
1 month ago
class-hustle-module-validator.php
3 months ago
class-hustle-notifications.php
2 days ago
class-hustle-settings-admin.php
1 month ago
class-hustle-wp-dashboard-page.php
5 months ago
class-opt-in.php
2 days ago
hustle-background-conversion-log.php
3 months ago
hustle-deletion.php
3 months ago
hustle-embedded-admin.php
3 years ago
hustle-entries-admin.php
5 months ago
hustle-entry-model.php
1 month ago
hustle-general-data-protection.php
5 months ago
hustle-init.php
1 month ago
hustle-mail.php
5 months ago
hustle-migration.php
5 months ago
hustle-model.php
2 days ago
hustle-module-model.php
1 month ago
hustle-module-widget-legacy.php
5 months ago
hustle-module-widget.php
5 months ago
hustle-modules-common-admin-ajax.php
1 month ago
hustle-popup-admin.php
3 years ago
hustle-providers-admin.php
1 month ago
hustle-providers.php
5 months ago
hustle-settings-admin-ajax.php
1 month ago
hustle-settings-page.php
3 years ago
hustle-slidein-admin.php
3 years ago
hustle-sshare-admin.php
2 days ago
hustle-sshare-model.php
2 days ago
hustle-tracking-model.php
3 months ago
interface-hustle-auth-provider.php
5 months ago
opt-in-geo.php
5 months ago
opt-in-utils.php
2 days ago
opt-in-wpmudev-api.php
5 months ago
hustle-background-conversion-log.php
130 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Hustle Background Conversion Log |
| 4 | * |
| 5 | * @package Hustle |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; // Exit if accessed directly. |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Class Hustle_Background_Conversion_Log |
| 14 | * |
| 15 | * Handles background processing for conversion log tasks. |
| 16 | */ |
| 17 | class Hustle_Background_Conversion_Log { |
| 18 | |
| 19 | /** |
| 20 | * Instance of this class |
| 21 | * |
| 22 | * @var Hustle_Background_Conversion_Log |
| 23 | */ |
| 24 | private static $instance = null; |
| 25 | |
| 26 | /** |
| 27 | * Cron hook name |
| 28 | * |
| 29 | * @var string |
| 30 | */ |
| 31 | private $cron_hook = 'hustle_conversion_log_cron'; |
| 32 | |
| 33 | /** |
| 34 | * Cron interval name |
| 35 | * |
| 36 | * @var string |
| 37 | */ |
| 38 | private $cron_interval = 'hustle_every_minute'; |
| 39 | |
| 40 | /** |
| 41 | * Get the singleton instance |
| 42 | * |
| 43 | * @return Hustle_Background_Conversion_Log |
| 44 | */ |
| 45 | public static function get_instance() { |
| 46 | if ( is_null( self::$instance ) ) { |
| 47 | self::$instance = new self(); |
| 48 | } |
| 49 | return self::$instance; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Constructor |
| 54 | */ |
| 55 | private function __construct() { |
| 56 | add_action( $this->cron_hook, array( $this, 'process_task' ) ); |
| 57 | add_filter( 'cron_schedules', array( $this, 'add_cron_interval' ) ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Initialize the background task |
| 62 | */ |
| 63 | public function init() { |
| 64 | if ( ! wp_next_scheduled( $this->cron_hook ) ) { |
| 65 | wp_schedule_event( time(), $this->cron_interval, $this->cron_hook ); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Add custom cron interval (every 15 minutes) |
| 71 | * |
| 72 | * @param array $schedules Existing schedules. |
| 73 | * @return array Modified schedules. |
| 74 | */ |
| 75 | public function add_cron_interval( $schedules ) { |
| 76 | $schedules[ $this->cron_interval ] = array( |
| 77 | 'interval' => 900, // 900 seconds = 15 minutes |
| 78 | 'display' => esc_html__( 'Every Fifteen Minutes', 'hustle' ), |
| 79 | ); |
| 80 | return $schedules; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Process the background task |
| 85 | */ |
| 86 | public function process_task() { |
| 87 | self::save_conversion_logs(); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Save temporary conversion logs. |
| 92 | * |
| 93 | * @since 7.8.11 |
| 94 | */ |
| 95 | public static function save_conversion_logs() { |
| 96 | $temp_conversions = get_option( 'hustle_conversion_logs', array() ); |
| 97 | if ( ! empty( $temp_conversions ) ) { |
| 98 | foreach ( $temp_conversions as $conversion ) { |
| 99 | |
| 100 | $date = date_i18n( 'Y-m-d H:i:s', $conversion['time'] ); |
| 101 | Hustle_Tracking_Model::get_instance()->save_tracking( |
| 102 | $conversion['module_id'], |
| 103 | $conversion['action'], |
| 104 | $conversion['module_type'], |
| 105 | $conversion['post_id'], |
| 106 | $conversion['module_sub_type'], |
| 107 | $date, |
| 108 | $conversion['ip'] |
| 109 | ); |
| 110 | } |
| 111 | delete_option( 'hustle_conversion_logs' ); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Stop the scheduled task |
| 117 | */ |
| 118 | public function stop() { |
| 119 | $timestamp = wp_next_scheduled( $this->cron_hook ); |
| 120 | if ( $timestamp ) { |
| 121 | wp_unschedule_event( $timestamp, $this->cron_hook ); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Prevent cloning of the instance |
| 127 | */ |
| 128 | private function __clone() {} |
| 129 | } |
| 130 |