New in AffiliateWP 2.7: Changes to the core bootstrap and loading order

Starting with the upcoming 2.7 Beta 1 release, there are some important changes coming to the AffiliateWP bootstrap that all third-party add-on developers should know about.

Affiliate_WP will no longer be available prior to the plugins_loaded hook

Before AffiliateWP 2.7:

  • The main Affiliate_WP class was instantiated and most of the core files were loaded whenever the main plugin file first was loaded by WordPress
  • Most of the core APIs were being initialized on the plugins_loaded hook

AffiliateWP 2.7 or newer:

  • Affiliate_WP will be instantiated on plugins_loaded the same time its core files are loaded the same time its APIs are initialized

This change to the loading order is primarily intended to help improve the customer experience when using AffiliateWP with add-ons. Bootstrapping all of core on the plugins_loaded hook will allow add-ons to more reliably predict when AffiliateWP is available and act accordingly.

For add-ons that are currently trying to access AffiliateWP before plugins_loaded has fired, we recommend checking out the section of the post below covering the newly-introduced affwp_plugins_loaded hook.

Mainly though, if you’re firing off your bootstrap in your main plugin file, hooking it instead to this new hook for AffiliateWP 2.7+ is going to be you best option. The AffiliateWP version can be retrieved from the affwp_version option key.

A new affwp_plugins_loaded hook for add-ons

Because of the changes to the loading order, we felt the best way to promote compatibility with first- and third-party add-ons in the long term was by introducing a new affwp_plugins_loaded hook.

The new hook fires immediately after the AffiliateWP bootstrap has executed and is going to be the best way for add-ons to reliably predict that AffiliateWP has loaded.

We’ll be moving all of our official add-ons to use this new hook in short order.

To make the change in a third-party add-on, we suggest using the following snippet for maximum backward compatibility:

$affwp_version = get_option( 'affwp_version' );
 
if ( version_compare( $affwp_version, '2.7', '<' ) ) {
    add_action( 'plugins_loaded', 'your_bootstrap', 100 );
} else {
    add_action( 'affwp_plugins_loaded', 'your_bootstrap', 100 );
}

New minimum requirements

A central part of the motivation for moving the bootstrap out of the main plugin file and onto plugins_loaded was to make room for a new approach we’re taking to handle minimum requirements checking.

AffiliateWP 2.7 bumps the PHP minimum to 5.6 and the WordPress minimum to 5.0.

Our Minimum Requirements Roadmap directs us to start enforcing minimum requirements on a rolling schedule, and having this requirements checking class in place will make future adjustments a snap.

Partial activation mode

Finally, with the requirements checking baked into AffiliateWP, so comes support for what we’re calling partial activation. If the stated minimum requirements aren’t met, AffiliateWP (and any affected add-ons) will revert into partial activation mode.

Ultimately, partial activation has the effect of loading the plugin but preventing the bootstrap from running and potentially causing issues on customers’ sites.

Partial activation is not a perfect solution by any means, but it’s a big improvement over the straight up site breakage that might otherwise happen.

Coming up in AffiliateWP

That’s about it in terms of changes to the bootstrap in AffiliateWP 2.7 and beyond. Coming up, we can’t wait to share details on all of the other developer goodies and improvements coming in the 2.7 release.

Please subscribe to the blog feed if you haven’t and maybe opt-in to beta releases in AffiliateWP on your testing environment in the mean time. AffiliateWP 2.7 Beta 1 will be shipping to a WordPress near you very soon!

Leave a Reply

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