From 78d3acb74c46180e058858b9b69db59f04d4bb27 Mon Sep 17 00:00:00 2001 From: Michael Thomas Date: Fri, 18 Feb 2022 13:48:59 -0500 Subject: [PATCH] Store Cognito base url solely in api.php --- api.php | 2 +- cognito-forms.php | 6 ++++++ src/globals.ts | 10 +++++++++- templates/main.php | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/api.php b/api.php index f347647..7e9b957 100644 --- a/api.php +++ b/api.php @@ -19,7 +19,7 @@ // Cognito API access if ( !class_exists('CognitoAPI') ) { class CognitoAPI { - public static $formsBase = 'https://www.cognitoforms.com/'; + public static $formsBase = 'https://cognitoforms.com/'; // Convert MS GUID to Short GUID private static function guid_to_short_guid($guid) { diff --git a/cognito-forms.php b/cognito-forms.php index 47d141b..d1dceea 100644 --- a/cognito-forms.php +++ b/cognito-forms.php @@ -142,6 +142,12 @@ if ( !class_exists( 'CognitoFormsPlugin' ) ) { $asset_file['version'] ); + wp_add_inline_script( + 'cognito-block-editor-js', + 'window.COGNITO_BASEURL = "' . CognitoAPI::$formsBase . '";', + 'before' + ); + // Register block editor styles for backend. wp_register_style( 'cognito-block-editor-css', // Handle. diff --git a/src/globals.ts b/src/globals.ts index 8867fc3..65d2b43 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -1 +1,9 @@ -export const baseUrl = 'https://forms.cognito.test'; +declare const COGNITO_BASEURL: string; + +let baseUrl: string; +if ( window.hasOwnProperty( 'COGNITO_BASEURL' ) ) + baseUrl = COGNITO_BASEURL; +else + baseUrl = 'https://www.cognitoforms.com'; + +export { baseUrl }; diff --git a/templates/main.php b/templates/main.php index 5998770..05b9907 100755 --- a/templates/main.php +++ b/templates/main.php @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -$url = 'https://www.cognitoforms.com/'; +$url = CognitoAPI::$formsBase; if ($_GET['page'] == 'CognitoCreateForm') { $url = $url . 'forms/new';