From 5821d33193bf3fcb74980bdc97d3f618807fa157 Mon Sep 17 00:00:00 2001 From: Sam Seay Date: Mon, 2 Jan 2023 16:57:13 +1300 Subject: [PATCH 01/10] Add API endpoint and JS to show checkbox list of woo beta branches. --- features/woocommerce-beta-tester.php | 32 ++++++++++++++- jurassic.ninja.php | 6 +-- jurassicninja.js | 58 ++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 4 deletions(-) diff --git a/features/woocommerce-beta-tester.php b/features/woocommerce-beta-tester.php index 59b2deb..6658ae8 100644 --- a/features/woocommerce-beta-tester.php +++ b/features/woocommerce-beta-tester.php @@ -9,6 +9,21 @@ define( 'WOOCOMMERCE_BETA_TESTER_PLUGIN_URL', 'https://github.com/woocommerce/woocommerce-beta-tester/archive/refs/heads/trunk.zip' ); +add_action( + 'jurassic_ninja_added_rest_api_endpoints', + function () { + add_get_endpoint( + 'woocommerce-beta-tester/branches', + function () { + $manifest_url = 'https://betadownload.jetpack.me/woocommerce-branches.json'; + $manifest = json_decode( wp_remote_retrieve_body( wp_remote_get( $manifest_url ) ) ); + + return $manifest; + } + ); + } +); + add_action( 'jurassic_ninja_init', function () { @@ -23,6 +38,7 @@ function ( &$app = null, $features, $domain ) use ( $defaults ) { if ( $features['woocommerce-beta-tester'] ) { debug( '%s: Adding WooCommerce Beta Tester Plugin', $domain ); add_woocommerce_beta_tester_plugin(); + // TODO - determine which branch to install } }, 10, @@ -46,7 +62,8 @@ function ( $defaults ) { function ( $features, $json_params ) { if ( isset( $json_params['woocommerce-beta-tester'] ) ) { $features['woocommerce-beta-tester'] = $json_params['woocommerce-beta-tester']; - // The WooCommerce Beta Tester Plugin works only when woocommerce is installed and active too. + + // The WooCommerce Beta Tester Plugin works only when WooCommerce is installed and active too. if ( $features['woocommerce-beta-tester'] ) { $features['woocommerce'] = true; } @@ -95,3 +112,16 @@ function ( $s ) use ( $cmd ) { } ); } + +/** + * Installs and activates a live branch of WooCommerce on the site. + */ +function add_woocommerce_live_branch( $url ) { + $cmd = "wp plugin install $url --activate"; + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); +} diff --git a/jurassic.ninja.php b/jurassic.ninja.php index 1386ccb..0329256 100644 --- a/jurassic.ninja.php +++ b/jurassic.ninja.php @@ -47,7 +47,7 @@ function init() { // Create settings page. add_settings_page(); // Settings problems include credentials and IDs not configured. - if ( ! settings_problems() ) { + // if ( ! settings_problems() ) { // Include the JS only under the page which has the /create slug. add_scripts(); // Serve the API root and nonce only under the page which has the /create slug. @@ -57,7 +57,7 @@ function init() { // Disable temporarily. Run via crontab and Jurassic Ninja's CLI // add_cron_job( __FILE__ );. add_admin_bar_node(); - } + // } /** * Done after adding settings page and before anything else related to Jurassic Ninja specifics. * @@ -146,7 +146,7 @@ function add_scripts() { add_action( 'wp_enqueue_scripts', function () { - if ( page_is_launching_page() ) { + if ( true ) { wp_enqueue_script( 'jurassicninja.js', plugins_url( '', __FILE__ ) . '/jurassicninja.js', array( 'jquery' ), '1.1', true ); /** * Done after enqueueing the jurassic.ninja.js file diff --git a/jurassicninja.js b/jurassicninja.js index 31e13a3..5a41a3b 100644 --- a/jurassicninja.js +++ b/jurassicninja.js @@ -19,6 +19,7 @@ function init() { if ( isSpecialOpsPage() ) { hookJetpackBranches(); + hookWooCommerceBetaBranches(); hookAvailableLanguages(); jQuery( '[data-is-create-button]' ).click( function () { const $this = jQuery( this ); @@ -319,6 +320,18 @@ function favicon_update_colour( colour ) { } } +function getAvailableWooCommerceBetaBranches() { + return fetch( '/wp-json/jurassic.ninja/woocommerce-beta-tester/branches' ) + .then( response => response.json() ) + .then( body => { + if (body.data && body.data.pr) { + return Object.values(body.data.pr).sort((a, b) => a.branch.localeCompare(b.branch)); + } + + return []; + } ); +} + function getAvailableJetpackBetaPlugins() { return fetch( '/wp-json/jurassic.ninja/jetpack-beta/plugins') .then( response => response.json() ) @@ -330,6 +343,7 @@ function getAvailableJetpackBetaPlugins() { return plugins; } ); } + function getAvailableJetpackBetaBranches( plugin_slug ) { return fetch( '/wp-json/jurassic.ninja/jetpack-beta/plugins/' + ( plugin_slug || 'jetpack' ) + '/branches' ) .then( response => response.json() ) @@ -463,3 +477,47 @@ function hookJetpackBranches() { } ); } ); } + +function hookWooCommerceBetaBranches() { + getAvailableWooCommerceBetaBranches().then( branches => { + const wooBetaCheckBox = document.querySelector('[data-feature=woocommerce-beta-tester]'); + + if (branches.length && wooBetaCheckBox) { + const checkboxContainer = wooBetaCheckBox.closest('.checkbox'); + const wooBetaSelect = document.createElement('input'); + + wooBetaSelect.id = 'woocommerce_beta_branch'; + wooBetaSelect.name = 'woocommerce_beta_branch'; + wooBetaSelect.className = 'form-control'; + wooBetaSelect.setAttribute('role' , 'search') ; + wooBetaSelect.setAttribute('list', 'woocommerce_branches'); + wooBetaSelect.setAttribute('type', 'text'); + wooBetaSelect.setAttribute('Placeholder', 'Select a branch to enable'); + wooBetaSelect.style.display = "none"; + + const datalist = document.createElement('datalist'); + datalist.id = 'woocommerce_branches'; + + branches.forEach( branch => { + const option = document.createElement('option'); + option.innerHTML = branch.branch; + option.value = branch.branch; + datalist.appendChild(option); + } ); + + checkboxContainer.appendChild(wooBetaSelect); + checkboxContainer.appendChild(datalist); + + // Toggle display of the select list + wooBetaCheckBox.addEventListener('change', function() { + if (this.checked) { + wooBetaSelect.style.display = "block"; + } else { + wooBetaSelect.style.display = "none"; + } + }); + } + }); +} + + From 61492e8d615237ba9b4aa7f199ace2c1d4f90da9 Mon Sep 17 00:00:00 2001 From: Sam Seay Date: Mon, 16 Jan 2023 19:40:16 +1300 Subject: [PATCH 02/10] Add code to install beta tester from GH and run the beta tester CLI --- features/woocommerce-beta-tester.php | 79 ++++++++++++++++++++++------ jurassicninja.js | 5 +- 2 files changed, 68 insertions(+), 16 deletions(-) diff --git a/features/woocommerce-beta-tester.php b/features/woocommerce-beta-tester.php index 6658ae8..b1dd6ff 100644 --- a/features/woocommerce-beta-tester.php +++ b/features/woocommerce-beta-tester.php @@ -7,8 +7,6 @@ namespace jn; -define( 'WOOCOMMERCE_BETA_TESTER_PLUGIN_URL', 'https://github.com/woocommerce/woocommerce-beta-tester/archive/refs/heads/trunk.zip' ); - add_action( 'jurassic_ninja_added_rest_api_endpoints', function () { @@ -38,7 +36,13 @@ function ( &$app = null, $features, $domain ) use ( $defaults ) { if ( $features['woocommerce-beta-tester'] ) { debug( '%s: Adding WooCommerce Beta Tester Plugin', $domain ); add_woocommerce_beta_tester_plugin(); - // TODO - determine which branch to install + + if ($features['woocommerce-beta-tester-live-branch']) { + $branch = $features['woocommerce-beta-tester-live-branch']; + + debug( '%s: Adding WooCommerce Beta Tester Live Branch: %s', $domain, $branch ); + add_woocommerce_live_branch( $branch ); + } } }, 10, @@ -60,14 +64,21 @@ function ( $defaults ) { add_filter( 'jurassic_ninja_rest_create_request_features', function ( $features, $json_params ) { + error_log("*** WOOCOMMERCE BETA TESTER ***"); + error_log( print_r( $json_params, true ) ); if ( isset( $json_params['woocommerce-beta-tester'] ) ) { - $features['woocommerce-beta-tester'] = $json_params['woocommerce-beta-tester']; + $features['woocommerce-beta-tester'] = $json_params['woocommerce-beta-tester']; // The WooCommerce Beta Tester Plugin works only when WooCommerce is installed and active too. if ( $features['woocommerce-beta-tester'] ) { $features['woocommerce'] = true; } } + + if (isset( $json_params['woocommerce-beta-tester-live-branch'] ) ) { + $features['woocommerce-beta-tester-live-branch'] = $json_params['woocommerce-beta-tester-live-branch']; + } + return $features; }, 10, @@ -100,24 +111,62 @@ function ( $fields ) { ); /** - * Installs and activates WooCommerce Beta Tester plugin on the site. + * Get the WooCommerce Beta Tester Plugin Zip URL from Github. */ -function add_woocommerce_beta_tester_plugin() { - $woocommerce_beta_tester_plugin_url = WOOCOMMERCE_BETA_TESTER_PLUGIN_URL; - $cmd = "wp plugin install $woocommerce_beta_tester_plugin_url --activate"; - add_filter( - 'jurassic_ninja_feature_command', - function ( $s ) use ( $cmd ) { - return "$s && $cmd"; +function get_woocommerce_beta_tester_zip_url() { + $url = 'https://api.github.com/repos/woocommerce/woocommerce/releases'; + $response = wp_remote_get( $url ); + + if( is_wp_error( $response ) ) { + return false; + } else { + $releases = json_decode( wp_remote_retrieve_body( $response ), true ); + + $filteredReleases = array_filter($releases, function ($release) { + return strpos( $release['tag_name'], "wc-beta-tester" ) !== false; + }); + + usort( $releases, function ( $a, $b ) { + return strtotime( $b['created_at'] ) - strtotime( $a['created_at'] ); + }); + + $latestRelease = $releases[0]; + + $assets = $latestRelease['assets']; + $zip = array_filter($assets, function ($asset) { + return strpos( $asset['name'], "zip" ) !== false; + }); + + if ( count($zip) > 0 ) { + return $zip[0]['browser_download_url']; + } else { + return false; } - ); + } +} + +function add_woocommerce_beta_tester_plugin() { + $zipUrl = get_woocommerce_beta_tester_zip_url(); + + if ( $zipUrl ) { + $cmd = "wp plugin install $zipUrl --activate"; + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); + } else{ + throw new Exception( 'Could not find WooCommerce Beta Tester plugin zip file.' ); + } } /** * Installs and activates a live branch of WooCommerce on the site. */ -function add_woocommerce_live_branch( $url ) { - $cmd = "wp plugin install $url --activate"; +function add_woocommerce_live_branch( $branch_name ) { + $cmd = "wp wc-beta-tester install $branch_name && wp wc-beta-tester activate $branch_name"; + add_filter( 'jurassic_ninja_feature_command', function ( $s ) use ( $cmd ) { diff --git a/jurassicninja.js b/jurassicninja.js index 5a41a3b..672ec69 100644 --- a/jurassicninja.js +++ b/jurassicninja.js @@ -493,15 +493,18 @@ function hookWooCommerceBetaBranches() { wooBetaSelect.setAttribute('list', 'woocommerce_branches'); wooBetaSelect.setAttribute('type', 'text'); wooBetaSelect.setAttribute('Placeholder', 'Select a branch to enable'); + wooBetaSelect.setAttribute('data-feature', 'woocommerce-beta-tester-live-branch'); wooBetaSelect.style.display = "none"; const datalist = document.createElement('datalist'); datalist.id = 'woocommerce_branches'; + console.log(branches); + branches.forEach( branch => { const option = document.createElement('option'); option.innerHTML = branch.branch; - option.value = branch.branch; + option.value = branch.download_url; datalist.appendChild(option); } ); From 4d006cf942bed3edad593163daa18109f2875365 Mon Sep 17 00:00:00 2001 From: Sam Seay Date: Mon, 16 Jan 2023 20:21:58 +1300 Subject: [PATCH 03/10] WIP --- features/woocommerce-beta-tester.php | 4 ++-- jurassicninja.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/features/woocommerce-beta-tester.php b/features/woocommerce-beta-tester.php index b1dd6ff..ba4d556 100644 --- a/features/woocommerce-beta-tester.php +++ b/features/woocommerce-beta-tester.php @@ -64,8 +64,8 @@ function ( $defaults ) { add_filter( 'jurassic_ninja_rest_create_request_features', function ( $features, $json_params ) { - error_log("*** WOOCOMMERCE BETA TESTER ***"); - error_log( print_r( $json_params, true ) ); + // error_log("*** WOOCOMMERCE BETA TESTER ***"); + // error_log( print_r( $json_params, true ) ); if ( isset( $json_params['woocommerce-beta-tester'] ) ) { $features['woocommerce-beta-tester'] = $json_params['woocommerce-beta-tester']; diff --git a/jurassicninja.js b/jurassicninja.js index 672ec69..1b1fcbe 100644 --- a/jurassicninja.js +++ b/jurassicninja.js @@ -336,11 +336,11 @@ function getAvailableJetpackBetaPlugins() { return fetch( '/wp-json/jurassic.ninja/jetpack-beta/plugins') .then( response => response.json() ) .then( body => { - let plugins = Object.keys( body.data ).map( slug => { - return Object.assign( { slug: slug }, body.data[slug] ); - } ); - plugins.sort( ( a, b ) => a.name.localeCompare( b.name ) ); - return plugins; + // let plugins = Object.keys( body.data ).map( slug => { + // return Object.assign( { slug: slug }, body.data[slug] ); + // } ); + // plugins.sort( ( a, b ) => a.name.localeCompare( b.name ) ); + return []; } ); } From e6cdd1e8ed628c8315313a4529a5dd263c944b5d Mon Sep 17 00:00:00 2001 From: Sam Seay Date: Tue, 17 Jan 2023 20:02:35 +1300 Subject: [PATCH 04/10] Clean up the code. --- features/woocommerce-beta-tester.php | 7 ++++--- jurassicninja.js | 14 ++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/features/woocommerce-beta-tester.php b/features/woocommerce-beta-tester.php index ba4d556..8974e8b 100644 --- a/features/woocommerce-beta-tester.php +++ b/features/woocommerce-beta-tester.php @@ -63,9 +63,7 @@ function ( $defaults ) { add_filter( 'jurassic_ninja_rest_create_request_features', - function ( $features, $json_params ) { - // error_log("*** WOOCOMMERCE BETA TESTER ***"); - // error_log( print_r( $json_params, true ) ); + function ( $features, $json_params ) { if ( isset( $json_params['woocommerce-beta-tester'] ) ) { $features['woocommerce-beta-tester'] = $json_params['woocommerce-beta-tester']; @@ -145,6 +143,9 @@ function get_woocommerce_beta_tester_zip_url() { } } +/** + * Retrieve and install the WooCommerce Beta Tester Plugin. + */ function add_woocommerce_beta_tester_plugin() { $zipUrl = get_woocommerce_beta_tester_zip_url(); diff --git a/jurassicninja.js b/jurassicninja.js index 1b1fcbe..0512274 100644 --- a/jurassicninja.js +++ b/jurassicninja.js @@ -336,11 +336,11 @@ function getAvailableJetpackBetaPlugins() { return fetch( '/wp-json/jurassic.ninja/jetpack-beta/plugins') .then( response => response.json() ) .then( body => { - // let plugins = Object.keys( body.data ).map( slug => { - // return Object.assign( { slug: slug }, body.data[slug] ); - // } ); - // plugins.sort( ( a, b ) => a.name.localeCompare( b.name ) ); - return []; + let plugins = Object.keys( body.data ).map( slug => { + return Object.assign( { slug: slug }, body.data[slug] ); + } ); + plugins.sort( ( a, b ) => a.name.localeCompare( b.name ) ); + return plugins; } ); } @@ -498,13 +498,11 @@ function hookWooCommerceBetaBranches() { const datalist = document.createElement('datalist'); datalist.id = 'woocommerce_branches'; - - console.log(branches); branches.forEach( branch => { const option = document.createElement('option'); option.innerHTML = branch.branch; - option.value = branch.download_url; + option.value = branch.branch; datalist.appendChild(option); } ); From bb003bb36bd4bb2c15a202336393eef095f02e4a Mon Sep 17 00:00:00 2001 From: Sam Seay Date: Tue, 17 Jan 2023 20:59:08 +1300 Subject: [PATCH 05/10] Some small fixes. --- features/woocommerce-beta-tester.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/features/woocommerce-beta-tester.php b/features/woocommerce-beta-tester.php index 8974e8b..c761a4d 100644 --- a/features/woocommerce-beta-tester.php +++ b/features/woocommerce-beta-tester.php @@ -27,6 +27,7 @@ function () { function () { $defaults = array( 'woocommerce-beta-tester' => false, + 'woocommerce-beta-tester-live-branch' => false ); add_action( @@ -37,10 +38,10 @@ function ( &$app = null, $features, $domain ) use ( $defaults ) { debug( '%s: Adding WooCommerce Beta Tester Plugin', $domain ); add_woocommerce_beta_tester_plugin(); - if ($features['woocommerce-beta-tester-live-branch']) { + if ( $features['woocommerce-beta-tester-live-branch'] ) { $branch = $features['woocommerce-beta-tester-live-branch']; - debug( '%s: Adding WooCommerce Beta Tester Live Branch: %s', $domain, $branch ); + debug( '%s: Adding WooCommerce Live Branch: %s', $domain, $branch ); add_woocommerce_live_branch( $branch ); } } @@ -147,17 +148,17 @@ function get_woocommerce_beta_tester_zip_url() { * Retrieve and install the WooCommerce Beta Tester Plugin. */ function add_woocommerce_beta_tester_plugin() { - $zipUrl = get_woocommerce_beta_tester_zip_url(); + $zip_url = get_woocommerce_beta_tester_zip_url(); - if ( $zipUrl ) { - $cmd = "wp plugin install $zipUrl --activate"; + if ( $zip_url ) { + $cmd = "wp plugin install $zip_url --activate"; add_filter( 'jurassic_ninja_feature_command', function ( $s ) use ( $cmd ) { return "$s && $cmd"; } ); - } else{ + } else { throw new Exception( 'Could not find WooCommerce Beta Tester plugin zip file.' ); } } From 57bc3a7aac5b7bd237dcf3ca90937a495ff1be42 Mon Sep 17 00:00:00 2001 From: Sam Seay Date: Wed, 18 Jan 2023 18:51:48 +1300 Subject: [PATCH 06/10] Fix a bug determining the release to use. --- features/woocommerce-beta-tester.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/features/woocommerce-beta-tester.php b/features/woocommerce-beta-tester.php index c761a4d..29cec85 100644 --- a/features/woocommerce-beta-tester.php +++ b/features/woocommerce-beta-tester.php @@ -74,7 +74,7 @@ function ( $features, $json_params ) { } } - if (isset( $json_params['woocommerce-beta-tester-live-branch'] ) ) { + if ( isset( $json_params['woocommerce-beta-tester-live-branch'] ) ) { $features['woocommerce-beta-tester-live-branch'] = $json_params['woocommerce-beta-tester-live-branch']; } @@ -125,11 +125,11 @@ function get_woocommerce_beta_tester_zip_url() { return strpos( $release['tag_name'], "wc-beta-tester" ) !== false; }); - usort( $releases, function ( $a, $b ) { + usort( $filteredReleases, function ( $a, $b ) { return strtotime( $b['created_at'] ) - strtotime( $a['created_at'] ); }); - $latestRelease = $releases[0]; + $latestRelease = $filteredReleases[0]; $assets = $latestRelease['assets']; $zip = array_filter($assets, function ($asset) { @@ -167,7 +167,7 @@ function ( $s ) use ( $cmd ) { * Installs and activates a live branch of WooCommerce on the site. */ function add_woocommerce_live_branch( $branch_name ) { - $cmd = "wp wc-beta-tester install $branch_name && wp wc-beta-tester activate $branch_name"; + $cmd = "wp wc-beta-tester deactivate_woocommerce && wp wc-beta-tester install $branch_name && wp wc-beta-tester activate $branch_name"; add_filter( 'jurassic_ninja_feature_command', From e036e9d520b7200915fe45cb12414cb6743f7691 Mon Sep 17 00:00:00 2001 From: Sam Seay Date: Wed, 18 Jan 2023 18:53:51 +1300 Subject: [PATCH 07/10] Beta tester no longer needs WooCommerce active to work. --- features/woocommerce-beta-tester.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/features/woocommerce-beta-tester.php b/features/woocommerce-beta-tester.php index 29cec85..d09eeaa 100644 --- a/features/woocommerce-beta-tester.php +++ b/features/woocommerce-beta-tester.php @@ -66,12 +66,7 @@ function ( $defaults ) { 'jurassic_ninja_rest_create_request_features', function ( $features, $json_params ) { if ( isset( $json_params['woocommerce-beta-tester'] ) ) { - $features['woocommerce-beta-tester'] = $json_params['woocommerce-beta-tester']; - - // The WooCommerce Beta Tester Plugin works only when WooCommerce is installed and active too. - if ( $features['woocommerce-beta-tester'] ) { - $features['woocommerce'] = true; - } + $features['woocommerce-beta-tester'] = $json_params['woocommerce-beta-tester']; } if ( isset( $json_params['woocommerce-beta-tester-live-branch'] ) ) { From e59e0819d8d4f64888194f18d1767a6876942164 Mon Sep 17 00:00:00 2001 From: Sam Seay Date: Wed, 18 Jan 2023 18:55:23 +1300 Subject: [PATCH 08/10] Revert testing changes. --- jurassic.ninja.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jurassic.ninja.php b/jurassic.ninja.php index 0329256..149fca9 100644 --- a/jurassic.ninja.php +++ b/jurassic.ninja.php @@ -2,7 +2,7 @@ /** * Plugin Name: Jurassic Ninja * Description: Launch ephemeral instances of WordPress + Jetpack using ServerPilot and an Ubuntu Box. - * Version: 5.20 + * Version: 5.21 * Author: Automattic * * @package jurassic-ninja @@ -47,7 +47,7 @@ function init() { // Create settings page. add_settings_page(); // Settings problems include credentials and IDs not configured. - // if ( ! settings_problems() ) { + if ( ! settings_problems() ) { // Include the JS only under the page which has the /create slug. add_scripts(); // Serve the API root and nonce only under the page which has the /create slug. @@ -57,7 +57,7 @@ function init() { // Disable temporarily. Run via crontab and Jurassic Ninja's CLI // add_cron_job( __FILE__ );. add_admin_bar_node(); - // } + } /** * Done after adding settings page and before anything else related to Jurassic Ninja specifics. * @@ -146,7 +146,7 @@ function add_scripts() { add_action( 'wp_enqueue_scripts', function () { - if ( true ) { + if ( page_is_launching_page() ) { wp_enqueue_script( 'jurassicninja.js', plugins_url( '', __FILE__ ) . '/jurassicninja.js', array( 'jquery' ), '1.1', true ); /** * Done after enqueueing the jurassic.ninja.js file From d2563c9a065b6f9fc030dcd66c91d3576459f6fd Mon Sep 17 00:00:00 2001 From: Sam Seay Date: Mon, 23 Jan 2023 15:59:33 +1300 Subject: [PATCH 09/10] Fix PHP lint issues --- features/woocommerce-beta-tester.php | 53 +++++++++++++++++----------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/features/woocommerce-beta-tester.php b/features/woocommerce-beta-tester.php index d09eeaa..dc677a1 100644 --- a/features/woocommerce-beta-tester.php +++ b/features/woocommerce-beta-tester.php @@ -9,7 +9,7 @@ add_action( 'jurassic_ninja_added_rest_api_endpoints', - function () { + function () { add_get_endpoint( 'woocommerce-beta-tester/branches', function () { @@ -27,7 +27,7 @@ function () { function () { $defaults = array( 'woocommerce-beta-tester' => false, - 'woocommerce-beta-tester-live-branch' => false + 'woocommerce-beta-tester-live-branch' => false, ); add_action( @@ -37,7 +37,7 @@ function ( &$app = null, $features, $domain ) use ( $defaults ) { if ( $features['woocommerce-beta-tester'] ) { debug( '%s: Adding WooCommerce Beta Tester Plugin', $domain ); add_woocommerce_beta_tester_plugin(); - + if ( $features['woocommerce-beta-tester-live-branch'] ) { $branch = $features['woocommerce-beta-tester-live-branch']; @@ -64,7 +64,7 @@ function ( $defaults ) { add_filter( 'jurassic_ninja_rest_create_request_features', - function ( $features, $json_params ) { + function ( $features, $json_params ) { if ( isset( $json_params['woocommerce-beta-tester'] ) ) { $features['woocommerce-beta-tester'] = $json_params['woocommerce-beta-tester']; } @@ -72,7 +72,7 @@ function ( $features, $json_params ) { if ( isset( $json_params['woocommerce-beta-tester-live-branch'] ) ) { $features['woocommerce-beta-tester-live-branch'] = $json_params['woocommerce-beta-tester-live-branch']; } - + return $features; }, 10, @@ -111,27 +111,36 @@ function get_woocommerce_beta_tester_zip_url() { $url = 'https://api.github.com/repos/woocommerce/woocommerce/releases'; $response = wp_remote_get( $url ); - if( is_wp_error( $response ) ) { + if ( is_wp_error( $response ) ) { return false; } else { $releases = json_decode( wp_remote_retrieve_body( $response ), true ); - $filteredReleases = array_filter($releases, function ($release) { - return strpos( $release['tag_name'], "wc-beta-tester" ) !== false; - }); + $filtered_releases = array_filter( + $releases, + function ( $release ) { + return strpos( $release['tag_name'], 'wc-beta-tester' ) !== false; + } + ); - usort( $filteredReleases, function ( $a, $b ) { - return strtotime( $b['created_at'] ) - strtotime( $a['created_at'] ); - }); + usort( + $filtered_releases, + function ( $a, $b ) { + return strtotime( $b['created_at'] ) - strtotime( $a['created_at'] ); + } + ); - $latestRelease = $filteredReleases[0]; + $latest_release = $filtered_releases[0]; - $assets = $latestRelease['assets']; - $zip = array_filter($assets, function ($asset) { - return strpos( $asset['name'], "zip" ) !== false; - }); + $assets = $latest_release['assets']; + $zip = array_filter( + $assets, + function ( $asset ) { + return strpos( $asset['name'], 'zip' ) !== false; + } + ); - if ( count($zip) > 0 ) { + if ( count( $zip ) > 0 ) { return $zip[0]['browser_download_url']; } else { return false; @@ -141,10 +150,12 @@ function get_woocommerce_beta_tester_zip_url() { /** * Retrieve and install the WooCommerce Beta Tester Plugin. + * + * @throws Exception If the plugin zip file cannot be found. */ function add_woocommerce_beta_tester_plugin() { $zip_url = get_woocommerce_beta_tester_zip_url(); - + if ( $zip_url ) { $cmd = "wp plugin install $zip_url --activate"; add_filter( @@ -160,10 +171,12 @@ function ( $s ) use ( $cmd ) { /** * Installs and activates a live branch of WooCommerce on the site. + * + * @param string $branch_name The name of the branch to install. */ function add_woocommerce_live_branch( $branch_name ) { $cmd = "wp wc-beta-tester deactivate_woocommerce && wp wc-beta-tester install $branch_name && wp wc-beta-tester activate $branch_name"; - + add_filter( 'jurassic_ninja_feature_command', function ( $s ) use ( $cmd ) { From 0bb99421bcf3d2050c8eacd35b4c6693ae26e360 Mon Sep 17 00:00:00 2001 From: dereksmart Date: Sun, 22 Jan 2023 22:22:27 -0500 Subject: [PATCH 10/10] pin jetpack codesniffer to 2.6.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 26a979b..99910f9 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "php": "~7.1 || 8.*" }, "require-dev": { - "automattic/jetpack-codesniffer": "^2.0", + "automattic/jetpack-codesniffer": "2.6.0", "brain/monkey": "^2.6", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "phpunit/phpunit": "7.* || 8.*",