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:
  • -
    +
    +[jn_jpcrm_options] +
  • From 188db1bf78440464cf5613b2a787b36f07c7c788 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Tue, 5 Apr 2022 14:26:36 -0600 Subject: [PATCH 07/13] Spacing/wording tweaks --- features/jetpack-crm.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/features/jetpack-crm.php b/features/jetpack-crm.php index e04e25c..36ea116 100644 --- a/features/jetpack-crm.php +++ b/features/jetpack-crm.php @@ -23,7 +23,7 @@ function ( &$app, $features, $domain ) use ( $defaults ) { $features = array_merge( $defaults, $features ); - // Don't install if Jetpack CRM isn't specified. + // Don't install if Jetpack CRM isn't selected. if ( ! $features['jpcrm'] ) { return; } @@ -43,7 +43,7 @@ function ( &$app, $features, $domain ) use ( $defaults ) { } else { // Install current version of Jetpack CRM from WP.org repo. - debug( '%s: Installing Jetpack CRM from %s', $domain, $features['jpcrm-build'] ); + debug( '%s: Installing Jetpack CRM from WP.org', $domain ); add_directory_plugin( 'zero-bs-crm' ); } @@ -84,6 +84,7 @@ function add_jpcrm_from_wporg( $version ) { } $cmd = "wp plugin install zero-bs-crm --version=$version --activate"; + add_filter( 'jurassic_ninja_feature_command', function ( $s ) use ( $cmd ) { @@ -106,6 +107,7 @@ function add_jpcrm_from_custom_build( $build ) { $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 ) { From 3ff94065942aad70d4bed21114099d54895f52cc Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Tue, 5 Apr 2022 14:26:59 -0600 Subject: [PATCH 08/13] Catch jpcrm feature param --- features/jetpack-crm.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/features/jetpack-crm.php b/features/jetpack-crm.php index 36ea116..94e282e 100644 --- a/features/jetpack-crm.php +++ b/features/jetpack-crm.php @@ -57,6 +57,10 @@ function ( &$app, $features, $domain ) use ( $defaults ) { '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']; } From 05b9468d80df513993d95edf95afae452d744c15 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Tue, 5 Apr 2022 14:27:22 -0600 Subject: [PATCH 09/13] Allow build input based on branch name --- features/jetpack-crm.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/features/jetpack-crm.php b/features/jetpack-crm.php index 94e282e..caf9c2f 100644 --- a/features/jetpack-crm.php +++ b/features/jetpack-crm.php @@ -103,13 +103,17 @@ function ( $s ) use ( $cmd ) { */ 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 ) ); - } + // 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 ) ); + // } + + $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'; - $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( From ad42d94fc2fec025fa9a457c5673aec702b6b42a Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Tue, 5 Apr 2022 14:29:59 -0600 Subject: [PATCH 10/13] Add placeholders --- features/jetpack-crm.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/jetpack-crm.php b/features/jetpack-crm.php index caf9c2f..e160550 100644 --- a/features/jetpack-crm.php +++ b/features/jetpack-crm.php @@ -143,8 +143,8 @@ function () { Date: Tue, 5 Apr 2022 14:42:36 -0600 Subject: [PATCH 11/13] Tweak function name --- jurassicninja.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jurassicninja.js b/jurassicninja.js index 800c085..31e13a3 100644 --- a/jurassicninja.js +++ b/jurassicninja.js @@ -360,7 +360,7 @@ function toggleJetpackProducts() { $jetpack_products.toggle( $jetpack_toggle.is( ':checked' ) ); } -function toggleJPCRMProducts() { +function toggleJPCRMOptions() { const $jpcrm_toggle = jQuery( '[data-feature=jpcrm]' ); const $jpcrm_options = jQuery( '.jn-jpcrm-options' ); $jpcrm_options.toggle( $jpcrm_toggle.is( ':checked' ) ); @@ -377,7 +377,7 @@ function hookJetpackBranches() { $jetpack_toggle.change( toggleJetpackProducts ); toggleJetpackProducts(); - $jpcrm_toggle.change( toggleJPCRMProducts ); + $jpcrm_toggle.change( toggleJPCRMOptions ); let onchange; if ( $branches_list.length ) { From 5b67c0ce2eabe12120ea2fb77990391bb1f440f8 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Tue, 5 Apr 2022 14:45:49 -0600 Subject: [PATCH 12/13] Indent tweak --- features/jetpack-crm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/jetpack-crm.php b/features/jetpack-crm.php index e160550..47c2156 100644 --- a/features/jetpack-crm.php +++ b/features/jetpack-crm.php @@ -30,7 +30,7 @@ function ( &$app, $features, $domain ) use ( $defaults ) { if ( $features['jpcrm-version'] ) { - // Install specified version of Jetpack CRM from WP.org repo. + // 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'] ); From 9e43b23e9a4ae0ecb586f67cd3bf5c359dbe7c2d Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Tue, 19 Apr 2022 13:34:27 -0500 Subject: [PATCH 13/13] PHPCS fixes --- features/jetpack-crm.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/features/jetpack-crm.php b/features/jetpack-crm.php index 47c2156..00c34aa 100644 --- a/features/jetpack-crm.php +++ b/features/jetpack-crm.php @@ -79,6 +79,8 @@ function ( $features, $json_params ) { /** * 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 ) { @@ -100,15 +102,22 @@ function ( $s ) use ( $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 ) { - // 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:disable Squiz.PHP.CommentedOutCode.Found - $clean_build = str_replace('/', '_', $build); + /* + * 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/'; @@ -150,4 +159,4 @@ function () {