diff --git a/docs/specialops.md b/docs/specialops.md
index 80cd41a..738e68f 100644
--- a/docs/specialops.md
+++ b/docs/specialops.md
@@ -69,7 +69,9 @@ Recommended `/specialops` page content:
-
+
+[jn_jpcrm_options]
+
diff --git a/features/jetpack-crm-master.php b/features/jetpack-crm-master.php
deleted file mode 100644
index 3d4e570..0000000
--- a/features/jetpack-crm-master.php
+++ /dev/null
@@ -1,63 +0,0 @@
- false,
- );
-
- add_action(
- 'jurassic_ninja_add_features_before_auto_login',
- function ( &$app, $features, $domain ) use ( $defaults ) {
- $features = array_merge( $defaults, $features );
- if ( $features['jetpack-crm-master'] ) {
- // Abort the installation from master if the public plugin is selected.
- if ( $features['zero-bs-crm'] ) {
- return;
- }
- debug( '%s: Adding Jetpack CRM Plugin (master branch)', $domain );
- add_jetpack_crm_master_plugin();
- }
- },
- 10,
- 3
- );
-
- add_filter(
- 'jurassic_ninja_rest_create_request_features',
- function ( $features, $json_params ) {
- if ( isset( $json_params['jetpack-crm-master'] ) ) {
- $features['jetpack-crm-master'] = $json_params['jetpack-crm-master'];
- }
-
- return $features;
- },
- 10,
- 2
- );
- }
-);
-
-/**
- * Installs and activates Jetpack CRM plugin (master branch) on the site.
- */
-function add_jetpack_crm_master_plugin() {
- $jetpack_crm_plugin_master_url = JETPACK_CRM_PLUGIN_MASTER_URL;
- $cmd = "wp plugin install $jetpack_crm_plugin_master_url --activate";
- add_filter(
- 'jurassic_ninja_feature_command',
- function ( $s ) use ( $cmd ) {
- return "$s && $cmd";
- }
- );
-}
diff --git a/features/jetpack-crm.php b/features/jetpack-crm.php
new file mode 100644
index 0000000..00c34aa
--- /dev/null
+++ b/features/jetpack-crm.php
@@ -0,0 +1,162 @@
+ false,
+ 'jpcrm-build' => false,
+ 'jpcrm-version' => false,
+ );
+
+ add_action(
+ 'jurassic_ninja_add_features_before_auto_login',
+ function ( &$app, $features, $domain ) use ( $defaults ) {
+
+ $features = array_merge( $defaults, $features );
+
+ // Don't install if Jetpack CRM isn't selected.
+ if ( ! $features['jpcrm'] ) {
+ return;
+ }
+
+ if ( $features['jpcrm-version'] ) {
+
+ // Install specified version of Jetpack CRM from WP.org repo.
+ debug( '%s: Installing Jetpack CRM version %s from WP.org repo', $domain, $features['jpcrm-version'] );
+ add_jpcrm_from_wporg( $features['jpcrm-version'] );
+
+ } elseif ( $features['jpcrm-build'] ) {
+
+ // Install custom build of Jetpack CRM.
+ debug( '%s: Installing Jetpack CRM from %s', $domain, $features['jpcrm-build'] );
+ add_jpcrm_from_custom_build( $features['jpcrm-build'] );
+
+ } else {
+
+ // Install current version of Jetpack CRM from WP.org repo.
+ debug( '%s: Installing Jetpack CRM from WP.org', $domain );
+ add_directory_plugin( 'zero-bs-crm' );
+
+ }
+
+ },
+ 10,
+ 3
+ );
+
+ add_filter(
+ 'jurassic_ninja_rest_create_request_features',
+ function ( $features, $json_params ) {
+
+ if ( isset( $json_params['jpcrm'] ) ) {
+ $features['jpcrm'] = $json_params['jpcrm'];
+ }
+
+ if ( isset( $json_params['jpcrm-version'] ) ) {
+ $features['jpcrm-version'] = $json_params['jpcrm-version'];
+ }
+
+ if ( isset( $json_params['jpcrm-build'] ) ) {
+ $features['jpcrm-build'] = $json_params['jpcrm-build'];
+ }
+
+ return $features;
+ },
+ 10,
+ 2
+ );
+ }
+);
+
+/**
+ * Installs and activates a specified version of Jetpack CRM from the WP.org plugin repo.
+ *
+ * @param string $version Version of Jetpack CRM.
+ */
+function add_jpcrm_from_wporg( $version ) {
+
+ // Verify we have a valid version number.
+ if ( ! version_compare( $version, '1.0.0', '>=' ) ) {
+ return new \WP_Error( 'bad_version_number', 'Bad version number.', array( 'status' => 404 ) );
+ }
+
+ $cmd = "wp plugin install zero-bs-crm --version=$version --activate";
+
+ add_filter(
+ 'jurassic_ninja_feature_command',
+ function ( $s ) use ( $cmd ) {
+ return "$s && $cmd";
+ }
+ );
+
+}
+
+/**
+ * Installs and activates a specified build of Jetpack CRM from our custom build URL.
+ *
+ * @param string $build Hash of build to use.
+ */
+function add_jpcrm_from_custom_build( $build ) {
+
+ // phpcs:disable Squiz.PHP.CommentedOutCode.Found
+
+ /*
+ * Require commit SHA-1 hash (40 char long hex).
+ * if ( ! preg_match( '/^[A-Fa-f0-9]{40}$/', $build ) ) {
+ * return new \WP_Error( 'bad_commit_hash', 'Invalid commit hash.', array( 'status' => 404 ) );
+ * }
+ */
+ // phpcs:enable
+
+ $clean_build = str_replace( '/', '_', $build );
+
+ // note that this public link is in a public repo
+ $jpcrm_build_base_url = 'https://jetpackcrm-builds.s3.amazonaws.com/builds/';
+ $jpcrm_build_url = $jpcrm_build_base_url . 'zero-bs-crm-' . $clean_build . '.zip';
+
+ $cmd = "wp plugin install $jpcrm_build_url --activate";
+
+ add_filter(
+ 'jurassic_ninja_feature_command',
+ function ( $s ) use ( $cmd ) {
+ return "$s && $cmd";
+ }
+ );
+}
+
+/**
+ * Register a shortcode which renders Jetpack Licensing controls suitable for SpecialOps usage.
+ */
+\add_shortcode(
+ 'jn_jpcrm_options',
+ function () {
+ ob_start();
+ ?>
+
+
+ 'AMP',
- 'zero-bs-crm' => 'Jetpack CRM',
'classic-editor' => 'Classic Editor',
'code-snippets' => 'Code Snippets',
'config-constants' => 'Config Constants',
diff --git a/jurassicninja.js b/jurassicninja.js
index f6cb55c..31e13a3 100644
--- a/jurassicninja.js
+++ b/jurassicninja.js
@@ -97,6 +97,13 @@ function collectFeaturesFromFormInputs() {
},
[]
);
+
+ // get selected JPCRM option and value
+ selected_jpcrm_option = document.querySelector( "input[type='radio'][name='jpcrm-options']:checked" );
+ if ( selected_jpcrm_option.dataset.feature ) {
+ features[selected_jpcrm_option.dataset.feature] = selected_jpcrm_option.nextElementSibling.value;
+ }
+
return features;
}
@@ -353,9 +360,16 @@ function toggleJetpackProducts() {
$jetpack_products.toggle( $jetpack_toggle.is( ':checked' ) );
}
+function toggleJPCRMOptions() {
+ const $jpcrm_toggle = jQuery( '[data-feature=jpcrm]' );
+ const $jpcrm_options = jQuery( '.jn-jpcrm-options' );
+ $jpcrm_options.toggle( $jpcrm_toggle.is( ':checked' ) );
+}
+
function hookJetpackBranches() {
const $jetpack_toggle = jQuery( '[data-feature=jetpack]' );
const $jetpack_beta_toggle = jQuery( '[data-feature=jetpack-beta]' );
+ const $jpcrm_toggle = jQuery( '[data-feature=jpcrm]' );
const $branches_list = jQuery('#jetpack_beta_branches_group');
const $search_input = jQuery('#jetpack_branch');
const search_results = document.getElementById('jetpack_branches');
@@ -363,6 +377,8 @@ function hookJetpackBranches() {
$jetpack_toggle.change( toggleJetpackProducts );
toggleJetpackProducts();
+ $jpcrm_toggle.change( toggleJPCRMOptions );
+
let onchange;
if ( $branches_list.length ) {
onchange = () => {
diff --git a/lib/stuff.php b/lib/stuff.php
index 0d625e0..3088196 100644
--- a/lib/stuff.php
+++ b/lib/stuff.php
@@ -116,7 +116,7 @@ function require_feature_files() {
'/features/jetpack-beta.php',
'/features/wc-smooth-generator.php',
'/features/woocommerce-beta-tester.php',
- '/features/jetpack-crm-master.php',
+ '/features/jetpack-crm.php',
'/features/jetpack-debug-helper.php',
'/features/client-example.php',
'/features/my-jetpack.php',