diff --git a/hubspot-form-block.php b/hubspot-form-block.php index f62437c..238d0fa 100644 --- a/hubspot-form-block.php +++ b/hubspot-form-block.php @@ -30,9 +30,11 @@ function block_init() { add_action( 'init', __NAMESPACE__ . '\\block_init' ); function register_scripts() { + $region = get_option( 'hubspot_embed_region', 'eu1' ) === 'eu1' ? 'js-eu1' : 'js'; + wp_register_script( 'hs-forms', - 'https://js.hsforms.net/forms/v2.js', + sprintf( 'https://%s.hsforms.net/forms/embed/v2.js', $region ), [], null, [ 'strategy' => 'async' ] @@ -59,11 +61,11 @@ function enqueue_scripts() { return; } - $region = get_option( 'hubspot_embed_region', 'eu1' ); + $region = get_option( 'hubspot_embed_region', 'eu1' ) === 'eu1' ? 'js-eu1' : 'js'; wp_enqueue_script( 'hs-script-loader', - sprintf( 'https://js-%s.hs-scripts.com/%s.js', $region, $portal_id ), + sprintf( 'https://%s.hs-scripts.com/%s.js', $region, $portal_id ), [], null, [ diff --git a/src/render.php b/src/render.php index 8fc3b11..5ca4d7b 100644 --- a/src/render.php +++ b/src/render.php @@ -2,6 +2,7 @@ global $hubspot_form_block_instance_ids; $portal_id = $attributes['portalId'] ?: get_option( 'hubspot_embed_portal_id' ); +$region = $attributes['region'] ?: get_option( 'hubspot_embed_region', 'eu1' ); $form_id = $attributes['formId'] ?: ''; if ( empty( $portal_id ) || empty( $form_id ) ) { @@ -28,6 +29,7 @@ // Generate config object. $config = [ 'portalId' => $portal_id, + 'region' => $region, 'formId' => $form_id, 'locale' => mb_substr( get_locale(), 0, 2 ), 'target' => sprintf( '#%s', $target ),