From 7dd88e0faeb10c9f48cb56833c683b9a4b717e5b Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:17:55 +0100 Subject: [PATCH 1/5] Required WP version is bumped to 5.9. --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 07f9487..6ba417c 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: plausible, DaanvandenBergh Donate link: https://plausible.io/ Tags: analytics, google analytics, web analytics, stats, privacy -Requires at least: 5.3 +Requires at least: 5.9 Tested up to: 6.6 Requires PHP: 7.0 Stable tag: 2.2.0 From e0c9b6536bf26a87c33526f3393aabe7540dddc2 Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:19:01 +0100 Subject: [PATCH 2/5] Removed unused code. --- src/Admin/Provisioning.php | 78 +------------------------------------- 1 file changed, 1 insertion(+), 77 deletions(-) diff --git a/src/Admin/Provisioning.php b/src/Admin/Provisioning.php index 6d395c1..f988d40 100644 --- a/src/Admin/Provisioning.php +++ b/src/Admin/Provisioning.php @@ -219,47 +219,6 @@ public function create_goals( $goals ) { } } - /** - * @param $old_settings - * @param $settings - * - * @return void - * @codeCoverageIgnore Because we don't want to test the API. - */ - public function maybe_create_woocommerce_funnel( $old_settings, $settings ) { - if ( ! Helpers::is_enhanced_measurement_enabled( 'revenue', $settings[ 'enhanced_measurements' ] ) || ! Integrations::is_wc_active() ) { - return; // @codeCoverageIgnore - } - - $goals = []; - $woocommerce = new WooCommerce( false ); - - foreach ( $woocommerce->event_goals as $event_key => $event_goal ) { - // Don't add this goal to the funnel. Create it separately instead. - if ( $event_key === 'remove-from-cart' ) { - $this->create_goals( [ $this->create_goal_request( $event_goal ) ] ); - - continue; - } - - if ( $event_key === 'purchase' ) { - $goals[] = $this->create_goal_request( $event_goal, 'Revenue', get_woocommerce_currency() ); - - continue; - } - - if ( $event_key === 'view-product' ) { - $goals[] = $this->create_goal_request( $event_goal, 'Pageview', null, '/product*' ); - - continue; - } - - $goals[] = $this->create_goal_request( $event_goal ); - } - - $this->create_funnel( __( 'Woo Purchase Funnel', 'plausible-analytics' ), $goals ); - } - /** * Creates a funnel and creates goals if they don't exist. * @@ -336,41 +295,6 @@ public function maybe_delete_goals( $old_settings, $settings ) { update_option( 'plausible_analytics_enhanced_measurements_goal_ids', $goals ); } - /** - * Delete all custom WooCommerce event goals if Revenue setting is disabled. The funnel is deleted when the minimum - * required no. of goals is no longer met. - * - * @param $old_settings - * @param $settings - * - * @return void - * @codeCoverageIgnore Because we don't want to test if the API is working. - */ - public function maybe_delete_woocommerce_goals( $old_settings, $settings ) { - $enhanced_measurements = array_filter( $settings[ 'enhanced_measurements' ] ); - - // Setting is enabled, no need to continue. - if ( Helpers::is_enhanced_measurement_enabled( 'revenue', $enhanced_measurements ) ) { - return; - } - - $goals = get_option( 'plausible_analytics_enhanced_measurements_goal_ids', [] ); - $woo_integration = new WooCommerce( false ); - - foreach ( $goals as $id => $name ) { - $key = $this->array_search_contains( $name, $woo_integration->event_goals ); - - if ( $key ) { - $this->client->delete_goal( $id ); - - unset( $goals[ $id ] ); - } - } - - // Refresh the stored IDs in the DB. - update_option( 'plausible_analytics_enhanced_measurements_goal_ids', $goals ); - } - /** * Searches an array for the presence of $string within each element's value. Strips currencies using a regex, e.g. * (USD), because these are added to revenue goals by Plausible. @@ -387,7 +311,7 @@ public function array_search_contains( $string, $haystack ) { } foreach ( $haystack as $key => $value ) { - if ( strpos( $value, $string ) !== false ) { + if ( str_contains( $value, $string ) ) { return $key; } } From 74f686c756100833dd6a82ae39dc7388ef10e73b Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:22:40 +0100 Subject: [PATCH 3/5] Added: migration script to make sure custom props, funnel and goals are created if Revenue enhanced measurement is already enabled after plugin update. --- src/Admin/Upgrades.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Admin/Upgrades.php b/src/Admin/Upgrades.php index 75e06ef..f3aae29 100644 --- a/src/Admin/Upgrades.php +++ b/src/Admin/Upgrades.php @@ -10,6 +10,7 @@ namespace Plausible\Analytics\WP\Admin; use Exception; +use Plausible\Analytics\WP\Admin\Provisioning\Integrations; use Plausible\Analytics\WP\Helpers; /** @@ -77,6 +78,10 @@ public function run() { $this->upgrade_to_210(); } + if ( version_compare( $plausible_analytics_version, '2.3.0', '<' ) ) { + $this->upgrade_to_230(); + } + // Add required upgrade routines for future versions here. } @@ -254,7 +259,7 @@ private function upgrade_to_203() { } /** - * v2.0.8 and older contained a bug that + * v2.0.8 and older contained a bug that caused the Enhanced Measurement option to not be an array in some cases. * * @return void */ @@ -269,4 +274,25 @@ public function upgrade_to_210() { update_option( 'plausible_analytics_version', '2.1.0' ); } + + /** + * If EDD is active and Ecommerce is enabled, create goals after updating the plugin. + * + * @since v2.3.0 + * + * @return void + */ + public function upgrade_to_230() { + $settings = Helpers::get_settings(); + + if ( Helpers::is_enhanced_measurement_enabled( 'revenue' ) ) { + $edd_provisioning = new Provisioning\Integrations\EDD( new Integrations() ); + $provisioning = new Provisioning(); + + $provisioning->maybe_create_custom_properties( [], $settings ); + $edd_provisioning->maybe_create_edd_funnel( [], $settings ); + } + + update_option( 'plausible_analytics_version', '2.3.0' ); + } } From 4fa60435c66ff4921a319ec5844394bc552ff420 Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:23:53 +0100 Subject: [PATCH 4/5] This code doesn't have to be tested. --- src/Admin/Upgrades.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Admin/Upgrades.php b/src/Admin/Upgrades.php index f3aae29..2b26567 100644 --- a/src/Admin/Upgrades.php +++ b/src/Admin/Upgrades.php @@ -262,6 +262,7 @@ private function upgrade_to_203() { * v2.0.8 and older contained a bug that caused the Enhanced Measurement option to not be an array in some cases. * * @return void + * @codeCoverageIgnore */ public function upgrade_to_210() { $settings = Helpers::get_settings(); @@ -281,6 +282,7 @@ public function upgrade_to_210() { * @since v2.3.0 * * @return void + * @codeCoverageIgnore */ public function upgrade_to_230() { $settings = Helpers::get_settings(); From 58924f8c455d047a59ea65fb5724b3e6a26da6b1 Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:27:48 +0100 Subject: [PATCH 5/5] This code doesn't have to be tested. --- src/Admin/Upgrades.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Admin/Upgrades.php b/src/Admin/Upgrades.php index 2b26567..6ee7206 100644 --- a/src/Admin/Upgrades.php +++ b/src/Admin/Upgrades.php @@ -279,10 +279,11 @@ public function upgrade_to_210() { /** * If EDD is active and Ecommerce is enabled, create goals after updating the plugin. * - * @since v2.3.0 + * @since v2.3.0 * * @return void - * @codeCoverageIgnore + * + * @codeCoverageIgnore because all we'd be doing is testing the Plugins API. */ public function upgrade_to_230() { $settings = Helpers::get_settings();