From 7167f4fe2edceefd99f409fbad4e9c81afb2fcec Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Mon, 4 Apr 2022 14:39:03 -0600 Subject: [PATCH 01/13] Rename feature file --- features/{jetpack-crm-master.php => jetpack-crm.php} | 0 lib/stuff.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename features/{jetpack-crm-master.php => jetpack-crm.php} (100%) diff --git a/features/jetpack-crm-master.php b/features/jetpack-crm.php similarity index 100% rename from features/jetpack-crm-master.php rename to features/jetpack-crm.php 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', From fa9239b5c607566390d6bb64ef22370055e460da Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Mon, 4 Apr 2022 15:52:06 -0600 Subject: [PATCH 02/13] First pass at allowing custom JPCRM builds/versions to be installed --- features/jetpack-crm.php | 78 +++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 16 deletions(-) diff --git a/features/jetpack-crm.php b/features/jetpack-crm.php index 3d4e570..8d0220f 100644 --- a/features/jetpack-crm.php +++ b/features/jetpack-crm.php @@ -7,27 +7,41 @@ namespace jn; -define( 'JETPACK_CRM_PLUGIN_MASTER_URL', 'https://github.com/automattic/zero-bs-crm/archive/master.zip' ); - add_action( 'jurassic_ninja_init', function () { + $defaults = array( - 'jetpack-crm-master' => false, + 'jpcrm-build' => false, + 'zero-bs-crm' => false, + 'jpcrm-version' => 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(); + + // Don't install if Jetpack CRM isn't specified. + if ( ! $features['zero-bs-crm'] ) { + return; } + + if ( $features['jpcrm-version'] ) { + + // Install specified version of Jetpack CRM. + 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'] ); + + } + }, 10, 3 @@ -36,8 +50,13 @@ function ( &$app, $features, $domain ) use ( $defaults ) { 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']; + + 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; @@ -49,15 +68,42 @@ function ( $features, $json_params ) { ); /** - * Installs and activates Jetpack CRM plugin (master branch) on the site. + * Installs and activates a specified version of Jetpack CRM from the WP.org plugin repo. */ -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"; +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. + */ +function add_jpcrm_from_custom_build( $build ) { + + // For now, 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 ) ); + } + + $jpcrm_build_base_url = 'https://TBD/builds/'; + $jpcrm_build_url = $jpcrm_build_base_url . 'zero-bs-crm-' . $build . '.zip'; + $cmd = "wp plugin install $jpcrm_build_url --activate"; + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); +} \ No newline at end of file From 9f0ff367784bc2facd8a1311bc4d99c47d59b3b9 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Tue, 5 Apr 2022 08:55:52 -0600 Subject: [PATCH 03/13] Handle JPCRM installation within feature file --- features/jetpack-crm.php | 12 +++++++++--- features/plugins.php | 1 - 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/features/jetpack-crm.php b/features/jetpack-crm.php index 8d0220f..36f9567 100644 --- a/features/jetpack-crm.php +++ b/features/jetpack-crm.php @@ -12,8 +12,8 @@ function () { $defaults = array( + 'jpcrm' => false, 'jpcrm-build' => false, - 'zero-bs-crm' => false, 'jpcrm-version' => false, ); @@ -24,13 +24,13 @@ function ( &$app, $features, $domain ) use ( $defaults ) { $features = array_merge( $defaults, $features ); // Don't install if Jetpack CRM isn't specified. - if ( ! $features['zero-bs-crm'] ) { + if ( ! $features['jpcrm'] ) { return; } if ( $features['jpcrm-version'] ) { - // Install specified version of Jetpack CRM. + // 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'] ); @@ -40,6 +40,12 @@ function ( &$app, $features, $domain ) use ( $defaults ) { 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 %s', $domain, $features['jpcrm-build'] ); + add_directory_plugin( 'zero-bs-crm' ); + } }, diff --git a/features/plugins.php b/features/plugins.php index 957a3b2..f83b12c 100644 --- a/features/plugins.php +++ b/features/plugins.php @@ -18,7 +18,6 @@ function () { $whitelist = array( 'amp' => 'AMP', - 'zero-bs-crm' => 'Jetpack CRM', 'classic-editor' => 'Classic Editor', 'code-snippets' => 'Code Snippets', 'config-constants' => 'Config Constants', From 3e0604ccd7905e8e4084994ded6523caa7b895dc Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Tue, 5 Apr 2022 09:50:00 -0600 Subject: [PATCH 04/13] Add JPCRM toggle options to JS --- jurassicninja.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jurassicninja.js b/jurassicninja.js index f6cb55c..800c085 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 toggleJPCRMProducts() { + 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( toggleJPCRMProducts ); + let onchange; if ( $branches_list.length ) { onchange = () => { From f4d151160cf08378b90d910f9efa02d2b158d61b Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Tue, 5 Apr 2022 09:50:14 -0600 Subject: [PATCH 05/13] Add jn_jpcrm_options shortcode --- features/jetpack-crm.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/features/jetpack-crm.php b/features/jetpack-crm.php index 36f9567..e04e25c 100644 --- a/features/jetpack-crm.php +++ b/features/jetpack-crm.php @@ -112,4 +112,32 @@ function ( $s ) use ( $cmd ) { return "$s && $cmd"; } ); -} \ No newline at end of file +} + +/** + * Register a shortcode which renders Jetpack Licensing controls suitable for SpecialOps usage. + */ +\add_shortcode( + 'jn_jpcrm_options', + function () { + ob_start(); + ?> + +
+ Date: Tue, 5 Apr 2022 09:52:00 -0600 Subject: [PATCH 06/13] Add jn_jpcrm_options shortcode to specialops template --- docs/specialops.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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: