PluginProbe
Lasso Lite – Affiliate Link Manager & Product Displays / 114
Lasso Lite – Affiliate Link Manager & Product Displays v114
158 157 155 156 154 153 152 151 150 149 148 trunk 0.9.9 104 105 106 107 108 109 110 111 112 113 114 115 All 57 releases
simple-urls / classes / class-cron.php

class-cron.php in Lasso Lite – Affiliate Link Manager & Product Displays 114, at classes/class-cron.php

112 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Declare class Config
4 *
5 * @package Config
6 */
7
8 namespace LassoLite\Classes;
9
10 use LassoLite\Classes\Processes\Import_All;
11
12 /**
13 * Config
14 */
15 class Cron {
16
17 const CRONS = array(
18 'lasso_lite_tracking_support_status' => 'daily',
19 'lasso_lite_import_all' => 'lasso_lite_15_minutes',
20 );
21
22 /**
23 * Cron constructor.
24 */
25 public function __construct() {
26 add_filter( 'cron_schedules', array( $this, 'add_lasso_cron' ) );
27 add_action( 'lasso_lite_tracking_support_status', array( $this, 'lasso_lite_tracking_support_status' ) );
28 add_action( 'lasso_lite_import_all', array( $this, 'lasso_import_all' ) );
29
30 $this->lasso_create_schedule_hook();
31 }
32
33 /**
34 * Add a custom cron to WordPress
35 *
36 * @param array $schedules An array of non-default cron schedules. Default empty.
37 */
38 public function add_lasso_cron( $schedules ) {
39 $schedules['lasso_lite_15_minutes'] = array(
40 'interval' => 15 * MINUTE_IN_SECONDS, // ? 15 minutes in seconds
41 'display' => __( '15 minutes' ),
42 );
43
44 return $schedules;
45 }
46
47 /**
48 * Create hook for the new cron
49 */
50 public function lasso_create_schedule_hook() {
51 $crons = self::CRONS;
52 $events = array();
53 $crons_array = _get_cron_array();
54
55 if ( ! is_array( $crons_array ) ) {
56 return;
57 }
58
59 foreach ( $crons_array as $time => $cron ) {
60 foreach ( $cron as $hook => $dings ) {
61 if ( strpos( $hook, 'lasso_lite_' ) === false ) {
62 continue;
63 }
64
65 foreach ( $dings as $sig => $data ) {
66 $interval = $data['interval'] ?? HOUR_IN_SECONDS;
67
68 // ? get the cron that is less than the existing one
69 if ( isset( $events[ $hook ] ) && $interval >= $events[ $hook ]->interval ) {
70 continue;
71 }
72
73 $events[ $hook ] = (object) array(
74 'hook' => $hook,
75 'time' => $time, // ? UTC
76 'schedule' => $data['schedule'],
77 'interval' => $interval,
78 );
79
80 }
81 }
82 }
83
84 foreach ( $crons as $cron_name => $interval ) {
85 if ( ! wp_next_scheduled( $cron_name ) ) {
86 wp_schedule_event( time(), $interval, $cron_name );
87 }
88 }
89 }
90
91 /**
92 * Tracking support status
93 */
94 public function lasso_lite_tracking_support_status() {
95 $settings = Setting::get_settings();
96 if ( boolval( $settings[ Enum::SUPPORT_ENABLED ] ) ) {
97 Setting::save_support( false );
98 }
99 }
100
101 /**
102 * Import all
103 */
104 public function lasso_import_all() {
105 $allow_import_all = get_option( Import_All::OPTION, '0' );
106 if ( 1 === intval( $allow_import_all ) ) {
107 $lasso_import_all = new Import_All();
108 $lasso_import_all->import();
109 }
110 }
111 }
112