diff --git a/features/plugins.php b/features/plugins.php index 70c29d6..957a3b2 100644 --- a/features/plugins.php +++ b/features/plugins.php @@ -27,6 +27,7 @@ function () { 'jetpack' => 'Jetpack', 'mailpoet' => 'Mailpoet', 'vaultpress' => 'VaultPress', + 'woocommerce-payments' => 'WooCommerce Payments', 'woocommerce' => 'WooCommerce', 'wordpress-beta-tester' => 'WordPress Beta Tester Plugin', 'wp-downgrade' => 'WP Downgrade', diff --git a/features/woocommerce-payments.php b/features/woocommerce-payments.php new file mode 100644 index 0000000..c38472f --- /dev/null +++ b/features/woocommerce-payments.php @@ -0,0 +1,125 @@ + false, + 'woocommerce-payments-jn-options' => false, + 'woocommerce-payments-release' => false, +); + +add_action( + 'jurassic_ninja_init', + function () { + add_action( + 'jurassic_ninja_add_features_before_auto_login', + function ( &$app = null, $features, $domain ) { + $features = array_merge( WCPAY_DEFAULTS, $features ); + if ( ! isset( $features['woocommerce-payments'] ) && $features['woocommerce-payments-release'] ) { + debug( '%s: Adding WooCommerce Payments (version %s)', $domain, $features['woocommerce-payments-release'] ); + add_woocommerce_payments_release_plugin( $features['woocommerce-payments-release'] ); + } + + if ( $features['woocommerce-payments-dev-tools'] ) { + debug( '%s: Adding WooCommerce Payments Dev Tools', $domain ); + add_woocommerce_payments_dev_tools(); + } + + if ( $features['woocommerce-payments-jn-options'] ) { + debug( '%s: Adding WooCommerce Payments Jurassic Ninja Options', $domain ); + add_woocommerce_payments_jurassic_ninja_options(); + } + }, + 10, + 3 + ); + + add_filter( + 'jurassic_ninja_rest_feature_defaults', + function ( $defaults ) { + return array_merge( $defaults, WCPAY_DEFAULTS ); + } + ); + + add_filter( + 'jurassic_ninja_rest_create_request_features', + function ( $features, $json_params ) { + if ( isset( $json_params['woocommerce-payments-dev-tools'] ) ) { + $features['woocommerce-payments-dev-tools'] = true; + } + + if ( isset( $json_params['woocommerce-payments-jn-options'] ) ) { + $features['woocommerce-payments-jn-options'] = true; + } + + if ( isset( $json_params['woocommerce-payments-release'] ) ) { + $features['woocommerce-payments-release'] = $json_params['woocommerce-payments-release']; + $features['woocommerce'] = true; + } + + return $features; + }, + 10, + 2 + ); + } +); + +/** + * Installs and activates the WooCommerce Payments plugin on the site + * for a given release tag. + * + * @param string $release_tag The WooCommerce Payments release tag to install. + */ +function add_woocommerce_payments_release_plugin( $release_tag ) { + $woocommerce_payments_release_tag_url = "https://github.com/Automattic/woocommerce-payments/releases/download/$release_tag/woocommerce-payments.zip"; + $cmd = "wp plugin install $woocommerce_payments_release_tag_url --activate"; + + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); +} + +/** + * Installs and activates the WooCommerce Payments Dev Tools plugin on the site. + */ +function add_woocommerce_payments_dev_tools() { + $woocommerce_payments_dev_tools_plugin_url = 'https://github.com/Automattic/woocommerce-payments-dev-tools-ci/archive/trunk.zip'; + // We install the trunk version of the plugin. + $cmd = "wp plugin install $woocommerce_payments_dev_tools_plugin_url --activate"; + + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); +} + +/** + * Adds a set of WordPress options to the site to make it + * easier to work with WooCommerce Payments on + * Jurassic Ninja sites. + */ +function add_woocommerce_payments_jurassic_ninja_options() { + // Disable the WPCOM request proxy and enable UPE and subscriptions features. + $cmd = 'wp option update wcpaydev_proxy 0' + . ' && wp option update _wcpay_feature_upe 1' + . ' && wp option update _wcpay_feature_upe_additional_payment_methods 1' + . ' && wp option update _wcpay_feature_subscriptions 1'; + + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); +} diff --git a/lib/stuff.php b/lib/stuff.php index 541046f..0d625e0 100644 --- a/lib/stuff.php +++ b/lib/stuff.php @@ -127,6 +127,7 @@ function require_feature_files() { '/features/gutenberg-nightly.php', '/features/wordpress-4.php', '/features/themes.php', + '/features/woocommerce-payments.php', ); $available_features = apply_filters( 'jurassic_ninja_available_features', $available_features );