-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpul-missed-schedule.php
53 lines (49 loc) · 1.64 KB
/
simpul-missed-schedule.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
<?php
/*
Plugin Name: Simpul Missed Schedule by Esotech
Version: 1.0
Author: Esotech - Alexander Conroy - Geilt
Author URI: http://www.geilt.com
Description: Checks for Missed Schedules Posts and Posts them.
Requires at least: 3.5.1
Tested up to: 3.5.1
License: MIT
*/
$simpulMissedSchedule = new SimpulMissedSchedule;
class SimpulMissedSchedule {
const SIMPUL_MS_DELAY = 1;
const SIMPUL_MS_OPTION = 'simpul_missed_schedule';
public function __construct(){
add_action('init', array($this, 'init'));
register_deactivation_hook(__FILE__, array($this, 'cleanup'));
}
private function init() {
global $wpdb;
$last = get_option(SELF::SIMPUL_MS_OPTION, false);
if (($last !== false) && ($last > ( current_time('timestamp') - (SELF::SIMPUL_MS_DELAY * 60)))) return;
update_option(SELF::SIMPUL_MS_OPTION, current_time('timestamp'));
$query = $wpdb->prepare(
"SELECT
ID
FROM ' . $wpdb->prefix . 'posts
WHERE
post_status = 'future'
AND ( post_date <= %s OR post_date_gmt <= %s )
LIMIT 10",
current_time('mysql'),
current_time('mysql', 1)
);
$scheduledIDs = $wpdb->get_col( $query );
if (!count( $scheduledIDs )) return;
foreach( $scheduledIDs as $scheduledID ):
if ( !$scheduledID ):
continue;
else:
wp_publish_post( $scheduledID );
endif;
endforeach;
}
private function cleanup(){
delete_option(SELF::SIMPUL_MS_OPTION);
}
}