Fixing Wordpress Scheduled Posts

Wordpress has a neat little feature that allows you to write a post and then schedule it to display at some point in the future. This seems good, but it invariably doesn't work on some server platforms and rather than publishing a post Wordpress just counts the amount of time passed since it was supposed to go live. The basic solution to this is to go into the post and click on publish, which can be a pain if you are taking a couple of days off from blogging and want to leave it running.

The problem lies with the functions that convert a scheduled post into a live post which are kept in the file wp-cron.php in the root Wordpress directory. For some reason the Wordpress developers decided to call the scheduling functions using the fsockopen() function available in PHP. This essentially opens a browser session to the wp-cron.php file, just as you would if you browsed to the location using your web browser.

What seems to be happening is that the browser request is getting blocked due to a permissions problem, which leads to Wordpress simply not running the cron functions. However, even when the wp-cron.php file is loaded manually using your web browser there are two if statements at the top of the file that tend to stop things from working.

After much tinkering and research I have found the following solution. Note that I am currently using Wordpress version 2.6 and so it can't be assumed that this works for future versions, if indeed this problem still exists.

Open the file wp-cron.php (situated in the main Wordpress folder) and comment out lines 6 to 10.

Change this:

<?php
ignore_user_abort(true);
define('DOING_CRON', TRUE);
require_once('./wp-config.php');
 
if ( $_GET['check'] != wp_hash('187425') )
  exit;
 
if ( get_option('doing_cron') > time() )
  exit;
 
update_option('doing_cron', time() + 30);

To this:

<?php
ignore_user_abort(true);
define('DOING_CRON', TRUE);
require_once('./wp-config.php');
 
/*if ( $_GET['check'] != wp_hash('187425') )
  exit;
 
if ( get_option('doing_cron') > time() )
  exit;*/
 
update_option('doing_cron', time() + 30);

Next, open the index.php file in your Wordpress folder and change it from this:

<?php
/* Short and sweet */
define('WP_USE_THEMES', true);
require('./wp-blog-header.php');
?>

To this:

<?php
/* Short and sweet */
define('WP_USE_THEMES', true);
require('./wp-cron.php');
require('./wp-blog-header.php');
?>

This adds a the wp-cron.php file every time the blog is looked at and because we have removed the if statements at the top of the file the cron functions are always run.

This might cause a small issue on very busy blogs as it can make your pages load slightly slower than normal. So if you have a lot of traffic you might want to just save your posts in draft form and publish them manually each morning.

Of course to run the cron functions on Wordpress (modified or not) you need to actually look at the front page of the blog. If you are refreshing the administration section then nothing will happen.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
9 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.