-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtootpress_cron.php
125 lines (97 loc) · 2.45 KB
/
tootpress_cron.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Cron
*
* @package TootPress
* @since 0.1
*/
// Security: Stops code execution if WordPress is not loaded
if (!defined('ABSPATH')) { exit; }
/**
* Creates the intervall for requesting new toots
*
* @since 0.1
*
* @param array Schedules
* @return array Schedules
*/
function tootpress_cron_schedule_newtoots ( $schedules ) {
$period=get_option('tootpress_cron_period');
$schedules['tootpress_schedule_newtoots'] = array(
'interval' => $period,
'display' => esc_html__( 'TootPress Custom Window' ),
);
return $schedules;
}
add_filter( 'cron_schedules', 'tootpress_cron_schedule_newtoots' );
/**
* Creates the intervall for requesting all toots
*
* @since 0.1
*
* @param array Schedules
* @return array Schedules
*/
function tootpress_cron_schedule_alltoots ( $schedules ) {
$schedules['tootpress_schedule_alltoots'] = array(
'interval' => 300,
'display' => esc_html__( 'TootPress Every5Minutes' ),
);
return $schedules;
}
add_filter( 'cron_schedules', 'tootpress_cron_schedule_alltoots' );
/**
* Defines the cron for requesting new toots
*
* @since 0.1
*
* @return bool
*/
function tootpress_cron_process_newtoots() {
// Is Steady Load active?
$cron_status=get_option('tootpress_cron_newtoots_status');
if($cron_status) {
if(tootpress_ready_to_retrieve_toots_from_mastodon_api()){
// Request API
tootpress_copy_toots_from_mastodon("forwards");
return true;
} else {
return false;
}
}
}
add_action( 'tootpress_cron_hook_newtoots', 'tootpress_cron_process_newtoots' );
/**
* Defines the cron for requesting all toots
*
* @since 0.1
*
* @return bool
*/
function tootpress_cron_process_alltoots() {
// Is Complete History Load active?
$cron_status=get_option('tootpress_cron_alltoots_status');
if($cron_status) {
if(tootpress_ready_to_retrieve_toots_from_mastodon_api()){
// Request API
tootpress_copy_toots_from_mastodon("backwards");
return true;
} else {
return false;
}
}
}
add_action( 'tootpress_cron_hook_alltoots', 'tootpress_cron_process_alltoots' );
/**
* Schedules the crons
*
* @since 0.1
*
*/
if( !wp_next_scheduled( 'tootpress_cron_hook_newtoots' ) ) {
wp_schedule_event( time(), 'tootpress_schedule_newtoots', 'tootpress_cron_hook_newtoots' );
}
if( !wp_next_scheduled( 'tootpress_cron_hook_alltoots' ) ) {
wp_schedule_event( time(), 'tootpress_schedule_alltoots', 'tootpress_cron_hook_alltoots' );
}
?>