diff --git a/woocommerce-payments.php b/woocommerce-payments.php index 6fe181dcc78..d0aa3417fd1 100644 --- a/woocommerce-payments.php +++ b/woocommerce-payments.php @@ -29,6 +29,9 @@ * Initialize the Jetpack connection functionality. */ function wcpay_jetpack_init() { + if ( ! wcpay_check_old_jetpack_version() ) { + return; + } $jetpack_config = new Automattic\Jetpack\Config(); $jetpack_config->ensure( 'connection', @@ -52,4 +55,34 @@ function wcpay_init() { } // Make sure this is run *after* WooCommerce has a chance to initialize its packages (wc-admin, etc). That is run with priority 10. +// If you change the priority of this action, you'll need to change it in the wcpay_check_old_jetpack_version function too. add_action( 'plugins_loaded', 'wcpay_init', 11 ); + +/** + * Check if WCPay is installed alongside an old version of Jetpack (8.1 or earlier). Due to the autoloader code in those old + * versions, the Jetpack Config initialization code would just crash the site. + * TODO: Remove this when Jetpack 8.1 (Released on January 2020) is so old we don't think anyone will run into this problem anymore. + * + * @return bool True if the plugin can keep initializing itself, false otherwise. + */ +function wcpay_check_old_jetpack_version() { + if ( defined( 'JETPACK__VERSION' ) && version_compare( JETPACK__VERSION, '8.2', '<' ) ) { + add_filter( 'admin_notices', 'wcpay_show_old_jetpack_notice' ); + // Prevent the rest of the plugin from initializing. + remove_action( 'plugins_loaded', 'wcpay_init', 11 ); + return false; + } + return true; +} + +/** + * Display an error notice if the installed Jetpack version is too old to even start initializing the plugin. + */ +function wcpay_show_old_jetpack_notice() { + ?> +
+ +