From cf857c28e8184f8536c2b78cf8c61ac9822a98ec Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Mon, 30 Oct 2023 11:46:00 -0400 Subject: [PATCH 1/4] remove host-info jarvis check --- bootstrap.php | 53 --------------------------------------------------- inc/Data.php | 1 - 2 files changed, 54 deletions(-) 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, From d20a84e6f85d1581addafb76c3db50dcbe24ab3a Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Mon, 30 Oct 2023 11:46:29 -0400 Subject: [PATCH 2/4] update app isJarvis checks to use capabilities rather than sdk value for isJarvis --- src/app/pages/home/accountCard.js | 2 +- src/app/util/helpers.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/pages/home/accountCard.js b/src/app/pages/home/accountCard.js index 986575c3f..725207d69 100644 --- a/src/app/pages/home/accountCard.js +++ b/src/app/pages/home/accountCard.js @@ -11,7 +11,7 @@ import { Card, Title } from "@newfold/ui-component-library"; import { addUtmParams, getPlatformPathUrl, getPlatformBaseUrl } from "../../util/helpers"; import classNames from "classnames"; -const isJarvis = NewfoldRuntime.sdk.isJarvis; +const isJarvis = NewfoldRuntime.capabilities.isJarvis; const base = [ { diff --git a/src/app/util/helpers.js b/src/app/util/helpers.js index 7f24dd49f..60e3991db 100644 --- a/src/app/util/helpers.js +++ b/src/app/util/helpers.js @@ -168,7 +168,7 @@ export const addUtmParams = (url, params = {}) => { */ export const getPlatformBaseUrl = ( path = '' ) => { const brand = NewfoldRuntime.sdk.plugin.brand; - const isJarvis = NewfoldRuntime.sdk.isJarvis; + const isJarvis = NewfoldRuntime.capabilities.isJarvis; const baseUrl = () => { if (brand === 'Bluehost_India') { @@ -198,7 +198,7 @@ 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; + const isJarvis = NewfoldRuntime.capabilities.isJarvis; if (isJarvis) { return getPlatformBaseUrl('/my-account/') + jarvisPath; From 2e950a3901e41c467a5b26723f0da5469fc12def Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Mon, 30 Oct 2023 11:50:57 -0400 Subject: [PATCH 3/4] also update other references to values in sdk object in favor of newer values. --- src/app/data/help.js | 2 +- src/app/index.js | 2 +- src/app/util/helpers.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/util/helpers.js b/src/app/util/helpers.js index 60e3991db..a36356d92 100644 --- a/src/app/util/helpers.js +++ b/src/app/util/helpers.js @@ -167,7 +167,7 @@ export const addUtmParams = (url, params = {}) => { * @return {string} */ export const getPlatformBaseUrl = ( path = '' ) => { - const brand = NewfoldRuntime.sdk.plugin.brand; + const brand = NewfoldRuntime.plugin.brand; const isJarvis = NewfoldRuntime.capabilities.isJarvis; const baseUrl = () => { From eb83de17472211b9e8f7ad8b9f526207462daf88 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Mon, 30 Oct 2023 16:10:20 -0400 Subject: [PATCH 4/4] create helper method for isJarvis capabilities check and default to true (for local and test envs) --- src/app/pages/home/accountCard.js | 16 +++++++--------- src/app/util/helpers.js | 21 +++++++++++++++++---- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/app/pages/home/accountCard.js b/src/app/pages/home/accountCard.js index 725207d69..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.capabilities.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 a36356d92..430fb0851 100644 --- a/src/app/util/helpers.js +++ b/src/app/util/helpers.js @@ -168,14 +168,13 @@ export const addUtmParams = (url, params = {}) => { */ export const getPlatformBaseUrl = ( path = '' ) => { const brand = NewfoldRuntime.plugin.brand; - const isJarvis = NewfoldRuntime.capabilities.isJarvis; 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.capabilities.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