tags:

views:

485

answers:

4

I'm trying to write a Wordpress plug-in that automatically posts a blog post at a certain time of day. For example, read a bunch of RSS feeds and post a daily digest of all new entries.

There are plug-ins that do something similar to what I want, but many of them rely on a cron job for the automated scheduling. I'll do that if I have to, but I was hoping there was a better way. Getting a typical Wordpress user to add a cron job isn't exactly friendly.

Is there a good way to schedule a task that runs from a Wordpress plug-in? It doesn't have to run at exactly the right time.

A: 

vBulletin uses a sort of Pseudo-Cron system, that basically checks a schedule on every page access, and fires any processes that are due then.

It's been a while since I worked with Wordpress, but I think something like this should work if it runs on each page view.

mabwi
If you made it dependant on every attempted comment spam, you could have millisecond accuracy. :-)
Paul Tomblin
A: 

I think the best way to do this is with a pseudo-cron. I have seen it on several occasions, and although not exact in the timing, it should do what you need it to do. Since in Wordpress the index.php is the first thing always hit based upon the settings in the .htaccess, create a file called pseudo-cron.php, dump it into the root directory, and then require it once from the index. Whenever someone hits the site, it will run, and you can use it to initiate a script, and check if another daily digest needs to be generated depending upon the time of the day, and when the previous digest ran.

hal10001
+2  A: 

pseudo-cron is good but the two issues it has is

1, It requires someone to "hit" the blog to execute. Low volume sites will potentially have wide ranging execution times so don't be two specific about the time.

2, The processing happens before the page loads. So if teh execution time happens and you have lots of "cron" entries you potentially upset visitors by giving them a sub standard experience.

Just my 2 cents :-)

Stephen Baugh