Menu Search
Jump to the content X X
SmashingConf London Avatar

We use ad-blockers as well, you know. We gotta keep those servers running though. Did you know that we publish useful books and run friendly conferences — crafted for pros like yourself? E.g. our upcoming SmashingConf London, dedicated to all things web performance.

Schedule Events Using WordPress Cron

I don’t know about you, but I wake up every morning with at least 10 emails that I didn’t have when I went to sleep. While most people probably know that these emails aren’t being sent manually by some sleep-deprived, coffee-fuelled intern, many people don’t understand the ins and outs of the systems that automate tasks such as sending email.

WordPress Cron1
(Image: Don Schuetze2)

That’s where cron and WordPress Cron come into play. But they can be used for far more than filling inboxes to the brim. Before we dive into the specifics of both, here is a quick breakdown of the topics we’ll cover below:

  • What is cron and how does WordPress fit into it?
  • Introducing WordPress Cron
  • Limitations of WordPress Cron (and solutions to fix ’em)
  • What tasks is WordPress Cron used for?
  • How does WordPress execute scheduled tasks?
  • How to schedule tasks through WordPress Cron
  • Tips for developing with WordPress Cron
  • Popular plugins that use WordPress Cron

Still interested? Let’s get to it.

What Is Cron And How Does WordPress Fit Into It? Link

Cron is a system originally built for UNIX that enables users to execute commands, programs and other actions at specified times. As Wikipedia so eloquently puts it, “Cron is a time-based job scheduler.”

Further Reading on SmashingMag: Link

Basically, what that means is you can schedule an action to take place at a specific time, without having to manually execute code at that time. But how does this relate to your website — particularly, your WordPress website? Setting up your WordPress website to use the UNIX cron system built into your server’s operating system is possible; however, it can be difficult for two main reasons:

  1. Your host might not permit you to set up cron for security reasons.
  2. Different servers might require cron to be set up in different ways, which would require familiarity with a wide variety of systems.

If the WordPress team couldn’t rely on using each server’s cron, then how did they schedule tasks to be performed? They built WordPress Cron.

Introducing WordPress Cron Link

WordPress Cron is what many people refer to as a “pseudo-cron system.” The difference is in how UNIX cron and WordPress Cron take action. A typical UNIX cron system runs in this order:

  1. A time tied to an action occurs.
  2. Cron runs the action tied to that time.

With WordPress Cron, it works a little differently:

  1. A visitor comes to any page on your WordPress website.
  2. WordPress Cron checks each cron event to see whether the scheduled time has passed.
  3. If the scheduled time for that event has passed, then WordPress Cron executes any actions tied to that event.

Limitations Of WordPress Cron (And Solutions To Fix ’Em) Link

You may be wondering, “What happens if no one visits my website at all? Does WordPress Cron not run?” The biggest limitation of WordPress Cron stems from its inability to run without visitors. This leads to a few potential issues.

WordPress Cron Is Imprecise (Zero Visits = Zero Cron Runs) Link

If you’ve scheduled an email to be sent at 2:00 pm on Monday, then the email likely wouldn’t be sent precisely at that time, unless your website received a visit at exactly 2:00 pm. Instead, the email would be sent at the time of the first visit after 2:00 pm.

In most cases, this has little impact. But what if the email was a reminder for an event the next day, Tuesday? If the next visitor came on Tuesday night, then the email would likely serve no benefit, and could possibly confuse visitors.

So, consider the impact of no visits. If a website gets no traffic at all, then WordPress Cron will never run.

The solution is to create a more precise cron system.

If your website requires the timing to be exact, you could follow one of two methods. You could set up your server’s cron to hit wp-cron.php at a regular interval by following the instructions outlined in Harish Chouhan’s article on Wptuts+7. If this seems overly complicated, you could use a tool such as Pingdom8 to trigger an HTTP request directly to wp-cron.php.

Running Heavy Processes Could Slow Down Your Website Link

Similar to running any heavy process on page load, WordPress Cron could slow down your website significantly for the visitor who triggers a heavy process tied to a scheduled event.

The solution is to keep WordPress Cron actions simple.

Especially if you run actions frequently, keep the actions tied to scheduled cron events as simple as possible. Every extra ounce of complexity will hinder the performance for your end users.

What Tasks Is WordPress Cron Used For? Link

We’ve covered what WordPress Cron is and what its limitations are. Now it’s time to discuss what it’s actually used for. WordPress Cron can be employed to schedule two types of hooks:

  • those to execute at a regular, repeating interval;
  • those to execute only once at a fixed time.

Examples of Tasks Scheduled at a Regular, Repeating Interval Link

WordPress’ core and a number of plugins use WordPress Cron to execute the following tasks at regular, repeating intervals:

  • backing up the website,
  • checking the WordPress version to ensure it’s up to date,
  • checking for updates to plugins and themes,
  • optimizing the database to improve performance.

Examples of Tasks Scheduled to Run Only Once at a Fixed Time Link

Single events that occur only once are used for actions such as:

  • publishing a blog post at a specific time,
  • sending an email at a specific time.

How Does WordPress Execute Scheduled Tasks? Link

Before jumping into how to schedule your own events, it might be helpful to understand how WordPress Cron operates. WordPress Cron runs using two files:

  • /wp-includes/cron.php
    This file contains the entire WordPress Cron API and the functions you’ll need to schedule events.
  • /wp-cron.php
    This file actually executes WordPress Cron and calls the hooks attached to the scheduled events. This file is loaded through the spawn_cron()9 function in cron.php.

We’ve got the files now, but what happens when a WordPress page loads? We’ll walk through the process here together (but it’s worth having a solid understanding of hooks and filters10 before going through it):

  1. A visitor requests a page on your website.
  2. In /wp-includes/default-filters.php, WordPress hooks the wp_cron() function to the init action.
  3. When the init action occurs in /wp-settings.php, wp_cron() runs.
  4. The wp_cron() function ensures that WordPress Cron is not disabled and that the earliest scheduled cron event has passed its execution time.
  5. If it has passed its execution time, then spawn_cron() runs and first checks whether we’re already carrying out cron and, if so, doesn’t run it again.
    if ( defined('DOING_CRON') || isset($_GET['doing_wp_cron']) )
  6. Starting on line 247 of cron.php, spawn_cron() loads wp-cron.php through the HTTP request. (Using wp_remote_post() to load wp-cron.php doesn’t prevent the remainder of the page from loading for the visitor.)
    $cron_request = apply_filters( 'cron_request', array(
      'url' => site_url( 'wp-cron.php?doing_wp_cron=' . $doing_wp_cron ),
      'key' => $doing_wp_cron,
      'args' => array( 'timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters( 'https_local_ssl_verify', true ) )
    ) );
    wp_remote_post( $cron_request['url'], $cron_request['args'] );
  7. The wp-cron.php file loads and loops through all of the scheduled cron events, doing the following:
    • Line 85
      If the event is on a recurring schedule, then WordPress runs wp_reschedule_event()11 to schedule the next occurrence of this event.
    • Line 90
      WordPress unschedules the current event, using wp_unschedule_event()1912, so that it doesn’t run again in the future.
    • Line 92
      WordPress runs all of the functions tied to the hook provided in the cron event, including all of the actions that were scheduled to run at this second or prior to this second, using do_action_ref_array()13.
    foreach ( $crons as $timestamp => $cronhooks ) {
      if ( $timestamp > $gmt_time )
      foreach ( $cronhooks as $hook => $keys ) {
        foreach ( $keys as $k => $v ) {
          $schedule = $v['schedule'];
          if ( $schedule != false ) {
            $new_args = array($timestamp, $schedule, $hook, $v['args']);
            call_user_func_array('wp_reschedule_event', $new_args);
          wp_unschedule_event( $timestamp, $hook, $v['args'] );
          do_action_ref_array( $hook, $v['args'] );
          // If the hook ran too long and another cron process stole the lock, quit.
          if ( _get_cron_lock() != $doing_wp_cron )

As is the case with a lot of the WordPress source code, the process is organized in a way that makes it fairly easy to follow. I encourage you to look at the code yourself in both cron.php and wp-cron.php to learn more.

How To Schedule Tasks Through WordPress Cron? Link

If you’ve made it this far, then we can finally turn our attention to how to use WordPress Cron in our own plugins.

Create Recurring Events in WordPress Cron Link

Creating an event that repeats on a fixed schedule is done using wp_schedule_event( $timestamp, $recurrence, $hook, $args )14, in which the following four parameters are used:

  • $timestamp (required: integer)
    This is the time when you want the event to occur. This must be in a UNIX timestamp and must be in GMT. If you’re using local time, then convert it to GMT first or else the event won’t fire at the correct time.
  • $recurrence (required: string)
    This is how often the event should occur. The default options are hourly, twicedaily or daily. You can also add your own options, which we’ll touch on shortly.
  • $hook (required: string)
    This is the name of the action hook you’d like to execute. The advantage of calling an action hook instead of a function directly is that you can tie multiple functions to one hook using add_action()15.
  • $args (optional: array)
    These are any arguments you want to pass to the hooked function or functions. This could be a post ID, a backup schedule ID, a user ID or any other information you’ll use in your functions.

Let’s say we built a plugin that backs up the WordPress database once a day. Here’s what the code would look like if we were to schedule the backup with WordPress Cron:

//On plugin activation schedule our daily database backup 
register_activation_hook( __FILE__, 'wi_create_daily_backup_schedule' );
function wi_create_daily_backup_schedule(){
  //Use wp_next_scheduled to check if the event is already scheduled
  $timestamp = wp_next_scheduled( 'wi_create_daily_backup' );

  //If $timestamp == false schedule daily backups since it hasn't been done previously
  if( $timestamp == false ){
    //Schedule the event for right now, then to repeat daily using the hook 'wi_create_daily_backup'
    wp_schedule_event( time(), 'daily', 'wi_create_daily_backup' );

//Hook our function , wi_create_backup(), into the action wi_create_daily_backup
add_action( 'wi_create_daily_backup', 'wi_create_backup' );
function wi_create_backup(){
  //Run code to create backup.

To start, we hook wi_create_daily_backup_schedule() to register_activation_hook() so that our cron backup event will be added immediately when the plugin is activated. In wi_create_daily_backup_schedule(), we do two things:

  1. We use wp_next_scheduled()16 to check whether our cron event has already been created. And wp_next_scheduled() will either return a timestamp of the next scheduled event for a hook (wi_create_daily_backup) or return false, telling us that our cron event is not scheduled.
  2. If $timestamp == false, then we schedule our cron event for daily backups. We schedule the first backup to happen immediately by using the PHP function time(), and then we pass the daily recurrence schedule and our wi_create_daily_backup hook.

After creating the scheduled event, all that’s left to do is tie our backup function to the wi_create_backup action. We use add_action( 'wi_create_daily_backup', 'wi_create_backup' ) to hook our function. Then, we write our wi_create_backup() function to generate a backup of the website.

Adding a New WordPress Cron Schedule Link

As I mentioned when discussing recurring events, the default options for recurring schedules are hourly, twicedaily and daily. But what if, instead of running our backup daily, we wanted to run it weekly? WordPress makes a weekly schedule easy with the cron_schedules filter. To make the schedule weekly, you’d write the following code in your plugin:

add_filter( 'cron_schedules', 'wi_add_weekly_schedule' ); 
function wi_add_weekly_schedule( $schedules ) {
  $schedules['weekly'] = array(
    'interval' => 7 * 24 * 60 * 60, //7 days * 24 hours * 60 minutes * 60 seconds
    'display' => __( 'Once Weekly', 'my-plugin-domain' )
  You could add another schedule by creating an additional array element
  $schedules['biweekly'] = array(
    'interval' => 7 * 24 * 60 * 60 * 2
    'display' => __( 'Every Other Week', 'my-plugin-domain' )

  return $schedules;

The $schedules array is passed into our function and enables us to add the weekly key with the desired schedule. For the interval key, we must include the number of seconds we’d like between the times this cron event runs. To run once weekly, we calculate 7 days × 24 hours × 60 minutes × 60 seconds to give us the total number of seconds in a week. Then, we create the display name, “Once Weekly,” in case others need to read a description of our schedule.

Don’t forget to localize your description using __()17, so that it can be translated later. If you’re interested in adding more than one schedule, simply create a new array key within $schedules, such as $schedules[‘biweekly’], and add the interval and description. To complete our function, we return the $schedules array, including our new schedule.

Looking at the previous example of our backup schedule, if we wanted it to run weekly, we’d simply take this:

wp_schedule_event( time(), 'daily', 'wi_create_daily_backup' );

And we’d change it to this, using the new weekly schedule we created:

wp_schedule_event( time(), 'weekly', 'wi_create_daily_backup' );

Now, our backup will run once a week.

Removing Scheduled Cron Events Link

Returning to our backup plugin example, what we’ve done so far does have one problem. We haven’t removed our scheduled backup event upon deactivation of the plugin. This won’t actually cause an error when the event executes daily, but it will force cron to run, possibly slowing down the website ever so slightly. Removing our scheduled event is easy.

register_deactivation_hook( __FILE__, 'wi_remove_daily_backup_schedule' );
function wi_remove_daily_backup_schedule(){
  wp_clear_scheduled_hook( 'wi_create_daily_backup' );

Very much like we did on activation, we hook a function, wi_remove_daily_backup_schedule(), to the deactivation of our plugin. We pass the event hook wi_create_daily_backup to wp_clear_scheduled_hook()18, and then the schedule will be removed from WordPress Cron.

It’s worth noting that wp_clear_scheduled_hook() will remove all events associated with that hook. If you want to remove only one event, then use wp_unschedule_event()1912 instead; this function requires that you pass in the timestamp of the event you wish to remove.

Create a Single Event in WordPress Cron Link

Creating a single event to occur at a specified time is sometimes required. To create a single event in WordPress Cron, we must use wp_schedule_single_event( $timestamp, $hook, $args )20. The parameters here are exactly the same as wp_schedule_event(), except that they don’t include the $recurrence parameter, thus allowing the event to occur only once.

Let’s say we want to send a reminder email for a volunteer activity that will happen in the future. You can use this code directly inside a function run when the post about the volunteer activity is saved in WordPress’ admin section.

//Convert start time from local time to GMT since WP Cron sends based on GMT
$start_time_gmt = strtotime( get_gmt_from_date( date( 'Y-m-d H:i:s', $start_time ) ) . ' GMT' );

//Set reminder time for three days before event start time
$time_prior_event = 3 * 24 * 60 * 60; //3 days * 24 hours * 60 minutes * 60 seconds
$reminder_time = $start_time_gmt - $time_prior_event;

//Remove existing cron event for this post if one exists
//We pass $post_id because cron event arguments are required to remove the scheduled event
wp_clear_scheduled_hook( 'wi_send_reminder_email', array( $post_id ) );

//Schedule the reminder
wp_schedule_single_event( $reminder_time, 'wi_send_reminder_email', array( $post_id ) );

In this code, a number of important steps are happening. First, if the time of the volunteer activity is stored in a variable in local time, then we have to convert it to GMT, because WordPress Cron is not run using local time. Once converted to the variable $start_time_gmt, we set $reminder_time to the volunteer activity’s start time minus the number of seconds prior to the event that we wish to send the email.

We then remove any scheduled events for this hook and post to avoid scheduling our event multiple times when the post is saved. Remember that you must pass an array, including the same arguments that you used to create the scheduled event, in order to remove it. In this case, we’re passing the post’s ID. This makes sense, after all. You want to remove the scheduled email reminder not for every volunteer activity, only for the one that the user is saving.

Once we’ve created the reminder time and cleared any previously scheduled events, we create the new event using wp_schedule_single_event(), with the timestamp $reminder_time. We also pass in the $post_id for this particular post so that we can include custom information in our email, such as the post’s title, the time of the activity, the description of the activity and any other information.

To actually send the email when the cron event occurs, we hook the function that we want to execute when the event fires to wi_send_reminder_email.

//Hook our function, wi_send_event_reminder_email(), into the action wi_send_reminder_email
add_action( 'wi_send_reminder_email', 'wi_send_event_reminder_email' );
function wi_send_event_reminder_email( $post_id ){
  //Run code to send reminder email, customizing based on the post id

Tips For Developing With WordPress Cron Link

When you code with WordPress Cron, a couple of tools in particular could really help your development process.

WP Crontrol Link

WP Crontrol21 is a WordPress plugin that helps you develop using the WordPress Cron API. It displays all scheduled cron events, enables you to edit, run or delete cron events using a GUI and also enables you to see all available cron schedules.

The admin interface of WP Crontrol.

I highly recommend WP Crontrol if you plan to use the WordPress Cron API in a plugin.

IDE Debugger Link

If you develop plugins using an integrated development environment (IDE) instead of a basic text editor, then a debugger can be a hugely helpful resource for reviewing the array of cron events and creating new events. If you’re not already using an IDE, two of the most popular are Eclipse22 and NetBeans23, but plenty more are out there to choose from.

The WordPress Cron API is used often in popular plugins across the WordPress platform. To give you a feel for its use, I’ll cover how two rather popular plugins employ the API.

Akismet Link

Akismet24 is the leading spam-prevention tool for WordPress. At the time of writing, it’s been downloaded over 14 million times.


Akismet uses the WordPress Cron API for a number of purposes, including:

  • Rechecking in the future whether a comment is spam in the event that Akismet’s servers are unreachable during a check;
  • Rechecking an Akismet API key if the plugin is unable to verify at that moment due to an unreachable server;
  • Deleting old spam comments on a regular basis;

To delete old spam comments, Akismet creates a daily event and deletes comments over a certain age every day.

if ( function_exists('wp_next_scheduled') && function_exists('wp_schedule_event') ) {
  // WP 2.1+: delete old comments daily
  if ( !wp_next_scheduled('akismet_scheduled_delete') )
    wp_schedule_event(time(), 'daily', 'akismet_scheduled_delete');

Broken Link Checker25 is a WordPress plugin that checks your entire website for broken links. It uses WordPress Cron for a number of regular activities, including:

  • Checking new links hourly to ensure they’re not broken,
  • Emailing notifications about broken links on the website,
  • Completing database maintenance every two months,
  • Updating news about the plugin every day,

Broken Link Checker creates each of these schedules through one function, setup_cron_events().

* Install or uninstall the plugin's Cron events based on current settings.
* @uses wsBrokenLinkChecker::$conf Uses $conf->options to determine if events need to be (un)installed.  
* @return void
function setup_cron_events(){
  //Link monitor
  if ( $this->conf->options['run_via_cron'] ){
    if (!wp_next_scheduled('blc_cron_check_links')) {
      wp_schedule_event( time(), 'hourly', 'blc_cron_check_links' );
  } else {

  //Email notifications about broken links
  if ( $this->conf->options['send_email_notifications'] || $this->conf->options['send_authors_email_notifications'] ){
    if ( !wp_next_scheduled('blc_cron_email_notifications') ){
      wp_schedule_event(time(), $this->conf->options['notification_schedule'], 'blc_cron_email_notifications');
  } else {

  //Run database maintenance every two weeks or so
  if ( !wp_next_scheduled('blc_cron_database_maintenance') ){
    wp_schedule_event(time(), 'bimonthly', 'blc_cron_database_maintenance');

  //Check for news notices related to this plugin
  if ( !wp_next_scheduled('blc_cron_check_news') ){
    wp_schedule_event(time(), 'daily', 'blc_cron_check_news');

Conclusion Link

By now, you’re probably croned out, but I’m glad you stuck with me. You should now have a solid understanding of what WordPress Cron is, how it works and how you can use it to automate different features and functionality in your plugin.

If you have experience with WordPress Cron or have just started playing around, I’d love to hear from you in the comments. What issues have you run into? What are you using it for? Any tips for speeding up development? Do you know of any plugins that use the WordPress Cron API in an innovative way?

(al ea)

Footnotes Link

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25

↑ Back to top Tweet itShare on Facebook

Jonathan Goldford is a partner at Wired Impact, a web design company that builds websites for nonprofits. Jonathan spends the majority of his time focused on web development and is passionate about encouraging nonprofits to use the web as a tool to impact the community. Jonathan has written articles on using web technologies for publications such as Mashable, Business Insider and American Express OPEN Forum.

  1. 1

    Brendon Boshell

    October 16, 2013 3:13 am

    Worth noting that WP Cron is unreliable on some hosts, because of the way it operates. Some restrictive hosts do not allow external URL calls and so the `wp_remote_post` call in the core will fail for some users.

    In my plugin Thank Me Later, I have had to write code to detect when WP Cron isn’t working correctly and revert to a “legacy mode” of executing the code while the page loads (which blocks the load). You can see the code I have used here, in the is_legacy_mode function:

    • 2

      Jonathan Goldford

      October 16, 2013 9:29 am

      Thanks for adding the note about unreliable hosts and for providing code to help folks resolve the issue.

  2. 3

    You can also run real cron jobs with some adjustments:

  3. 5

    For performance concern, WordPress users can disable the WP Cron System by adding

    define(‘DISABLE_WP_CRON’, true);

    to your wp-config.php file, and use server cron or external cron service (like

    I wrote a WordPress plugin which is being reviewed by WP team now. It can help users configure a cron job directly in WP’s backend system via EasyCron’s API. Will post the link of the plugin here when it passes the review.

  4. 7

    Small hint for developers, there will see all crons in the system. The debug helper plugin Debug Objects get output all crons and his values.

  5. 8

    Is there no WordPress equivalent to Drupal’s Ultimate Cron and Background Processes so that the cron tasks can run in parallel, in the background, and not affect users visiting your site?

    • 9

      Jonathan Goldford

      October 16, 2013 9:33 am

      @Brian, it’s my understanding that WordPress uses wp_remote_post() so the cron tasks will run in the background and not cause the rest of the page to halt loading. So, I think you’re covered there.

  6. 10

    Good to know :)

  7. 11

    Russell Heimlich

    October 17, 2013 5:37 pm

    If you’re running a multisite set-up and want to run WP-Cron from an external cron job you can use a simple script like Pascal Gill’s multi-cron script to run all of the sites cron tasks at a similiar time.

  8. 12

    Keith Pickett

    October 30, 2013 6:05 am

    The old-school UNIX user in me says you could set up a local cron job via command line or through something like cPanel, if available, to run a “wget ” to get past the no site visit issue. As a matter of fact, that is how I was planning to get past a situation that I’m dealing with right now before running across this post. Thanks for the info.
    Note: my post got filtered originally.. there should be a domain argument to wget example above.

    Edit #2: My post is irrelevant after clicking through some of the links above. Nevermind. I learned something about wp-cron.php… hanging my head in shame.

  9. 13

    This is a great article. I did find one thing that is slightly off though, and I would like to explain why.

    Under the heading ‘Running Heavy Processes Could Slow Down Your Website’, you seem to imply that when a wp-cron runs, it impacts the current page load. This is pretty much not what happens. Yes, if the cron is a high performance task, then it could impact overall server performance, which would in turn impact the current page load, but there is no direct impact on the current page load.

    Look back in /wp-includes/cron.php @ line 250. You will see this list of arguments, which is passed to the WP_Http class.

    ‘args’ => array( ‘timeout’ => 0.01, ‘blocking’ => false, ‘sslverify’ => apply_filters( ‘https_local_ssl_verify’, true ) )

    A close inspection of these arguments indicates that not only is the request set to immediately timeout (0.01 seconds), but it is also set to continue to process, on it’s own, without affecting this page load at all (‘blocking’ => false).

    Basically what happens is this.

    1.) it checks for jobs who’s schedule has passed
    2.) if any jobs are found, it cycles through them, and spawns a completely separate http request, which handles the task, independently of the current page load
    3.) after initiating this spawned request, it immediately continues to load this page

    The direct performance hit to this page request is so insignificant and small, that it is literally unnoticed, unless of course there is an abundance of tasks that are past schedule. Because of this methodology, your cron tasks can actually be simple or complex, so long as they don’t have overall server performance impacts, such as memory usage or intensive number crunching. Both of the typical server impacts (memory and processor cycles) can be easily limited with throttling, built into your code.

    Hopefully, your own research, based on my comment, yields the same results, and gets added to this great, informative article.


  10. 14

    Jens Ahrengot Boddum

    March 12, 2014 4:11 am

    Just wasted a couple of hours of my life because I overlooked this tiny notice in the codex:

    “For some reason there seems to be a problem on some systems where the hook must not contain underscores or uppercase characters.”

    Changing my scheduled action from schedule_this_action to schedule-this-action magically made things work.

    Just out of curiosity, does anyone know why the underscores break wp_cron on some servers?

  11. 15

    Hi Jonathan,
    You look to be very easy with WordPress CronJob.
    I use cron_schedules in a personal plugin to send email to users with wp_mail(). I have the plugin wp-better-email.
    Problem : WordPress return unknown function wp_mail. If i add require_once(‘wp-includes/pluggable.php’), it’s ok but wp-better-email is not used.
    Is there a way to wait loading WordPress dependency before starting schedule ?

  12. 16

    My website is loading slow on mobile devices which is causing a higher bounce rate. When I deactivated the plug in that is causing this I get an error message:

    Warning Illegal offset in wp_includes cron.php file on line 180 …..

    This is what is on line 180 – “if ( isset( $cron[ $hook ][ $key ] ) ) {“

    Any suggestions??

  13. 17

    Hello Jonathan,

    Thank you for the article, it helped me a lot to get started with WP cron.

    TIP: if you’re creating or deleting cron jobs that use arguments, make sure to explicitly convert them to the same type (string, int and so on).

    Explanation: I’ve had to implement the following task – email a user 2 weeks after they have activated their account and haven’t submitted a post for review – to remind them to write for a site. I added a cron job on user activation hook `gform_activate_user` (gravity forms in this case) with user ID as a parameter. I then deleted the cron job on `pending_post` hook when a post has been submitted for review and had author ID. However, although the user/author ID in logs was showing as the same number – one function returned int and another string. So, the cron wasn’t getting deleted because given different types the cron hash was different. So look out for that.

    NOTE: Also, `print_r` doesn’t display the type of a variable (hence to me the two IDs where exactly the same). However, var_dump does.

    I hope it helps some one :)


↑ Back to top