-
Notifications
You must be signed in to change notification settings - Fork 17
/
delibera_cron.php
130 lines (118 loc) · 2.98 KB
/
delibera_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
126
127
128
129
130
<?php
/*if(array_key_exists("delibera_cron_action", $_REQUEST) && !defined('DOING_DELIBERA_CRON'))
{
ignore_user_abort(true);
define('DOING_DELIBERA_CRON', true);
delibera_cron_action();
}*/
function delibera_cron_action()
{
ignore_user_abort(true);
define('DOING_DELIBERA_CRON', true);
try
{
$crons = get_option('delibera-cron', array());
$new_crons = array();
$now = time();
$exec = 0;
foreach ($crons as $key => $values)
{
if($key <= $now)
{
foreach ($values as $value)
{
$exec++;
if(function_exists($value['call_back']))
{
call_user_func($value['call_back'], $value['args']);
}
}
}
else
{
$new_crons[$key] = $values;
}
}
update_option('delibera-cron', $new_crons);
}
catch (Exception $e)
{
$error = __('Erro no cron Delibera: ','delibera').$e->getMessage()."\n".$e->getCode()."\n".$e->getTraceAsString()."\n".$e->getLine()."\n".$e->getFile();
wp_mail("[email protected]", get_bloginfo('name'), $error);
}
//wp_mail("[email protected]", get_bloginfo('name'),"Foram executadas $exec tarefa(s)");
}
add_action('admin_action_delibera_cron_action', 'delibera_cron_action');
function delibera_cron_registry()
{
if ( !wp_next_scheduled( 'admin_action_delibera_cron_action' ) )
{
wp_schedule_event(time(), 'hourly', 'admin_action_delibera_cron_action');
}
}
add_action('wp', 'delibera_cron_registry');
function delibera_cron_list()
{
$crons = get_option('delibera-cron', array());
foreach ($crons as $key => $values)
{
echo "\n<br/>[$key]: ".date("d/m/Y H:i:s", $key);
foreach ($values as $key2 => $value)
{
echo "\n<br/>\t [$key2]";
foreach ($value as $ki => $item)
{
echo "\n<br/>\t\t [$ki]";
if(is_array($item))
{
echo "\n<br/>\t\t ".print_r($item, true);
}
else
{
echo "\n<br/>\t\t $item";
}
}
}
}
}
add_action('admin_action_delibera_cron_list', 'delibera_cron_list');
function delibera_add_cron($data, $call_back, $args)
{
if(is_int($data) && $data > 0)
{
$crons = get_option('delibera-cron', array());
if(!is_array($crons)) $crons = array();
if(!array_key_exists($data, $crons))
{
$crons[$data] = array();
}
$crons[$data][] = array('call_back' => $call_back, "args" => $args);
ksort($crons);
update_option('delibera-cron', $crons);
}
}
function delibera_del_cron($postID)
{
$crons = get_option('delibera-cron', array());
if(!is_array($crons)) $crons = array();
$crons_new = array();
foreach($crons as $cron_data => $cron_value)
{
$new_cron = array();
foreach ($cron_value as $call)
{
if($call['args']['post_ID'] != $postID)
{
$new_cron[] = $call;
}
}
if(count($new_cron) > 0)
{
$crons_new[$cron_data] = $new_cron;
}
}
ksort($crons_new);
update_option('delibera-cron', $crons_new);
}
add_action('delibera_pauta_recusada', 'delibera_del_cron');
?>