diff --git a/bootstrap.php b/bootstrap.php index 605708cb3..691e68fb3 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -24,50 +24,6 @@ return; } -/** - * Check if platform is Jarvis - * - * @return bool - */ -function bluehost_is_jarvis() { - $is_jarvis = false; - $host = array( - 'dirs' => explode( '/', ABSPATH ), - 'user' => get_current_user(), - 'homedir' => null, - 'info_file' => null, - ); - - // Build host's home directory - foreach ( $host['dirs'] as $dir ) { - if ( ! empty( $dir ) ) { - $host['homedir'] = $host['homedir'] . '/' . $dir; - - if ( $dir === $host['user'] ) { - break; - } - } - } - - // Check for Jarvis .host-info file - if ( file_exists( $host['homedir'] . '/.host-info' ) ) { - $host['info_file'] = file_get_contents( $host['homedir'] . '/.host-info' ); - } - - // Check for Jarvis platform - if ( - null !== $host['info_file'] - && ( - false !== stripos( $host['info_file'], 'platform = jarvis' ) - || false !== stripos( $host['info_file'], 'platform=jarvis' ) - ) - ) { - $is_jarvis = true; - } - - return $is_jarvis; -} - /* * Initialize coming soon module via container */ @@ -100,15 +56,6 @@ function () { 'bluehost' ); -$bluehost_module_container->set( - 'isJarvis', - $bluehost_module_container->computed( - function () { - return bluehost_is_jarvis(); - } - ) -); - // properly get branding links depending on market $wordpress_hosting_page = ( get_option( 'mm_brand' ) === 'Bluehost_India' ) ? 'https://www.bluehost.in?utm_source=coming-soon-template&utm_medium=bluehost_plugin' : 'https://bluehost.com?utm_source=coming-soon-template&utm_medium=bluehost_plugin'; $my_panel = ( get_option( 'mm_brand' ) === 'Bluehost_India' ) ? 'https://my.bluehost.in/web-hosting/cplogin' : 'https://my.bluehost.com/web-hosting/cplogin'; diff --git a/inc/Data.php b/inc/Data.php index 79c07c6d3..33467e8e1 100644 --- a/inc/Data.php +++ b/inc/Data.php @@ -22,7 +22,6 @@ public static function runtime() { global $bluehost_module_container; $runtime = array( - 'isJarvis' => $bluehost_module_container->get('isJarvis'), 'plugin' => array( 'url' => BLUEHOST_BUILD_URL, 'version' => BLUEHOST_PLUGIN_VERSION, diff --git a/src/app/data/help.js b/src/app/data/help.js index 620e66501..a3b045214 100644 --- a/src/app/data/help.js +++ b/src/app/data/help.js @@ -2,7 +2,7 @@ import { NewfoldRuntime } from "@newfold-labs/wp-module-runtime"; import { getPlatformBaseUrl } from "../util/helpers"; const getSupportPhoneNumber = () => { - const brand = NewfoldRuntime.sdk.plugin.brand; + const brand = NewfoldRuntime.plugin.brand; if ( brand === 'Bluehost_India' ) { return '1800-419-4426'; diff --git a/src/app/index.js b/src/app/index.js index 34fde0533..5a76e57b3 100644 --- a/src/app/index.js +++ b/src/app/index.js @@ -71,7 +71,7 @@ const AppBody = ( props ) => { id="wppbh-app-rendered" className={ classnames( 'wpadmin-brand-bluehost', - `wppbh-wp-${ NewfoldRuntime.sdk.wpversion }`, + `wppbh-wp-${ NewfoldRuntime.wpVersion }`, `wppbh-page-${ kebabCase( location.pathname ) }`, props.className, 'nfd-w-full nfd-p-4 min-[783px]:nfd-p-0' diff --git a/src/app/pages/home/accountCard.js b/src/app/pages/home/accountCard.js index 986575c3f..f862cdeec 100644 --- a/src/app/pages/home/accountCard.js +++ b/src/app/pages/home/accountCard.js @@ -8,17 +8,15 @@ import { } from "@heroicons/react/24/outline"; import { NewfoldRuntime } from "@newfold-labs/wp-module-runtime"; import { Card, Title } from "@newfold/ui-component-library"; -import { addUtmParams, getPlatformPathUrl, getPlatformBaseUrl } from "../../util/helpers"; +import { addUtmParams, getPlatformPathUrl, getPlatformBaseUrl, isJarvis } from "../../util/helpers"; import classNames from "classnames"; -const isJarvis = NewfoldRuntime.sdk.isJarvis; - const base = [ { icon: CpuChipIcon, id: "account_link", href: addUtmParams( getPlatformPathUrl("hosting/list", "app") ), - label: isJarvis + label: isJarvis() ? __("Hosting", "bluehost-wordpress-plugin") : __("Control Panel", "bluehost-wordpress-plugin"), color: "nfd-fill-gray", @@ -27,7 +25,7 @@ const base = [ icon: GiftIcon, id: "products_link", href: addUtmParams( getPlatformPathUrl("renewal-center", "account_center#products") ), - label: isJarvis + label: isJarvis() ? __("Renewal Center", "bluehost-wordpress-plugin") : __("Products", "bluehost-wordpress-plugin"), color: "nfd-fill-primary-dark", @@ -36,7 +34,7 @@ const base = [ icon: CreditCardIcon, id: "billing_link", href: addUtmParams( getPlatformPathUrl("billing-center", "account_center#billing") ), - label: isJarvis + label: isJarvis() ? __("Payment Methods", "bluehost-wordpress-plugin") : __("Billing", "bluehost-wordpress-plugin"), color: "nfd-fill-primary", @@ -45,7 +43,7 @@ const base = [ icon: EnvelopeIcon, id: "mail_link", href: addUtmParams( getPlatformPathUrl("home", "app#/email-office") ), - label: isJarvis + label: isJarvis() ? __("Mail", "bluehost-wordpress-plugin") : __("Mail & Office", "bluehost-wordpress-plugin"), color: "nfd-fill-[#5b5b5b]", @@ -60,10 +58,10 @@ const base = [ { icon: IdentificationIcon, id: "validation_token_link", - href: isJarvis + href: isJarvis() ? addUtmParams( getPlatformPathUrl("account-center") ) : addUtmParams( getPlatformBaseUrl("/cgi/token") ), - label: isJarvis + label: isJarvis() ? __("Profile", "bluehost-wordpress-plugin") : __("Validation Token", "bluehost-wordpress-plugin"), color: "nfd-fill-[#f89c24]", diff --git a/src/app/util/helpers.js b/src/app/util/helpers.js index 7f24dd49f..430fb0851 100644 --- a/src/app/util/helpers.js +++ b/src/app/util/helpers.js @@ -167,15 +167,14 @@ export const addUtmParams = (url, params = {}) => { * @return {string} */ export const getPlatformBaseUrl = ( path = '' ) => { - const brand = NewfoldRuntime.sdk.plugin.brand; - const isJarvis = NewfoldRuntime.sdk.isJarvis; + const brand = NewfoldRuntime.plugin.brand; const baseUrl = () => { if (brand === 'Bluehost_India') { return 'https://my.bluehost.in'; } - if (isJarvis) { + if (isJarvis()) { return 'https://www.bluehost.com'; } @@ -198,9 +197,8 @@ export const getPlatformBaseUrl = ( path = '' ) => { * // returns https://www.bluehost.com/my-account/home if Jarvis or https://my.bluehost.com/hosting/app#home if legacy */ export const getPlatformPathUrl = ( jarvisPath = '', legacyPath = '' ) => { - const isJarvis = NewfoldRuntime.sdk.isJarvis; - if (isJarvis) { + if (isJarvis()) { return getPlatformBaseUrl('/my-account/') + jarvisPath; } @@ -225,3 +223,18 @@ export const handleHelpLinksClick = () => { } } }; + +/** + * Check if this is a jarvis site or not. + * Deafults to true in cases where the capabilites are not set such as + * in local and test environments that do not receive capabilities. + * + * @return boolean + */ +export const isJarvis = () => { + if ( NewfoldRuntime.hasCapability( 'isJarvis' ) ) { + return NewfoldRuntime.capabilities.isJarvis; + } else { + return true; + } +}; \ No newline at end of file