Changeset 424635
- Timestamp:
- 08/17/2011 05:12:27 AM (14 years ago)
- Location:
- wp-cron-control/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (3 diffs)
-
wp-cron-control.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-cron-control/trunk/readme.txt
r418191 r424635 1 1 === WP-Cron Control === 2 2 Contributors: tott, automattic 3 Tags: wp-cron, cron, cron jobs 3 Tags: wp-cron, cron, cron jobs, post missed schedule, scheduled posts 4 4 Donate link: http://hitchhackerguide.com 5 5 Tested up to: 3.1.2 … … 10 10 == Description == 11 11 12 This plugin allows you to take control over the execution of cron jobs. It's mainly useful for sites that either don't get enough comments to ensure a frequent execution of wp-cron or for sites where the execution of cron via regular methods can cause race conditions resulting in multiple execution of wp-cron at the same time. 12 This plugin allows you to take control over the execution of cron jobs. It's mainly useful for sites that either don't get enough comments to ensure a frequent execution of wp-cron or for sites where the execution of cron via regular methods can cause race conditions resulting in multiple execution of wp-cron at the same time. It can also help when you run into posts that missed their schedule. 13 13 14 14 This plugin implements a secret parameter and ensures that cron jobs are only executed when this parameter is existing. … … 31 31 == ChangeLog == 32 32 33 = Version 0.3 = 34 35 * Added option to enable extra check that would search for missing jobs for scheduled posts and add them if necessary. 36 33 37 = Version 0.2 = 34 38 -
wp-cron-control/trunk/wp-cron-control.php
r418191 r424635 5 5 Description: get control over wp-cron execution. 6 6 Author: Thorsten Ott, Automattic 7 Version: 0. 27 Version: 0.3 8 8 Author URI: http://hitchhackerguide.com 9 9 */ … … 37 37 $this->default_settings = (array) apply_filters( $this->plugin_prefix . 'default_settings', array( 38 38 'enable' => 1, 39 'enable_scheduled_post_validation' => 0, 39 40 'secret_string' => md5( __FILE__ . $blog_id ), 40 41 ) ); … … 43 44 'enable' => array( 'label' => 'Enable ' . $this->plugin_name, 'desc' => 'Enable this plugin and allow requests to wp-cron.php only with the appended secret parameter.', 'type' => 'yesno' ), 44 45 'secret_string' => array( 'label' => 'Secret string', 'desc' => 'The secret parameter that needs to be appended to wp-cron.php requests.', 'type' => 'text' ), 46 'enable_scheduled_post_validation' => array( 'label' => 'Enable scheduled post validation', 'desc' => 'In some rare cases it can happen that even when running wp-cron via a scheduled system cron job posts miss their schedule. This feature makes sure that there is a scheduled event for each scheduled post.', 'type' => 'yesno' ), 45 47 ) ); 46 48 … … 204 206 205 207 set_transient( 'doing_cron', $local_time ); 208 209 if ( 1 == self::instance()->settings['enable_scheduled_post_validation'] ) { 210 $this->validate_scheduled_posts(); 211 } 206 212 return true; 207 213 } … … 217 223 define( 'DISABLE_WP_CRON', true ); 218 224 return false; 225 } 226 227 public function validate_scheduled_posts() { 228 global $wpdb; 229 $sql = $wpdb->prepare( "SELECT ID, post_date_gmt FROM $wpdb->posts WHERE post_status = 'future' " ); 230 $results = $wpdb->get_results( $sql ); 231 $return = true; 232 233 if ( empty( $results ) ) 234 return true; 235 236 foreach ( $results as $r ) { 237 238 $gmt_time = strtotime( $r->post_date_gmt . ' GMT' ); 239 $timestamp = wp_next_scheduled( 'publish_future_post', array( (int) $r->ID ) ); 240 241 if ( $timestamp === false ) { 242 wp_schedule_single_event( $gmt_time, 'publish_future_post', array( (int) $r->ID ) ); 243 $return = false; 244 } else { 245 //update timestamp to adjust for daylights savings change, when necessary 246 if ( $timestamp != $gmt_time ) { 247 wp_clear_scheduled_hook( 'publish_future_post', array( (int) $r->ID ) ); 248 wp_schedule_single_event( $gmt_time, 'publish_future_post', array( (int) $r->ID ) ); 249 250 $new_date = date( 'Y-m-d H:i:s', $gmt_time ); 251 $sql_u = $wpdb->prepare( "UPDATE $wpdb->posts SET post_date_gmt=%s WHERE ID=%d", $new_date, $r->ID ); 252 $wpdb->query( $sql_u ); 253 $return = false; 254 } 255 } 256 } 257 258 return $return; 219 259 } 220 260 }
Note: See TracChangeset
for help on using the changeset viewer.