Skip to content

Commit

Permalink
Added: migration script to make sure custom props, funnel and goals a…
Browse files Browse the repository at this point in the history
…re created if Revenue enhanced measurement is already enabled after plugin update.
  • Loading branch information
Dan0sz committed Feb 26, 2025
1 parent e0c9b65 commit 74f686c
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/Admin/Upgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Plausible\Analytics\WP\Admin;

use Exception;
use Plausible\Analytics\WP\Admin\Provisioning\Integrations;
use Plausible\Analytics\WP\Helpers;

/**
Expand Down Expand Up @@ -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.
}

Expand Down Expand Up @@ -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
*/
Expand All @@ -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' );
}
}

0 comments on commit 74f686c

Please sign in to comment.