Skip to content

Commit

Permalink
auto upgrade brand code affiliation
Browse files Browse the repository at this point in the history
  • Loading branch information
manikantakailasa committed Mar 20, 2024
1 parent f1389ab commit 3294233
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
10 changes: 9 additions & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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
*/
Expand Down
28 changes: 28 additions & 0 deletions includes/Listeners/Jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
}
}
}
3 changes: 3 additions & 0 deletions upgrades/2.4.21.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

nfd_update_options_table();

0 comments on commit 3294233

Please sign in to comment.