Best Practices for Deconflicting Different Versions of Action Scheduler

tl;dr

When two or more plugins are running side-by-side, but include different versions of Action Scheduler, there is an increased risk of conflict in some cases.

The details

Numerous plugins include the Action Scheduler library and, in the vast majority of cases, they will successfully run side-by-side without issue—even if each includes a different version of the library. For example, we might have:

  • Plugin A including Action Scheduler 3.2.0 (or earlier)
  • Plugin B including Action Scheduler 3.2.1 (or higher)

In cases like this, Action Scheduler will try to ensure that the latest version (in this example that would be 3.2.1 or higher, as included by Plugin B) is the one that will be loaded.

However, an issue with the version resolution logic in Action Scheduler 3.2.0 and earlier means that, in some cases, that earlier version will unexpectedly be loaded instead of the latest one. Specifically, this can happen if Plugin A loads its older version of Action Scheduler early on during the plugins_loaded action, as described here, before Plugin B can do so.

This is potentially problematic because Plugin B may expect all the functionality included in its version of Action Scheduler to be available, but in fact an earlier version—the one included by Plugin A—has loaded. If Plugin B then tries to call a library function that does not yet exist in that earlier version of Action Scheduler, then a fatal error will result.

How can I tell if this affects me?

If you are a developer and are responsible for a plugin that includes or uses Action Scheduler—and especially if you are using recently added functionality such as the new as_has_scheduled_action() function—then please follow the advice in this advisory, otherwise your users may experience difficulties.

If you manage any sites where one or more of your plugins include Action Scheduler, and if you notice that one of them includes version 3.2.0 or earlier, you may wish to reach out to the relevant support teams for assistance before applying any plugin updates.

What action should I take?

If you are a developer and if your plugin includes or uses Action Scheduler:

  • Wherever possible, ensure your plugin ships the latest version of Action Scheduler. If it currently ships version 3.2.0 or earlier then we strongly recommend you release an update, bumping your bundled version of Action Scheduler to 3.2.1 or higher.
  • If you already include Action Scheduler 3.2.1 or higher, then you should still consider reviewing any code that interacts with Action Scheduler and apply defensive coding practices as appropriate. This might include:
    • Testing to see if the expected version of the library (or higher) is available.
    • Making use of function_exists() to ensure the Action Scheduler function you wish to use has actually been defined (a specific function you may wish to test for, if you use it, is the recently added as_has_scheduled_action()).

If you are the operator of a WordPress website and you believe some of your plugins may be bundled with Action Scheduler, then there are a few different ways to find out which version of Action Scheduler is actually being loaded and which plugin is responsible for loading it:

  • If you are also using WooCommerce, simply visit the WooCommerce → Status → System Status page and look for the Action Scheduler package entry in the WordPress Environment area: this will tell you the version number along with a filepath that can be used to determine which plugin it is bundled with.
  • Or, if you do not use WooCommerce, you can visit the Tools → Scheduled Actions screen and use the Help pulldown at the top of the screen to check which version of Action Scheduler has loaded.
  • If neither of those options exist, then it is most likely that Action Scheduler is not in active use on your site.

If you discover the active version is 3.2.0 or earlier, you may wish to reach out to the support team of that plugin before applying any further plugin updates.

Note that if WooCommerce is not installed then figuring out which plugin Action Scheduler is bundled with may be harder, but if you are in doubt you can use a custom snippet plugin and add some code like this:

add_action( 'admin_notices', function() {
	$result = '';
	
	try {
		$action_scheduler = new ReflectionClass( 'ActionScheduler' );
		$result = esc_html( $action_scheduler->getFileName() );
	}
	catch ( Exception $e ) {
		$result = 'Could not identify the plugin or theme which is loading Action Scheduler (or it may not be loaded).';
	}
	
	print "<div class='notice notice-warning'><p><strong>Action Scheduler</strong> &rarr; {$result}</p></div>";
} );

This will add a small admin notice with a filepath which may look something like:

/srv/public_html/mysite.com/wp-content/plugins/super-widget-blocks/vendor/woocommerce/action-scheduler/...
                                               -------------------

In the above example, this would be an indication that Super Widget Blocks is the relevant plugin—you can then ask the authors for assistance.

We hope this advisory was useful, but please do not hesitate to get in touch via the normal channels if we can clarify anything or provide further information.


Leave a Reply

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