1+ <?php
2+ function wp_schedule_single_event ($ timestamp , $ hook ) {
3+ $ args = array_slice (func_get_args (), 2 );
4+ $ crons = get_option ('cron ' );
5+ $ crons [$ timestamp ][$ hook ] = array ('schedule ' => false , 'args ' => $ args );
6+ ksort ($ crons );
7+ update_option ('cron ' , $ crons );
8+ }
9+ function wp_schedule_new_event ($ timestamp , $ recurrence , $ hook ) {
10+ $ args = array_slice (func_get_args (), 3 );
11+ $ crons = get_option ('cron ' );
12+ $ schedules = wp_get_schedules ();
13+ if (!isset ($ schedules [$ recurrence ]))
14+ return false ;
15+ $ crons [$ timestamp ][$ hook ] = array ('schedule ' => $ recurrence , 'args ' => $ args , 'interval ' => $ schedules [$ recurrence ]['interval ' ]);
16+ ksort ($ crons );
17+ update_option ('cron ' , $ crons );
18+ }
19+
20+
21+ function wp_reschedule_event ($ timestamp , $ recurrence , $ hook ) {
22+ $ args = array_slice (func_get_args (), 3 );
23+ $ crons = get_option ('cron ' );
24+ $ schedules = wp_get_schedules ();
25+ $ interval = 0 ;
26+
27+ // First we try to get it from the schedule
28+ if ( 0 == $ interval )
29+ $ interval = $ schedules [$ recurrence ]['interval ' ];
30+ // Now we try to get it from the saved interval in case the schedule disappears
31+ if ( 0 == $ interval )
32+ $ interval = $ crons [$ timestamp ][$ hook ]['interval ' ];
33+ // Now we assume something is wrong and fail to schedule
34+ if ( 0 == $ interval )
35+ return false ;
36+
37+ while ($ timestamp < time () + 1 ) {
38+ $ timestamp += $ interval ;
39+ }
40+ wp_schedule_new_event ($ timestamp , $ recurrence , $ hook );
41+ }
42+
43+ function wp_unschedule_event ($ timestamp , $ hook ) {
44+ $ crons = get_option ('cron ' );
45+ unset($ crons [$ timestamp ][$ hook ]);
46+ if ( empty ($ crons [$ timestamp ]) )
47+ unset($ crons [$ timestamp ]);
48+ update_option ('cron ' , $ crons );
49+ }
50+
51+ function wp_clear_scheduled_hook ($ hook ) {
52+ while ($ timestamp = next_scheduled ($ hook ))
53+ wp_unschedule_event ($ timestamp , $ hook );
54+ }
55+
56+ function wp_next_scheduled ($ hook ) {
57+ $ crons = get_option ('cron ' );
58+ if ( empty ($ crons ) )
59+ return false ;
60+ foreach ($ crons as $ timestamp => $ cron ) {
61+ //if($timestamp <= time()) continue;
62+ if (isset ($ cron [$ hook ])) return $ timestamp ;
63+ }
64+ return false ;
65+ }
66+
67+ function spawn_cron () {
68+ if (array_shift (array_keys (get_option ('cron ' ))) > time ()) return ;
69+
70+ //Since execute pings had CGI problems, but I'd like to test this without this code first
71+ // It seems to be working on CGI here, please report if you have issues
72+ /* if ( substr(php_sapi_name(), 0, 3) == 'cgi' ) {
73+ echo '<iframe src="' . $cron_url . '"></iframe>';
74+ }*/
75+
76+ $ cron_url = get_settings ('siteurl ' ) . '/wp-cron.php ' ;
77+ $ parts = parse_url ($ cron_url );
78+
79+ $ argyle = @ fsockopen ($ parts ['host ' ], $ _SERVER ['SERVER_PORT ' ], $ errno , $ errstr , 0.01 );
80+ if ( $ argyle )
81+ fputs ($ argyle , "GET {$ parts ['path ' ]}?time= " . time () . '&check= '
82+ . md5 (DB_PASS . '187425 ' ) . " HTTP/1.0 \r\nHost: {$ _SERVER ['HTTP_HOST ' ]}\r\n\r\n" );
83+ }
84+
85+ function wp_cron () {
86+ $ crons = get_option ('cron ' );
87+ if (!is_array ($ crons ) || array_shift (array_keys ($ crons )) > time ())
88+ return ;
89+
90+ $ schedules = wp_get_schedules ();
91+ foreach ($ crons as $ timestamp => $ cronhooks ) {
92+ if ($ timestamp > time ()) break ;
93+ foreach ($ cronhooks as $ hook => $ args ) {
94+ if (isset ($ schedules [$ hook ]['callback ' ]) && !call_user_func ($ schedules [$ hook ]['callback ' ]))
95+ continue ;
96+ spawn_cron ();
97+ break 2 ;
98+ }
99+ }
100+ }
101+
102+ function wp_get_schedules () {
103+ $ schedules = array (
104+ 'hourly ' => array ('interval ' => 3600 , 'display ' => __ ('Once Hourly ' )),
105+ 'daily ' => array ('interval ' => 86400 , 'display ' => __ ('Once Daily ' )),
106+ );
107+ return array_merge (apply_filters ('cron_schedules ' , array ()), $ schedules );
108+ }
109+ ?>
0 commit comments