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.
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.
4 Answers
codex wordpress: Function_Reference -> wp_schedule_event
pseudo-cron is good but the two issues it has is
- 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.
- 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 :-)
I think you're wrong about #2. WordPress generates an asynchronous curl() call to itself to fire the job, so there's no noticeable delay for visitors. If you want to workaround #1, you can setup a cron job to `wget example _ com _ wp-cron.php'.
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.
If you made it dependant on every attempted comment spam, you could have millisecond accuracy. :-)
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.
Wordpress Category Template Question
I am looking at using a custom template for a set of categories. Is it possible to use a category template (like category-4.php) on a parent category and have the children use that template as well? So based on the answer so far, is there a way to accomplish this? I want to add text and images to all categories within a parent category. 1 Answer From the documentation it does not appear to be possible without actually adding several category template files (unless you custom program it). I run Wordpress, and I have only seen it accomplished category by category. I have my Wordpress install and MediaWiki sharing the same login information. Unfortunately, users need to log into both separately, but at least they use the same credentials. What I would like to do is cause a successful login on the Wordpress blog to also cause a login for MediaWiki…
Wordpress MediaWiki Cookie Integration
I have my Wordpress install and MediaWiki sharing the same login information. Unfortunately, users need to log into both separately, but at least they use the same credentials. What I would like to do is cause a successful login on the Wordpress blog to also cause a login for MediaWiki (ideally both directions). There are two ways this could happen: Logging in causes a login on the other application (writes the cookie and creates the session in the DB) Accessing an application checks for the cookie of the other and then automatically logs in. Since the usernames are shared it seems like the latter should be pretty easy to do. Any…
In the latest version of WordPress, it gives you the opportunity to view a preview of what your site would look like using a different theme. You basically just click on the theme, it takes over the screen and you have a chance to activate or close it (and return to the previous screen, which is grayed out in the background). I have seen a similar technique used on a number of websites recently for display images as well. I'm wondering what technology/code they use to do this?…


