Skip to content

Commit

Permalink
Merge pull request #397 from bluehost/update-jarvis-detection
Browse files Browse the repository at this point in the history
Update Jarvis detection logic
  • Loading branch information
circlecube authored Apr 18, 2023
2 parents 424cf27 + a5ae2dc commit eb7e143
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 28 deletions.
25 changes: 24 additions & 1 deletion bluehost-wordpress-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@
require dirname( __FILE__ ) . '/bootstrap.php';
}

/**
* Check if site is hosted on Jarvis
*
* @return bool
*/
function bh_is_jarvis() {
$is_jarvis = false;
$host_root_dir = $_SERVER['CONTEXT_DOCUMENT_ROOT'] . '/..';
$host_file = null;

// Check for Jarvis .host-info file
if ( file_exists( $host_root_dir . '/.host-info' ) ) {
$host_file = file_get_contents( $host_root_dir . '/.host-info' );
}

// Check for Jarvis platform
if ( null !== $host_file && false !== strpos( $host_file, 'platform = jarvis' ) ) {
$is_jarvis = true;
}

return $is_jarvis;
}

/*
* Initialize container values for data module
*/
Expand All @@ -77,7 +100,7 @@ function () {
'id' => 'bluehost',
'file' => BLUEHOST_PLUGIN_FILE,
'brand' => get_option( 'mm_brand', 'bluehost' ),
'platform' => get_option( 'bh_platform', 'legacy' ),
'platform' => bh_is_jarvis() ? 'jarvis' : 'legacy',
'install_date' => get_option( 'bh_plugin_install_date' ),
)
);
Expand Down
26 changes: 0 additions & 26 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,6 @@ function () {
2
);

// Check if Bluehost platform Legacy or Jarvis
if ( ! get_transient( 'bh_platform' ) ) {
$bh_platform = 'legacy';
$bh_host_file = null;

// Check for Jarvis .host-info file
if ( file_exists( ABSPATH . '/.host-info' ) ) {
$bh_host_file = file_get_contents( ABSPATH . '/.host-info' );
} elseif ( file_exists( ABSPATH . '../.host-info' ) ) {
$bh_host_file = file_get_contents( ABSPATH . '../.host-info' );
}

// Check for Jarvis platform
if ( null !== $bh_host_file && false !== strpos( $bh_host_file, 'platform=jarvis' ) ) {
$bh_platform = 'jarvis';
}

if ( ! get_option( 'bh_platform' ) ) {
add_option( 'bh_platform', $bh_platform );
} else {
update_option( 'bh_platform', $bh_platform );
}

set_transient( 'bh_platform', '1', DAY_IN_SECONDS );
}

// Require files
require __DIR__ . '/inc/admin.php';
require __DIR__ . '/inc/admin-page-notifications-blocker.php';
Expand Down
2 changes: 1 addition & 1 deletion inc/admin/class-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function prepareAdminData() {
$hasToken = ! empty( $token );
$hasCustomerId = ! empty( $customerData ) && ! empty( $customerData['customer_id'] );
$showCTBs = $hasToken && $hasCustomerId;
$isJarvis = get_option( 'bh_platform' ) === 'jarvis' ? 'true' : null;
$isJarvis = bh_is_jarvis() ? 'true' : null;

\wp_add_inline_script( 'bh-ctb', 'window.bluehostWpAdminUrl="' . \admin_url() . '";', 'before' );
\wp_add_inline_script( 'bh-ctb', 'window.nfBrandPlatform="' . \get_option( 'mm_brand' ) . '";', 'before' );
Expand Down
13 changes: 13 additions & 0 deletions inc/upgrades/2.13.2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Handle updates for version 2.13.2
*
* Delete bh_platform option since it's no longer used.
*
* @package Bluehost
*/

// Delete existing bh_platform option if found.
if ( get_option( 'bh_platform' ) ) {
delete_option( 'bh_platform' );
}

0 comments on commit eb7e143

Please sign in to comment.