Running a scheduled task in a WordPress plug-in

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.

Read More

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.

Related posts

Leave a Reply

4 comments

  1. 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 🙂

  2. 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.

  3. 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.