Most people will never need such a thing in a WordPress site, but outside the boxes of blogging, where WordPress is a Swiss Army Knife, there are situations where you need to run a script or do something on a regular interval. Maybe it’s polling social media. Maybe it’s updating some information about your site. I’ve had my second need recently, so here is the 411 on it.

WARNING: This post has a lot of PHP code. If that makes you break out in shivers, go see a puppy.

My first need for this was when I recast the original ds106 Daily Create into its own wordpress based general theme. The big change was that people would submit their responses as tweets to a specific twitter account, and use hashtags with a certain base hashtag (#tdcXXX for the current DS106 Daily Create).

Okay, so I first figured out how to poll this information from Twitter via it’s API, and got a function to do all the stuff I needed it to (not critical to this post, but I have a bunch of posts about building the DS106 Daily Blank).

In the past I might have rigged up some PHP script and a unix cron job, but that’s alot to ask someone installing this as a theme. Fortunately, I did not need this, because as usual, WordPress has built in code for dealing with scheduled events.

While the example code gives you a sense of what is needed, it did not quite push me over the hump of understanding. More or less you set a “hook” which taps into the WordPress flow of logic to set up a scheduled event, and an “action” that this thing acts upon:

Unfortunately, I did not seem to include in my code comments where I got the code fragment I modified, but I bet a Canadian Loony not was from StackExchange. But this is the winning working code I used:

If I have my head wrapped around this, I am creating my very own WordPress action called dailyblank_hello_twitter. My script will create something, an event, with that name and that is run every hour. Once this is set up, it exists as a scheduled event in the site’s database, and its main purpose is to trigger that as an action every hour. For some reason, the example I found suggested that way of using $dt as a time value; I see other ways of doing it in other code examples, and thwy never work on my site. This one works.

But that alone does nothing, so I have to add an action association that tells WordPress what to do each time there is a dailyblank_hello_twitter actiobn– and that is to do whatever is in the function dailyblank_get_tweets (the full function is not needed here to explain the scheduling).

And that’s all you need. I do not think it actually sets an alarm clock and runs every hour; my guess is that all this stuff is triggered when someone visits your site (it might be you too) and WordPress checks itself for a missed timed event.

So that was the first time I needed a scheduled event (that was a bad pun).

The second one is related to the syndication method I use for setting up Connected Courses with the Feed WordPress plugin— and it probably is not a problem for a class sized aggregation hub.

But on ds106, where I cut my teeth on all this stuff, we have over 1300 subscribed feeds. And while I can use the dashboard, there is not exactly a way for people to know if they have already added their blog (and duplicates really gum up the works).

Well I do have a shortcode I use to generate subscribed blogs associated with a certain category (e.g. see the sidebar for or but nothing to show someone who is trying to signup if their blog is in the mix (or possibly, as in ds106, it have have been deactivated).

This was a shortcoming on the ds106 blog signup form. One late night in January 2016, I rolled up my sleeves and hacked a script that can generate a listing of all blogs we have in the ds106 syndication bus, whether they are active, and even a link to all posts syndicated from that blog.


The function I wrote for doing it is a bit gnarly call it ds106_update_feedlist()… I have to use the wordpress get_bookmarks() function (because Feed WordPress stores all its info as a WordPress link or bookmark), then it has to parse the results a few times to get all the information.

I thought it would be a lot of overhead to hit the database and process all this stuff each time the page above was accessed, so my idea was to create a function that would do all this work, but generate its output as a text file on the server. Then to view it, the calling page needed to spit out that file’s contents (I did this by making it a shortcode named [feedlist]).

Regardless, I had everything in place to do the big function, and generate a big wad of static content data in a file.

I decided to add something to the WordPress Admin dashboard to trigger the update- it’s not too hard to add your own stuff to the left side menus, in this case I added it as a submenu to the Tools menu:

tools ds106

This is done by adding an action to the admin menus, which is called each time you see a dashboard screen:

It took a lot of head banging to get this part right. Your function called by the admin_menu action must begin with register_. The stuff in add_submenu_page tells wordpress which menu it is part of (“tools.php” is the Tools menu), a title for the page that is generated (“Update Feeds List”), the name that appears on the menu (“Update FWP Feeds List”), the capability for which roles can access the page (any role that can “manage options” which means Administer roles only), the string that becomes part of the URL (the link on the menu becomes “…./wp-admin/tools.php?page=feedlist-update-page”) and what function generates the stuff on the Admin page (a callback function or in this case “ds106_feedlist_callback”).

All this does is add the menu to my dashboard. I need to write ds106_feedlist_callback to tell it what to put on that page.

Here is my function:

The page output sets up the basic wrappers for an admin page content, calls my custom function ds106_update_feedlist() to run the big ass function update, and the same function used for the shortcode ds106_feedlist() which merely echoes the static data file, and adds a time stamp on top.

Whew, this all works.

Except– to update the content, I have to manually visit the WordPress Admin dashbaord.

Enter a wordpress scheduled event. This turned out easy, since (a) I had the code above I used for the daily create, and (b) I have the function in place here that updates the static data file.

So now the public page updates itself, and provides a way for someone to check if their blog has been added to the ds106 syndication bus. It also shows which tags a feeds posts are connected to, e.g. what groups/courses their blog is connected to (I guess I should make those into links).

For admins, this is a quicker way to look for a subscribed blog than the Feed WordPress list in the dashboard, which with 1200 feeds, take a bit of churning to display.

But in this process I learned both how to connect my own custom function to a WordPress admin menu and how to schedule things that need to be run on a regular basis– not likely things too many people night need.

And I will grant any reader a Dedication Badge for wading through all this code. Click there.

Top / Featured Image: I did not search on “schedule” but “timer” hoping to get an image for a device. I hit my image on the first few results from a Google Image Search (limited to images licensed for reuse), and it’s even better when it’s from flickr cause (a) flickr is cool and (b) I can copy the attribution AND download the image from my very own attribution helper.

The image used is a flickr photo by numb3r shared under a Creative Commons (BY-SA) license

If this kind of stuff has value, please support me by tossing a one time PayPal kibble or monthly on Patreon
Become a patron at Patreon!
Profile Picture for CogDog The Blog
An early 90s builder of web stuff and blogging Alan Levine barks at on web storytelling (#ds106 #4life), photography, bending WordPress, and serendipity in the infinite internet river. He thinks it's weird to write about himself in the third person. And he is 100% into the Fediverse (or tells himself so) Tooting as


  1. Damn it. Read the post but didn’t read Pat’s comment until now. Really could have used wp-control last night. 🙂

    Always read the comments.

Leave a Reply

Your email address will not be published. Required fields are marked *