Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/jetpack affiliation - PRESS4-516 #64

Merged
merged 9 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 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\Data\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 @@ -79,6 +80,8 @@ function ( $value ) {
'newfold_container_set',
function ( Container $container ) {

NFD_DATA_MODULE_VERSION === '2.4.21' && nfd_update_options_table( $container );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the upgrade routine approach not work? That is the preferred method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are getting this error - Uncaught NewfoldLabs\Container\NotFoundException : No entry was found for "plugin" identifier.

As we talked about earlier, we're employing a hook call and specifying a version condition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manikantakailasa, I was thinking we would add the hook to the upgrade routine file. So in the 2.4.22.php file, add the newfold_container_set callback and move the code out of the called function into the hook.


register_activation_hook(
$container->plugin()->file,
function () use ( $container ) {
Expand Down Expand Up @@ -137,6 +140,33 @@ function nfd_create_event_queue_table() {
dbDelta( $sql );
}

/**
* Update affiliation code in option table
*
* @param object $container Container information
*/
function nfd_update_options_table( $container ) {
$brand_code = array(
'bluehost' => '86241',
'hostgator' => '57686',
'web' => '86239',
'crazy-domains' => '57687',
'hostgator-india' => '57686',
'bluehost-india' => '86241',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a good way to determine if a site is Bluehost India or HostGator India right now. We can keep this code, but it won't do anything.

'hostgator-latam' => '57686',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HostGator LATAM requires an additional region check to differentiate from normal HostGator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to verify additional regions because we have the same Jetpack affiliation code for all hosts, including Hostgator, Hostgator-India, and Hostgator-Latam?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manikantakailasa Ah, no. Let's remove the hostgator-india, bluehost-india, and hostgator-latam options then, as the other cases will cover these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing hostgator-india, bluehost-india, and hostgator-latam will result in the brands mapping to default and not having their respective Jetpack affiliation codes.

$container->plugin()->id; container will return brand as hostgator-india, bluehost-india, and hostgator-latam

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manikantakailasa The container()->plugin()->id will ONLY return the base brand depending on the plugin:

  • bluehost
  • hostgator
  • crazy-domains
  • web
  • mojo

It is not configured to include any suffixes.

'default' => '86240',
wpscholar marked this conversation as resolved.
Show resolved Hide resolved
);
$brand = $container->plugin()->id;
if ( is_plugin_active( 'jetpack/jetpack.php' ) ) {
if ( empty( $brand ) || ! array_key_exists( $brand, $brand_code ) ) {
$brand = 'default';
}
$jetpack_affiliate_code = get_option( 'jetpack_affiliate_code' );
! $jetpack_affiliate_code &&
update_option( 'jetpack_affiliate_code', $brand_code[ $brand ] );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to fix code formatting here

}
}

/**
* Drop the event queue table
*/
Expand Down
Loading
Loading