diff --git a/bootstrap.php b/bootstrap.php index 062687f..7d66947 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -3,6 +3,7 @@ use NewfoldLabs\WP\Module\Data\Data; use NewfoldLabs\WP\Module\Data\Helpers\Encryption; use NewfoldLabs\WP\Module\Data\Helpers\Transient; +use NewfoldLabs\WP\Module\Listeners\Jetpack; use NewfoldLabs\WP\Module\Data\SiteCapabilities; use NewfoldLabs\WP\ModuleLoader\Container; use WP_Forge\UpgradeHandler\UpgradeHandler; @@ -19,7 +20,7 @@ return; } -define( 'NFD_DATA_MODULE_VERSION', '2.4.20' ); +define( 'NFD_DATA_MODULE_VERSION', '2.4.21' ); if ( function_exists( 'is_admin' ) && is_admin() ) { $upgrade_handler = new UpgradeHandler( @@ -137,6 +138,13 @@ function nfd_create_event_queue_table() { dbDelta( $sql ); } +/** + * Update affiliation code in option table + */ +function nfd_update_options_table() { + ( new Jetpack() )->auto_upgrade_brand_code(); +} + /** * Drop the event queue table */ diff --git a/includes/Listeners/Jetpack.php b/includes/Listeners/Jetpack.php index eefa761..3f22134 100644 --- a/includes/Listeners/Jetpack.php +++ b/includes/Listeners/Jetpack.php @@ -133,4 +133,32 @@ public function detect_plugin_activation( $plugin ) { update_option( 'jetpack_affiliate_code', $this->brand_code[ $brand ] ); } } + + /** + * Update affiliation code in option table + */ + public function auto_upgrade_brand_code() { + $container = container(); + $plugin_brand_map = array( + 'bluehost-wordpress-plugin/bluehost-wordpress-plugin.php' => 'bluehost', + 'wp-plugin-hostgator/wp-plugin-hostgator.php' => 'hostgator', + 'wp-plugin-crazy-domains/wp-plugin-crazy-domains.php' => 'crazy-domains', + 'wp-plugin-web/wp-plugin-web.php' => 'web', + ); + $brand = ''; + if ( is_plugin_active( 'jetpack/jetpack.php' ) ) { + foreach ( $plugin_brand_map as $plugin => $brand_name ) { + if ( is_plugin_active( $plugin ) ) { + $brand = $brand_name; + break; + } + } + if ( empty( $brand ) || ! array_key_exists( $brand, $this->brand_code ) ) { + $brand = 'default'; + } + $jetpack_affiliate_code = get_option( 'jetpack_affiliate_code' ); + ! $jetpack_affiliate_code && + update_option( 'jetpack_affiliate_code', $this->brand_code[ $brand ] ); + } + } } diff --git a/upgrades/2.4.21.php b/upgrades/2.4.21.php new file mode 100644 index 0000000..dc9fcb4 --- /dev/null +++ b/upgrades/2.4.21.php @@ -0,0 +1,3 @@ +