diff --git a/bluehost-wordpress-plugin.php b/bluehost-wordpress-plugin.php index eff9b6aca..4910201d3 100644 --- a/bluehost-wordpress-plugin.php +++ b/bluehost-wordpress-plugin.php @@ -2,7 +2,7 @@ /** * Plugin Name: The Bluehost Plugin * Description: This plugin integrates your WordPress site with the Bluehost control panel, including performance, security, and update features. - * Version: 2.13.2 + * Version: 2.13.3 * Tested up to: 6.2 * Requires at least: 5.9 * Requires PHP: 7.0 @@ -18,6 +18,8 @@ use NewfoldLabs\WP\ModuleLoader\Container; use NewfoldLabs\WP\ModuleLoader\Plugin; +// use NewfoldLabs\WP\Module\CustomerBluehost\CustomerBluehost; +use Bluehost\SiteMeta; use function NewfoldLabs\WP\ModuleLoader\container as setContainer; @@ -33,7 +35,7 @@ } // Define constants -define( 'BLUEHOST_PLUGIN_VERSION', '2.13.2' ); +define( 'BLUEHOST_PLUGIN_VERSION', '2.13.3' ); define( 'BLUEHOST_PLUGIN_FILE', __FILE__ ); define( 'BLUEHOST_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'BLUEHOST_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); @@ -122,6 +124,8 @@ function () { 'file' => BLUEHOST_PLUGIN_FILE, 'brand' => get_option( 'mm_brand', 'bluehost' ), 'install_date' => get_option( 'bh_plugin_install_date' ), + // 'customer' => CustomerBluehost::collect(), + 'site_id' => SiteMeta::get_id(), ) ); } diff --git a/bootstrap.php b/bootstrap.php index 4b998d238..b5c5fbfa8 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -74,7 +74,6 @@ function () { require __DIR__ . '/inc/cli-init.php'; require __DIR__ . '/inc/jetpack.php'; require __DIR__ . '/inc/menu.php'; -require __DIR__ . '/inc/CTB/bootstrap.php'; require __DIR__ . '/inc/partners.php'; require __DIR__ . '/inc/performance.php'; require __DIR__ . '/inc/track-last-login.php'; diff --git a/composer.json b/composer.json index d46a51de8..50904bbed 100644 --- a/composer.json +++ b/composer.json @@ -38,13 +38,14 @@ "doctrine/inflector": "1.2.0 as 1.3.1", "newfold-labs/wp-module-business-reviews": "^1.1", "newfold-labs/wp-module-coming-soon": "^1.1.3", + "newfold-labs/wp-module-ctb": "^1.0.0", "newfold-labs/wp-module-customer-bluehost": "^1.5.3", "newfold-labs/wp-module-data": "^2.3.0", "newfold-labs/wp-module-ecommerce": "0.8.2", "newfold-labs/wp-module-loader": "^1.0.10", - "newfold-labs/wp-module-marketplace": "^1.5.0", + "newfold-labs/wp-module-marketplace": "^1.5.1", "newfold-labs/wp-module-notifications": "^1.1.2", - "newfold-labs/wp-module-onboarding": "1.3.0", + "newfold-labs/wp-module-onboarding": "1.4.1", "newfold-labs/wp-module-secure-passwords": "^1.1", "newfold-labs/wp-module-sso": "^1.0.3", "wp-forge/collection": "^1.0.2", diff --git a/composer.lock b/composer.lock index 15e1f1321..8999c0a9f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "15db393879dcc84112f27c147695299b", + "content-hash": "a902ceffef4f0efaca2bf3672a8c9f7c", "packages": [ { "name": "doctrine/inflector", @@ -249,6 +249,56 @@ }, "time": "2023-04-19T19:31:25+00:00" }, + { + "name": "newfold-labs/wp-module-ctb", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/newfold-labs/wp-module-ctb.git", + "reference": "949e785b815d55eda15ad0d06dc7a25d83803a93" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/newfold-labs/wp-module-ctb/zipball/949e785b815d55eda15ad0d06dc7a25d83803a93", + "reference": "949e785b815d55eda15ad0d06dc7a25d83803a93", + "shasum": "" + }, + "require-dev": { + "newfold-labs/wp-php-standards": "^1.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "NewfoldLabs\\WP\\Module\\CTB\\": "includes" + }, + "files": [ + "bootstrap.php" + ] + }, + "scripts": { + "fix": [ + "vendor/bin/phpcbf . --standard=phpcs.xml" + ], + "lint": [ + "vendor/bin/phpcs . --standard=phpcs.xml -s" + ] + }, + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "Evan Mullins", + "homepage": "https://evanmullins.com" + } + ], + "description": "Newfold module for 'Click to Buy' functionality in brand plugins", + "support": { + "source": "https://github.com/newfold-labs/wp-module-ctb/tree/1.0.0", + "issues": "https://github.com/newfold-labs/wp-module-ctb/issues" + }, + "time": "2023-04-21T20:08:32+00:00" + }, { "name": "newfold-labs/wp-module-customer-bluehost", "version": "1.5.3", @@ -442,16 +492,16 @@ }, { "name": "newfold-labs/wp-module-marketplace", - "version": "1.5.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/newfold-labs/wp-module-marketplace.git", - "reference": "98b21eb5fc9ac1c78eb8bc61e674b45a682739f3" + "reference": "9d2e43d375db62f88f0963a19674f0b4f50116bd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/newfold-labs/wp-module-marketplace/zipball/98b21eb5fc9ac1c78eb8bc61e674b45a682739f3", - "reference": "98b21eb5fc9ac1c78eb8bc61e674b45a682739f3", + "url": "https://api.github.com/repos/newfold-labs/wp-module-marketplace/zipball/9d2e43d375db62f88f0963a19674f0b4f50116bd", + "reference": "9d2e43d375db62f88f0963a19674f0b4f50116bd", "shasum": "" }, "require": { @@ -492,10 +542,10 @@ ], "description": "A module for rendering product data and interacting with the Hiive marketplace API.", "support": { - "source": "https://github.com/newfold-labs/wp-module-marketplace/tree/1.5.0", + "source": "https://github.com/newfold-labs/wp-module-marketplace/tree/1.5.1", "issues": "https://github.com/newfold-labs/wp-module-marketplace/issues" }, - "time": "2023-03-13T15:56:29+00:00" + "time": "2023-04-26T13:31:44+00:00" }, { "name": "newfold-labs/wp-module-notifications", @@ -544,16 +594,16 @@ }, { "name": "newfold-labs/wp-module-onboarding", - "version": "1.3.0", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/newfold-labs/wp-module-onboarding.git", - "reference": "053e660daf5de5c508b856228d498117d1c95f12" + "reference": "8f356fa28a87e05cd2d6b24b4365ef31c2119449" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/newfold-labs/wp-module-onboarding/zipball/053e660daf5de5c508b856228d498117d1c95f12", - "reference": "053e660daf5de5c508b856228d498117d1c95f12", + "url": "https://api.github.com/repos/newfold-labs/wp-module-onboarding/zipball/8f356fa28a87e05cd2d6b24b4365ef31c2119449", + "reference": "8f356fa28a87e05cd2d6b24b4365ef31c2119449", "shasum": "" }, "require": { @@ -593,10 +643,10 @@ ], "description": "Next-generation WordPress Onboarding for WordPress sites at Newfold Digital.", "support": { - "source": "https://github.com/newfold-labs/wp-module-onboarding/tree/1.3.0", + "source": "https://github.com/newfold-labs/wp-module-onboarding/tree/1.4.1", "issues": "https://github.com/newfold-labs/wp-module-onboarding/issues" }, - "time": "2023-04-06T08:04:58+00:00" + "time": "2023-04-25T08:06:41+00:00" }, { "name": "newfold-labs/wp-module-secure-passwords", diff --git a/inc/CTB/CTBApi.php b/inc/CTB/CTBApi.php deleted file mode 100644 index 811eb121e..000000000 --- a/inc/CTB/CTBApi.php +++ /dev/null @@ -1,105 +0,0 @@ -[a-zA-Z0-9-]+)', - array( - 'methods' => \WP_REST_Server::READABLE, - 'permission_callback' => function () { - return current_user_can( 'manage_options' ); - }, - 'callback' => function ( \WP_REST_Request $request ) { - - // Check for customer_id first. If it's not available, then CTB will not work. - $customer_data = CustomerBluehost::collect(); - if ( empty( $customer_data ) || ! isset( $customer_data['customer_id'] ) ) { - return new WP_Error( 500, 'Customer ID is required for CTB' ); - } - - $response = wp_remote_get( - NFD_HIIVE_URL . '/sites/v1/ctb/' . $request->get_param( 'id' ) . '', - array( - 'headers' => array( - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - 'Authorization' => 'Bearer ' . HiiveConnection::get_auth_token(), - ), - 'timeout' => 20, - ) - ); - - if ( $response instanceof WP_Error ) { - return $response; - } - - return new \WP_REST_Response( json_decode( wp_remote_retrieve_body( $response ) ), wp_remote_retrieve_response_code( $response ) ); - }, - ) - ); - - // Add route for purchasing a CTB - register_rest_route( - 'bluehost/v1', - '/ctb/(?P[a-zA-Z0-9-]+)', - array( - 'methods' => \WP_REST_Server::CREATABLE, - 'permission_callback' => function () { - return current_user_can( 'manage_options' ); - }, - 'callback' => function ( \WP_REST_Request $request ) { - - $ctb_id = $request->get_param( 'id' ); - $customer_data = CustomerBluehost::collect(); - if ( empty( $customer_data ) || ! isset( $customer_data['customer_id'] ) ) { - return new WP_Error( 500, 'Customer ID is required to purchase CTB' ); - } - $payload = array( - 'ctb_id' => $ctb_id, - 'customer_id' => $customer_data['customer_id'], - 'site_id' => SiteMeta::get_id(), - ); - - $response = wp_remote_post( - NFD_HIIVE_URL . '/sites/v1/ctb/' . $ctb_id . '/purchase', - array( - 'headers' => array( - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - 'Authorization' => 'Bearer ' . HiiveConnection::get_auth_token(), - ), - 'body' => wp_json_encode( $payload ), - 'timeout' => 20, - ) - ); - - if ( $response instanceof WP_Error ) { - return $response; - } - - return new \WP_REST_Response( json_decode( wp_remote_retrieve_body( $response ) ), wp_remote_retrieve_response_code( $response ) ); - }, - ) - ); - } - -} diff --git a/inc/CTB/bootstrap.php b/inc/CTB/bootstrap.php deleted file mode 100644 index cd9c66c0a..000000000 --- a/inc/CTB/bootstrap.php +++ /dev/null @@ -1,45 +0,0 @@ - esc_url_raw( get_home_url() . '/index.php?rest_route=/' ), - 'restApiNonce' => wp_create_nonce( 'wp_rest' ), - ) - ); - } -); - -add_action( - 'admin_enqueue_scripts', - function() { - wp_enqueue_style( - 'bh-ctb', - plugins_url( 'inc/CTB/ctb.css', BLUEHOST_PLUGIN_FILE ), - array(), - BLUEHOST_PLUGIN_VERSION - ); - } -); - -add_action( - 'admin_footer', - function () { - echo ""; - } -); diff --git a/inc/CTB/ctb.css b/inc/CTB/ctb.css deleted file mode 100644 index bfda1d7ef..000000000 --- a/inc/CTB/ctb.css +++ /dev/null @@ -1,113 +0,0 @@ -body.noscroll { - overflow-y: hidden; -} - -#nfd-ctb-container { - position: absolute; -} - -#nfd-ctb-container, -.ctb-modal-overlay { - position: fixed; - top: 0; - right: 0; - bottom: 0; - left: 0; -} - -#nfd-ctb-container { - z-index: 100000; - display: flex; - justify-content: center; - align-items: center; -} - -#nfd-ctb-container[aria-hidden='true'] { - display: none; -} - -.ctb-modal-overlay { - background-color: rgba(43, 46, 56, 0.9); -} - -.ctb-modal-content { - margin: auto; - padding: 1.25rem; - z-index: 2; - position: relative; - background-color: white; - /* z-index: 20001; */ - min-width: 500px; - max-width: 75%; - min-height: 250px; - background: white; - color: black; - display: flex; - justify-content: center; - align-items: center; -} - -.ctb-modal img { - max-width: 100%; -} - - -.ctb-modal button { - cursor: pointer; -} - -.ctb-loader { - width: 5rem; - height: 5rem; - border-radius: 50%; - background: #3575d3; - background: linear-gradient(to right, #3575d3 5%, rgba(0, 0, 0, 0) 32%); - position: relative; - will-change: transform; - -webkit-animation: ctbloader .9s infinite linear; - animation: ctbloader .9s infinite linear; - transform: translateZ(0); -} - -.ctb-loader:before { - width: 50%; - height: 50%; - background: #3575d3; - border-radius: 100% 0 0 0; - position: absolute; - top: 0; - left: 0; - content: ""; -} - -.ctb-loader:after { - background: #fff; - width: 88%; - height: 88%; - border-radius: 50%; - content: ""; - margin: auto; - position: absolute; - top: 0; - left: 0; - bottom: 0; - right: 0; -} - -@keyframes ctbloader { - 0% { - transform: rotate(0deg); - } - - 100% { - transform: rotate(360deg); - } -} - -@media screen and (max-width: 768px) { - .ctb-modal-content { - padding: 1.1rem; - min-width: 80vw; - max-width: 80vw; - } -} \ No newline at end of file diff --git a/inc/CTB/js/a11y-dialog.min.js b/inc/CTB/js/a11y-dialog.min.js deleted file mode 100644 index 9c774eb53..000000000 --- a/inc/CTB/js/a11y-dialog.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/*! a11y-dialog 7.4.0 — © Kitty Giraudel */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).A11yDialog=e()}(this,(function(){"use strict";var t=['a[href]:not([tabindex^="-"])','area[href]:not([tabindex^="-"])','input:not([type="hidden"]):not([type="radio"]):not([disabled]):not([tabindex^="-"])','input[type="radio"]:not([disabled]):not([tabindex^="-"])','select:not([disabled]):not([tabindex^="-"])','textarea:not([disabled]):not([tabindex^="-"])','button:not([disabled]):not([tabindex^="-"])','iframe:not([tabindex^="-"])','audio[controls]:not([tabindex^="-"])','video[controls]:not([tabindex^="-"])','[contenteditable]:not([tabindex^="-"])','[tabindex]:not([tabindex^="-"])'];function e(t){this._show=this.show.bind(this),this._hide=this.hide.bind(this),this._maintainFocus=this._maintainFocus.bind(this),this._bindKeypress=this._bindKeypress.bind(this),this.$el=t,this.shown=!1,this._id=this.$el.getAttribute("data-a11y-dialog")||this.$el.id,this._previouslyFocused=null,this._listeners={},this.create()}function i(t,e){return i=(e||document).querySelectorAll(t),Array.prototype.slice.call(i);var i}function n(t){(t.querySelector("[autofocus]")||t).focus()}function s(){i("[data-a11y-dialog]").forEach((function(t){new e(t)}))}return e.prototype.create=function(){return this.$el.setAttribute("aria-hidden",!0),this.$el.setAttribute("aria-modal",!0),this.$el.setAttribute("tabindex",-1),this.$el.hasAttribute("role")||this.$el.setAttribute("role","dialog"),this._openers=i('[data-a11y-dialog-show="'+this._id+'"]'),this._openers.forEach(function(t){t.addEventListener("click",this._show)}.bind(this)),this._closers=i("[data-a11y-dialog-hide]",this.$el).concat(i('[data-a11y-dialog-hide="'+this._id+'"]')),this._closers.forEach(function(t){t.addEventListener("click",this._hide)}.bind(this)),this._fire("create"),this},e.prototype.show=function(t){return this.shown||(this._previouslyFocused=document.activeElement,this.$el.removeAttribute("aria-hidden"),this.shown=!0,n(this.$el),document.body.addEventListener("focus",this._maintainFocus,!0),document.addEventListener("keydown",this._bindKeypress),this._fire("show",t)),this},e.prototype.hide=function(t){return this.shown?(this.shown=!1,this.$el.setAttribute("aria-hidden","true"),this._previouslyFocused&&this._previouslyFocused.focus&&this._previouslyFocused.focus(),document.body.removeEventListener("focus",this._maintainFocus,!0),document.removeEventListener("keydown",this._bindKeypress),this._fire("hide",t),this):this},e.prototype.destroy=function(){return this.hide(),this._openers.forEach(function(t){t.removeEventListener("click",this._show)}.bind(this)),this._closers.forEach(function(t){t.removeEventListener("click",this._hide)}.bind(this)),this._fire("destroy"),this._listeners={},this},e.prototype.on=function(t,e){return void 0===this._listeners[t]&&(this._listeners[t]=[]),this._listeners[t].push(e),this},e.prototype.off=function(t,e){var i=(this._listeners[t]||[]).indexOf(e);return i>-1&&this._listeners[t].splice(i,1),this},e.prototype._fire=function(t,e){var i=this._listeners[t]||[],n=new CustomEvent(t,{detail:e});this.$el.dispatchEvent(n),i.forEach(function(t){t(this.$el,e)}.bind(this))},e.prototype._bindKeypress=function(e){this.$el.contains(document.activeElement)&&(this.shown&&27===e.which&&"alertdialog"!==this.$el.getAttribute("role")&&(e.preventDefault(),this.hide(e)),this.shown&&9===e.which&&function(e,n){var s=function(e){return i(t.join(","),e).filter((function(t){return!!(t.offsetWidth||t.offsetHeight||t.getClientRects().length)}))}(e),o=s.indexOf(document.activeElement);n.shiftKey&&0===o?(s[s.length-1].focus(),n.preventDefault()):n.shiftKey||o!==s.length-1||(s[0].focus(),n.preventDefault())}(this.$el,e))},e.prototype._maintainFocus=function(t){!this.shown||t.target.closest('[aria-modal="true"]')||t.target.closest("[data-a11y-dialog-ignore-focus-trap]")||n(this.$el)},"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",s):window.requestAnimationFrame?window.requestAnimationFrame(s):window.setTimeout(s,16)),e})); diff --git a/inc/CTB/js/ctb.js b/inc/CTB/js/ctb.js deleted file mode 100644 index 30d18f03a..000000000 --- a/inc/CTB/js/ctb.js +++ /dev/null @@ -1,145 +0,0 @@ -{ - const purchase = (e) => { - let modalWindow = e.target.closest('.ctb-modal-content'); - let ctbId = e.target.getAttribute('data-ctb-id'); - e.target.closest('.ctb-actions').innerHTML = '
'; - window.fetch( - `${ window.bhctb.restApiUrl }bluehost/v1/ctb/${ ctbId }`, - { - credentials: 'same-origin', - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-WP-Nonce': window.bhctb.restApiNonce, - }, - } - ) - .then( response => { - purchaseStatus = (response.status === 200); - return response.json(); - }).then( data => { - if (data.content) { - modalWindow.innerHTML = data.content; - if (purchaseStatus){ - dismissNotice(ctbId); - } - } else { - displayError(modalWindow, "purchase"); - } - }); - } - - const loadCtb = (e) => { - let modal = openModal(e); - let modalWindow = modal.querySelector('.ctb-modal-content') - window.fetch( - `${ window.bhctb.restApiUrl }bluehost/v1/ctb/${ e.target.getAttribute('data-ctb-id') }`, - { - credentials: 'same-origin', - headers: { - 'Content-Type': 'application/json', - 'X-WP-Nonce': window.bhctb.restApiNonce, - }, - } - ) - .then( response => { - return response.json(); - }).then( data => { - if (data.content) { - modalWindow.innerHTML = data.content; - } else { - displayError(modalWindow, 'load'); - //remove ctb attributes from button so the user can click the link - removeCtbAttrs(e); - } - }); - } - - const removeCtbAttrs = (e) => { - let ctbButton = e.target; - ctbButton.removeAttribute('data-action'); - ctbButton.removeAttribute('data-ctb-id'); - } - - const openModal = (e) => { - let modalContent = ` -
-
-
-
-
-
- `; - let ctbContainer = document.getElementById('nfd-ctb-container'); - if (ctbContainer) { - ctbContainer.innerHTML = modalContent - } else { - ctbContainer = document.createElement('div'); - ctbContainer.setAttribute('id', 'nfd-ctb-container'); - ctbContainer.innerHTML = modalContent; - ctbContainer.target.insertAdjacentElement('afterend', nfd-ctb-container); - } - - ctbmodal = new A11yDialog(ctbContainer); - ctbmodal.show(); - document.querySelector('body').classList.add('noscroll'); - - purchaseStatus = false; - - return ctbContainer; - } - - const closeModal = (e) => { - ctbmodal.destroy(); - document.querySelector('body').classList.remove('noscroll'); - } - - const displayError = (modalWindow, error) => { - let message = (error === 'purchase') ? 'complete the transaction' : 'load the product information'; - modalWindow.innerHTML = `
-

Sorry, we are unable to ${message} at this time.

- -
`; - } - - const dismissNotice = (ctbId) => { - const ctbTrigger = document.querySelector('[data-ctb-id="' + ctbId + '"]') - const notice = ctbTrigger.closest('.bluehost-notice'); - if (notice) { - notice.parentNode.removeChild(notice); - window.fetch( - `${ window.bhctb.restApiUrl }newfold-notifications/v1/notifications/${ notice.dataset.id }`, - { - credentials: 'same-origin', - method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - 'X-WP-Nonce': window.bhctb.restApiNonce, - }, - } - ); - } - } - - window.addEventListener( - 'load', - () => { - document.getElementById('wpwrap').addEventListener('click', function(event) { - if (event.target.dataset.action === 'load-nfd-ctb') { - if ( window.nfdConnected ) { // has token and customer id - event.preventDefault(); - loadCtb(event); - } else { - // do nothing, fallback to href - } - } - if (event.target.dataset.action === 'purchase-ctb') { - purchase(event); - } - if (event.target.hasAttribute('data-a11y-dialog-destroy')) { - closeModal(event.target); - } - }); - } - ); -} diff --git a/inc/admin/class-assets.php b/inc/admin/class-assets.php index c3062a71d..5e769d1ed 100644 --- a/inc/admin/class-assets.php +++ b/inc/admin/class-assets.php @@ -72,16 +72,24 @@ public function register_assets( $hook ) { * for ctb script which loads on all admin */ protected function prepareAdminData() { - $token = get_option( 'nfd_data_token' ); - $customerData = CustomerBluehost::collect(); - $hasToken = ! empty( $token ); - $hasCustomerId = ! empty( $customerData ) && ! empty( $customerData['customer_id'] ); - $showCTBs = $hasToken && $hasCustomerId; - - \wp_add_inline_script( 'bh-ctb', 'window.bluehostWpAdminUrl="' . \admin_url() . '";', 'before' ); - \wp_add_inline_script( 'bh-ctb', 'window.nfBrandPlatform="' . \get_option( 'mm_brand' ) . '";', 'before' ); - \wp_add_inline_script( 'bh-ctb', 'window.nfdRestRoot="' . \get_home_url() . '/index.php?rest_route=";', 'before' ); - \wp_add_inline_script( 'bh-ctb', $showCTBs ? 'window.nfdConnected=true;' : 'window.nfdConnected=false;', 'before' ); + // register placeholder script handle with no source + wp_register_script( 'newfold-plugin', null, null, BLUEHOST_PLUGIN_VERSION, true ); + wp_enqueue_script( 'newfold-plugin' ); + + // add inline scripts to the handle with global js values + \wp_add_inline_script( 'newfold-plugin', 'window.bluehostWpAdminUrl="' . \admin_url() . '";', 'before' ); + \wp_add_inline_script( 'newfold-plugin', 'window.nfBrandPlatform="' . \get_option( 'mm_brand' ) . '";', 'before' ); + \wp_add_inline_script( 'newfold-plugin', 'window.nfdRestRoot="' . \get_home_url() . '/index.php?rest_route=";', 'before' ); + + // place values in nfdplugin object + \wp_localize_script( + 'newfold-plugin', + 'nfdplugin', + array( + 'restApiUrl' => \esc_url_raw( \get_home_url() . '/index.php?rest_route=' ), + 'restApiNonce' => \wp_create_nonce( 'wp_rest' ), + ) + ); } /** @@ -99,7 +107,7 @@ protected function prepareData() { 'pages' => Bluehost_Admin_App_Page::get_top_level_pages(), 'noticesPathsDenyList' => Bluehost_Admin_App_Page::$noticesPathsDenyList, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 'accountId' => mojo_site_bin2hex(), - 'nonce' => wp_create_nonce( mojo_site_bin2hex() ), + 'nonce' => \wp_create_nonce( mojo_site_bin2hex() ), 'customer' => $customerData, ), 'env' => array( diff --git a/src/app/pages/marketplace/index.js b/src/app/pages/marketplace/index.js index e1b356dc4..d51a49986 100644 --- a/src/app/pages/marketplace/index.js +++ b/src/app/pages/marketplace/index.js @@ -51,7 +51,7 @@ function MarketplacePage() { 'resturl': window.nfdRestRoot, 'eventendpoint': '/newfold-data/v1/events/', 'perPage': 12, - 'supportsCTB': window.nfdConnected, + 'supportsCTB': window.nfdctb.supportsCTB, } return ( diff --git a/tests/cypress/integration/ctb.cy.js b/tests/cypress/integration/ctb.cy.js index 5cfccfcd7..f74bb5b10 100644 --- a/tests/cypress/integration/ctb.cy.js +++ b/tests/cypress/integration/ctb.cy.js @@ -6,25 +6,28 @@ describe('Click to buy', function () { cy.intercept({ method: 'GET', - url: /bluehost(\/|%2F)v1(\/|%2F)ctb/, + url: /newfold-ctb(\/|%2F)v1(\/|%2F)ctb/, },{ fixture: 'ctbGET' }).as('ctbGET'); cy.intercept({ method: 'POST', - url: /bluehost(\/|%2F)v1(\/|%2F)ctb/, + url: /newfold-ctb(\/|%2F)v1(\/|%2F)ctb/, }, { fixture: 'ctbPOST' }).as('ctbPOST'); cy.visit('/wp-admin/admin.php?page=bluehost#/marketplace/plugins/yoast-seo-premium', { onBeforeLoad(contentWindow) { - // set nfdConnected to true, so the ctb click will pass to the endpoint and be intercepted - Object.defineProperty(contentWindow, 'nfdConnected', { + let nfdctb = { + supportsCTB: true + }; + // set supportsCTB to true, so the ctb click will pass to the endpoint and be intercepted + Object.defineProperty(contentWindow, 'nfdctb', { configurable: false, writable: false, - value: true + value: nfdctb }); } }); diff --git a/tests/cypress/integration/z-newfold-labs/wp-module-onboarding/branding.cy.js b/tests/cypress/integration/z-newfold-labs/wp-module-onboarding/branding.cy.js index f38213e5c..371a2f60a 100644 --- a/tests/cypress/integration/z-newfold-labs/wp-module-onboarding/branding.cy.js +++ b/tests/cypress/integration/z-newfold-labs/wp-module-onboarding/branding.cy.js @@ -5,14 +5,16 @@ describe( 'Branding', function () { cy.visit( 'wp-admin/index.php?page=nfd-onboarding&flow=ecommerce' ); } ); - it( 'Has Newfold CSS when mm_brand does not exist.', () => { + // since we are setting brand from plugin container, it will not be set to "newfold" + // by default even if mm_brand option is deleted from the database + it( 'Has Bluehost CSS when mm_brand does not exist.', () => { cy.exec( 'npx wp-env run cli wp option delete mm_brand' ); cy.reload(); - cy.get( 'body' ).should( 'have.class', 'nfd-brand-newfold' ); + cy.get( 'body' ).should( 'have.class', 'nfd-brand-bluehost' ); cy.get( '.is-bg-primary' ) - .should( 'have.css', 'background-color', 'rgb(221, 82, 40)' ) - .should( 'have.css', 'color', 'rgb(242, 242, 242)' ); - cy.get( '.nfd-step-card-subheading' ).should( 'contain', 'undefined' ); + .should( 'have.css', 'background-color', 'rgb(53, 117, 211)' ) + .should( 'have.css', 'color', 'rgb(255, 255, 255)' ); + cy.get( '.nfd-step-card-subheading' ).should( 'contain', 'Bluehost' ); } ); it( 'Has Newfold CSS when mm_brand has an empty value', () => {