| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* @todo Show opt-in popup after plugin activation. |
| 8 |
* @since 3.06.04 |
| 9 |
*/ |
| 10 |
class FrmUsageController { |
| 11 |
|
| 12 |
/** |
| 13 |
* Randomize the first send to prevent our servers from crashing. |
| 14 |
* |
| 15 |
* @since 3.06.04 |
| 16 |
*/ |
| 17 |
public static function schedule_send() { |
| 18 |
if ( wp_next_scheduled( 'formidable_send_usage' ) ) { |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
$tracking = array( |
| 23 |
'day' => rand( 0, 6 ) * DAY_IN_SECONDS, |
| 24 |
'hour' => rand( 0, 23 ) * HOUR_IN_SECONDS, |
| 25 |
'minute' => rand( 0, 59 ) * MINUTE_IN_SECONDS, |
| 26 |
'second' => rand( 0, 59 ), |
| 27 |
); |
| 28 |
|
| 29 |
$offset = array_sum( $tracking ); |
| 30 |
$init_send = strtotime( 'next sunday' ) + $offset; |
| 31 |
|
| 32 |
wp_schedule_event( $init_send, 'weekly', 'formidable_send_usage' ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Adds once weekly to the existing schedules. |
| 37 |
* |
| 38 |
* @since 3.06.04 |
| 39 |
*/ |
| 40 |
public static function add_schedules( $schedules = array() ) { |
| 41 |
$schedules['weekly'] = array( |
| 42 |
'interval' => DAY_IN_SECONDS * 7, |
| 43 |
'display' => __( 'Once Weekly', 'formidable' ), |
| 44 |
); |
| 45 |
return $schedules; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* @since 3.06.04 |
| 50 |
*/ |
| 51 |
public static function send_snapshot() { |
| 52 |
$usage = new FrmUsage(); |
| 53 |
$usage->send_snapshot(); |
| 54 |
} |
| 55 |
} |
| 56 |
|