From 4a9d51942d2d7c30c71b975d5c575bf022f8ef30 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 19 Feb 2026 13:05:47 +0800 Subject: [PATCH 1/3] Build and Minify Frontend JS --- DEVELOPMENT.md | 8 +++++++- SETUP.md | 3 ++- TESTING.md | 13 +++++++++++++ composer.json | 6 ++++++ .../class-convertkit-block-broadcasts.php | 8 ++++++-- ...class-convertkit-output-restrict-content.php | 7 ++++--- includes/class-convertkit-output.php | 15 ++++----------- includes/functions.php | 17 +++++++++++++++++ package.json | 7 +++++-- .../frontend/js/dist/frontend.min.asset.php | 1 + resources/frontend/js/dist/frontend.min.js | 1 + resources/frontend/js/frontend.js | 3 +++ 12 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 resources/frontend/js/dist/frontend.min.asset.php create mode 100644 resources/frontend/js/dist/frontend.min.js create mode 100644 resources/frontend/js/frontend.js diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 865fda0f0..3fd608b46 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -60,11 +60,17 @@ Typically, packages listed in this section would be internal development tools f - PHPStan - Codeception +### Build + +Run `npm run build` to compile frontend CSS and JS in one step. + ### CSS Run `npm run watch:css` to compile frontend CSS to `resources/frontend/css/frontend.css` when working on SCSS in the `resources/frontend/scss` folder. -`resources/frontend/css/frontend.css` is excluded from the repo by `.gitignore`; it is built before tests and deployment automatically using GitHub actions. +### JS + +Run `npm run watch:js` to compile frontend JS to `resources/frontend/js/dist/frontend-min.js` when working on JS in the `resources/frontend/js` folder. ## Committing Work diff --git a/SETUP.md b/SETUP.md index 459a9bea6..58507ae8c 100644 --- a/SETUP.md +++ b/SETUP.md @@ -94,7 +94,8 @@ In the Plugin's directory, at the command line, run `npm install`. This sets up: - JS linting / coding standards using WordPress recommended configurations (https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/#lint-js) - SCSS and CSS linting / coding standards using WordPress recommended configurations (https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/#lint-style) -- SASS compilation +- JS compilation and minification +- SASS compilation and minification ### Configure wp-config.php diff --git a/TESTING.md b/TESTING.md index 2c71a28aa..2da6c131f 100644 --- a/TESTING.md +++ b/TESTING.md @@ -32,10 +32,23 @@ The following Composer commands can be used: | `composer watch-css` | `composer watch-css` | Builds the frontend CSS file when changes are made to SCSS files | | `composer js-coding-standards` | `composer lint-js` | Runs WordPress JS Coding Standards on JS files | | `composer fix-js-coding-standards` | `composer fix-js` | Fixes JS files to meet WordPress JS Coding Standards | +| `composer build-js` | `composer build-js` | Builds the frontend JS file | +| `composer watch-js` | `composer watch-js` | Builds the frontend JS file when changes are made to frontend JS files | +| `composer build` | `composer build` | Builds frontend CSS and JS | | `composer static-analysis` | `composer phpstan` | Runs PHPStan static analysis with increased memory limit | | `composer test` | `composer test` | Builds and runs end-to-end tests with `fail-fast` enabled | | `composer test-integration` | `composer test-integration` | Builds and runs integration tests with `fail-fast` enabled | +The following npm commands can be used, if preferred: + +| Command | Description | +|---------|-------------| +| `npm run build:css` | Builds the frontend CSS file | +| `npm run watch:css` | Builds the frontend CSS file when changes are made to SCSS files | +| `npm run build:js` | Builds the frontend JS file | +| `npm run watch:js` | Builds the frontend JS file when changes are made to frontend JS files | +| `npm run build` | Builds frontend CSS and JS | + ## Write (or modify) a test If your work creates new functionality, write a test. diff --git a/composer.json b/composer.json index 2b309288c..792daf7df 100644 --- a/composer.json +++ b/composer.json @@ -31,8 +31,14 @@ "watch-css": "npm run watch:css", "lint-css": "npm run lint:css", "fix-css": "npm run fix:css", + "build-js": "npm run build:js", + "watch-js": "npm run watch:js", "lint-js": "npm run lint:js", "fix-js": "npm run fix:js", + "build": [ + "npm run build:css", + "npm run build:js" + ], "phpstan": "vendor/bin/phpstan analyse --memory-limit=1250M", "php-coding-standards": "vendor/bin/phpcs ./ -s -v", "fix-php-coding-standards": "vendor/bin/phpcbf ./ -s -v", diff --git a/includes/blocks/class-convertkit-block-broadcasts.php b/includes/blocks/class-convertkit-block-broadcasts.php index 2f47d1912..d41ba18fb 100644 --- a/includes/blocks/class-convertkit-block-broadcasts.php +++ b/includes/blocks/class-convertkit-block-broadcasts.php @@ -115,9 +115,12 @@ public function enqueue_scripts() { // Get ConvertKit Settings. $settings = new ConvertKit_Settings(); - wp_enqueue_script( 'convertkit-' . $this->get_name(), CONVERTKIT_PLUGIN_URL . 'resources/frontend/js/broadcasts.js', array(), CONVERTKIT_PLUGIN_VERSION, true ); + // Enqueue frontend JS. + convertkit_enqueue_frontend_js(); + + // Define variables. wp_localize_script( - 'convertkit-' . $this->get_name(), + 'convertkit-js', 'convertkit_broadcasts', array( // REST API URL endpoint. @@ -127,6 +130,7 @@ public function enqueue_scripts() { 'debug' => $settings->debug_enabled(), ) ); + } /** diff --git a/includes/class-convertkit-output-restrict-content.php b/includes/class-convertkit-output-restrict-content.php index 02ebdf2ec..93b6930e8 100644 --- a/includes/class-convertkit-output-restrict-content.php +++ b/includes/class-convertkit-output-restrict-content.php @@ -1431,9 +1431,11 @@ private function get_call_to_action( $post_id ) { // phpcs:ignore Generic.CodeAn // Only load scripts if the Disable Scripts option is off. if ( ! $this->settings->scripts_disabled() ) { // Enqueue scripts. - wp_enqueue_script( 'convertkit-restrict-content', CONVERTKIT_PLUGIN_URL . 'resources/frontend/js/restrict-content.js', array(), CONVERTKIT_PLUGIN_VERSION, true ); + convertkit_enqueue_frontend_js(); + + // Define variables. wp_localize_script( - 'convertkit-restrict-content', + 'convertkit-js', 'convertkit_restrict_content', array( 'nonce' => wp_create_nonce( 'wp_rest' ), @@ -1442,7 +1444,6 @@ private function get_call_to_action( $post_id ) { // phpcs:ignore Generic.CodeAn 'debug' => $this->settings->debug_enabled(), ) ); - } // Output code form if this request is after the user entered their email address, diff --git a/includes/class-convertkit-output.php b/includes/class-convertkit-output.php index 5078a58ff..be427fcf4 100644 --- a/includes/class-convertkit-output.php +++ b/includes/class-convertkit-output.php @@ -801,14 +801,10 @@ public function enqueue_scripts() { return; } - // Register scripts that we might use. - wp_register_script( - 'convertkit-js', - CONVERTKIT_PLUGIN_URL . 'resources/frontend/js/convertkit.js', - array(), - CONVERTKIT_PLUGIN_VERSION, - true - ); + // Enqueue frontend JS. + convertkit_enqueue_frontend_js(); + + // Define variables. wp_localize_script( 'convertkit-js', 'convertkit', @@ -820,9 +816,6 @@ public function enqueue_scripts() { ) ); - // Enqueue. - wp_enqueue_script( 'convertkit-js' ); - } /** diff --git a/includes/functions.php b/includes/functions.php index 0871a1360..f4f214ec1 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -540,6 +540,23 @@ function convertkit_enqueue_frontend_css() { } +/** + * Helper method to enqueue the frontend JS file. + * + * @since 3.2.0 + */ +function convertkit_enqueue_frontend_js() { + + wp_enqueue_script( + 'convertkit-js', + CONVERTKIT_PLUGIN_URL . 'resources/frontend/js/dist/frontend.min.js', + array(), + CONVERTKIT_PLUGIN_VERSION, + true + ); + +} + /** * Helper method to enqueue Select2 scripts for use within the ConvertKit Plugin. * diff --git a/package.json b/package.json index 579f2a262..0e2ef5531 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,11 @@ "watch:css": "sass resources/frontend/scss/frontend.scss resources/frontend/css/frontend.css --watch --style=compressed", "lint:css": "wp-scripts lint-style 'resources/frontend/scss/**/*.scss' 'resources/backend/css/**/*.css' --max-warnings=0", "fix:css": "wp-scripts lint-style 'resources/frontend/scss/**/*.scss' 'resources/backend/css/**/*.css' --fix", - "lint:js": "wp-scripts lint-js --max-warnings=0", - "fix:js": "wp-scripts lint-js --fix" + "build:js": "wp-scripts build resources/frontend/js/frontend.js --output-path=resources/frontend/js/dist --output-filename=frontend.min.js", + "watch:js": "wp-scripts start resources/frontend/js/frontend.js --output-path=resources/frontend/js/dist --output-filename=frontend.min.js", + "lint:js": "wp-scripts lint-js 'resources/frontend/js/*.js' --max-warnings=0", + "fix:js": "wp-scripts lint-js 'resources/frontend/js/*.js' --fix", + "build": "npm run build:css && npm run build:js" }, "prettier": "@wordpress/prettier-config", "devDependencies": { diff --git a/resources/frontend/js/dist/frontend.min.asset.php b/resources/frontend/js/dist/frontend.min.asset.php new file mode 100644 index 000000000..e4909a857 --- /dev/null +++ b/resources/frontend/js/dist/frontend.min.asset.php @@ -0,0 +1 @@ + array(), 'version' => '25c6a43d00a0d532ec2b'); diff --git a/resources/frontend/js/dist/frontend.min.js b/resources/frontend/js/dist/frontend.min.js new file mode 100644 index 000000000..82b87d518 --- /dev/null +++ b/resources/frontend/js/dist/frontend.min.js @@ -0,0 +1 @@ +(()=>{var e={184:()=>{document.addEventListener("DOMContentLoaded",function(){document.addEventListener("click",function(e){if(e.target.matches("ul.convertkit-broadcasts-pagination a")){e.preventDefault();const t=e.target.closest("div.convertkit-broadcasts");!function(e,t){convertkit_broadcasts.debug&&(console.log("convertKitBroadcastsRender()"),console.log(t)),e.classList.add("convertkit-broadcasts-loading");const n=new URLSearchParams(t),o=`${convertkit_broadcasts.ajax_url}?${n.toString()}`;fetch(o).then(function(e){return convertkit_broadcasts.debug&&console.log(e),e.json()}).then(function(t){convertkit_broadcasts.debug&&console.log(t),e.classList.remove("convertkit-broadcasts-loading"),e.innerHTML=t}).catch(function(t){convertkit.debug&&console.error(t),e.classList.remove("convertkit-broadcasts-loading")})}(t,{display_date:t.dataset.displayDate,date_format:t.dataset.dateFormat,display_image:t.dataset.displayImage,display_description:t.dataset.displayDescription,display_read_more:t.dataset.displayReadMore,read_more_label:t.dataset.readMoreLabel,limit:t.dataset.limit,paginate:t.dataset.paginate,paginate_label_prev:t.dataset.paginateLabelPrev,paginate_label_next:t.dataset.paginateLabelNext,link_color:t.dataset.linkColor,page:e.target.dataset.page})}})})},509:()=>{function e(e,t){const n=new CustomEvent(e,{detail:t});document.dispatchEvent(n)}document.addEventListener("DOMContentLoaded",function(){!function(t){const n=new URL(t),o=n.searchParams.get("ck_subscriber_id");if(null===o)return;n.searchParams.delete("ck_subscriber_id");const r=document.getElementsByTagName("title")[0].innerHTML;let c=n.searchParams.toString();c.length>0&&(c="?"+c),window.history.replaceState(null,r,n.pathname+c+n.hash),e("kit_subscriber_id_removed_from_url",{id:o})}(window.location.href),document.addEventListener("click",function(t){if(!(t.target.matches(".formkit-submit")||t.target.parentElement&&t.target.parentElement.matches(".formkit-submit")))return void(convertkit.debug&&console.log("not a ck form"));const n=document.querySelector('input[name="email_address"]').value;n.length?/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(n.toLowerCase())?(function(){const e=(new Date).getTime();for(let t=0;t<1e7&&!((new Date).getTime()-e>2e3);t++);}(),function(t){convertkit.debug&&(console.log("convertStoreSubscriberEmailAsIDInCookie"),console.log(t)),fetch(convertkit.ajaxurl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","X-WP-Nonce":convertkit.nonce},body:new URLSearchParams({email:t})}).then(function(e){return convertkit.debug&&console.log(e),e.json()}).then(function(n){convertkit.debug&&console.log(n),e("convertkit_user_subscribed",{id:n.id,email:t})}).catch(function(e){convertkit.debug&&console.error(e)})}(n)):convertkit.debug&&console.log("email not an email address"):convertkit.debug&&console.log("email empty")}),document.querySelectorAll('script[data-kit-limit-per-session="1"]').length>0&&(document.cookie="ck_non_inline_form_displayed=1; path=/",convertkit.debug&&console.log("Set `ck_non_inline_form_displayed` cookie for non-inline form limit"))})},688:()=>{function e(){const e=document.querySelector("#convertkit-subscriber-code");null!==e&&e.addEventListener("input",function(){e.style.setProperty("--_otp-digit",e.value.length),6===e.value.length&&(e.setSelectionRange(0,0),e.blur(),document.querySelector("#convertkit-restrict-content-form").requestSubmit())})}document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(".convertkit-restrict-content-modal-open").forEach(function(e){e.addEventListener("click",function(e){e.preventDefault(),document.querySelector("#convertkit-restrict-content-modal-background").style.display="block",document.querySelector("#convertkit-restrict-content-modal").style.display="block"})}),document.addEventListener("submit",function(t){t.target.matches("form#convertkit-restrict-content-form")&&(t.preventDefault(),function(t){if(document.querySelectorAll('input[type="text"], input[type="email"], input[type="submit"]').forEach(function(e){e.setAttribute("disabled","disabled")}),document.querySelector("#convertkit-restrict-content-modal-loading").style.display="block",null!==document.querySelector("input#convertkit-subscriber-code"))return n=convertkit_restrict_content.nonce,o=t.target.querySelector('input[name="subscriber_code"]').value,r=t.target.querySelector('input[name="token"]').value,c=t.target.querySelector('input[name="convertkit_post_id"]').value,fetch(convertkit_restrict_content.subscriber_verification_url,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":n},body:JSON.stringify({subscriber_code:o,token:r,convertkit_post_id:c})}).then(function(e){return convertkit_restrict_content.debug&&console.log(e),e.json()}).then(function(t){if(convertkit_restrict_content.debug&&console.log(t),!t.success)return document.querySelector("#convertkit-restrict-content-modal-content").innerHTML=t.data,document.querySelector("#convertkit-restrict-content-modal-loading").style.display="none",void e();window.location=t.url}).catch(function(e){convertkit_restrict_content.debug&&console.error(e)}),!1;var n,o,r,c;!function(t,n,o,r,c){fetch(convertkit_restrict_content.subscriber_authentication_url,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":t},body:JSON.stringify({convertkit_email:n,convertkit_resource_type:o,convertkit_resource_id:r,convertkit_post_id:c})}).then(function(e){return convertkit_restrict_content.debug&&console.log(e),e.json()}).then(function(t){convertkit_restrict_content.debug&&console.log(t),void 0!==t.code?document.querySelector("#convertkit-restrict-content-modal-content").innerHTML=t.message:document.querySelector("#convertkit-restrict-content-modal-content").innerHTML=t.data,document.querySelector("#convertkit-restrict-content-modal-loading").style.display="none",e()}).catch(function(e){convertkit_restrict_content.debug&&console.error(e)})}(convertkit_restrict_content.nonce,t.target.querySelector('input[name="convertkit_email"]').value,t.target.querySelector('input[name="convertkit_resource_type"]').value,t.target.querySelector('input[name="convertkit_resource_id"]').value,t.target.querySelector('input[name="convertkit_post_id"]').value)}(t))});const t=document.querySelector("#convertkit-restrict-content-modal-close");null!==t&&t.addEventListener("click",function(e){e.preventDefault(),document.querySelector("#convertkit-restrict-content-modal-background").style.display="none",document.querySelector("#convertkit-restrict-content-modal-loading").style.display="none",document.querySelector("#convertkit-restrict-content-modal").style.display="none"})})}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var c=t[o]={exports:{}};return e[o](c,c.exports,n),c.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";n(184),n(509),n(688)})()})(); \ No newline at end of file diff --git a/resources/frontend/js/frontend.js b/resources/frontend/js/frontend.js new file mode 100644 index 000000000..e4a6a2d15 --- /dev/null +++ b/resources/frontend/js/frontend.js @@ -0,0 +1,3 @@ +import './broadcasts.js'; +import './convertkit.js'; +import './restrict-content.js'; From 7863a638a2ebfedfa2c6385647e443ad54e5372c Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 19 Feb 2026 16:56:00 +0800 Subject: [PATCH 2/3] reCAPTCHA: Scope function to window --- resources/frontend/js/convertkit.js | 1 + resources/frontend/js/dist/frontend.min.asset.php | 2 +- resources/frontend/js/dist/frontend.min.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/frontend/js/convertkit.js b/resources/frontend/js/convertkit.js index 598916fe6..533d4a181 100644 --- a/resources/frontend/js/convertkit.js +++ b/resources/frontend/js/convertkit.js @@ -155,6 +155,7 @@ function convertKitRecaptchaFormSubmit(token) { // Submit the form. form.submit(); } +window.convertKitRecaptchaFormSubmit = convertKitRecaptchaFormSubmit; /* eslint-enable no-unused-vars */ /** diff --git a/resources/frontend/js/dist/frontend.min.asset.php b/resources/frontend/js/dist/frontend.min.asset.php index e4909a857..4ae57eb6f 100644 --- a/resources/frontend/js/dist/frontend.min.asset.php +++ b/resources/frontend/js/dist/frontend.min.asset.php @@ -1 +1 @@ - array(), 'version' => '25c6a43d00a0d532ec2b'); + array(), 'version' => '27c29088bdf910a921c1'); diff --git a/resources/frontend/js/dist/frontend.min.js b/resources/frontend/js/dist/frontend.min.js index 82b87d518..afeeda6b8 100644 --- a/resources/frontend/js/dist/frontend.min.js +++ b/resources/frontend/js/dist/frontend.min.js @@ -1 +1 @@ -(()=>{var e={184:()=>{document.addEventListener("DOMContentLoaded",function(){document.addEventListener("click",function(e){if(e.target.matches("ul.convertkit-broadcasts-pagination a")){e.preventDefault();const t=e.target.closest("div.convertkit-broadcasts");!function(e,t){convertkit_broadcasts.debug&&(console.log("convertKitBroadcastsRender()"),console.log(t)),e.classList.add("convertkit-broadcasts-loading");const n=new URLSearchParams(t),o=`${convertkit_broadcasts.ajax_url}?${n.toString()}`;fetch(o).then(function(e){return convertkit_broadcasts.debug&&console.log(e),e.json()}).then(function(t){convertkit_broadcasts.debug&&console.log(t),e.classList.remove("convertkit-broadcasts-loading"),e.innerHTML=t}).catch(function(t){convertkit.debug&&console.error(t),e.classList.remove("convertkit-broadcasts-loading")})}(t,{display_date:t.dataset.displayDate,date_format:t.dataset.dateFormat,display_image:t.dataset.displayImage,display_description:t.dataset.displayDescription,display_read_more:t.dataset.displayReadMore,read_more_label:t.dataset.readMoreLabel,limit:t.dataset.limit,paginate:t.dataset.paginate,paginate_label_prev:t.dataset.paginateLabelPrev,paginate_label_next:t.dataset.paginateLabelNext,link_color:t.dataset.linkColor,page:e.target.dataset.page})}})})},509:()=>{function e(e,t){const n=new CustomEvent(e,{detail:t});document.dispatchEvent(n)}document.addEventListener("DOMContentLoaded",function(){!function(t){const n=new URL(t),o=n.searchParams.get("ck_subscriber_id");if(null===o)return;n.searchParams.delete("ck_subscriber_id");const r=document.getElementsByTagName("title")[0].innerHTML;let c=n.searchParams.toString();c.length>0&&(c="?"+c),window.history.replaceState(null,r,n.pathname+c+n.hash),e("kit_subscriber_id_removed_from_url",{id:o})}(window.location.href),document.addEventListener("click",function(t){if(!(t.target.matches(".formkit-submit")||t.target.parentElement&&t.target.parentElement.matches(".formkit-submit")))return void(convertkit.debug&&console.log("not a ck form"));const n=document.querySelector('input[name="email_address"]').value;n.length?/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(n.toLowerCase())?(function(){const e=(new Date).getTime();for(let t=0;t<1e7&&!((new Date).getTime()-e>2e3);t++);}(),function(t){convertkit.debug&&(console.log("convertStoreSubscriberEmailAsIDInCookie"),console.log(t)),fetch(convertkit.ajaxurl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","X-WP-Nonce":convertkit.nonce},body:new URLSearchParams({email:t})}).then(function(e){return convertkit.debug&&console.log(e),e.json()}).then(function(n){convertkit.debug&&console.log(n),e("convertkit_user_subscribed",{id:n.id,email:t})}).catch(function(e){convertkit.debug&&console.error(e)})}(n)):convertkit.debug&&console.log("email not an email address"):convertkit.debug&&console.log("email empty")}),document.querySelectorAll('script[data-kit-limit-per-session="1"]').length>0&&(document.cookie="ck_non_inline_form_displayed=1; path=/",convertkit.debug&&console.log("Set `ck_non_inline_form_displayed` cookie for non-inline form limit"))})},688:()=>{function e(){const e=document.querySelector("#convertkit-subscriber-code");null!==e&&e.addEventListener("input",function(){e.style.setProperty("--_otp-digit",e.value.length),6===e.value.length&&(e.setSelectionRange(0,0),e.blur(),document.querySelector("#convertkit-restrict-content-form").requestSubmit())})}document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(".convertkit-restrict-content-modal-open").forEach(function(e){e.addEventListener("click",function(e){e.preventDefault(),document.querySelector("#convertkit-restrict-content-modal-background").style.display="block",document.querySelector("#convertkit-restrict-content-modal").style.display="block"})}),document.addEventListener("submit",function(t){t.target.matches("form#convertkit-restrict-content-form")&&(t.preventDefault(),function(t){if(document.querySelectorAll('input[type="text"], input[type="email"], input[type="submit"]').forEach(function(e){e.setAttribute("disabled","disabled")}),document.querySelector("#convertkit-restrict-content-modal-loading").style.display="block",null!==document.querySelector("input#convertkit-subscriber-code"))return n=convertkit_restrict_content.nonce,o=t.target.querySelector('input[name="subscriber_code"]').value,r=t.target.querySelector('input[name="token"]').value,c=t.target.querySelector('input[name="convertkit_post_id"]').value,fetch(convertkit_restrict_content.subscriber_verification_url,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":n},body:JSON.stringify({subscriber_code:o,token:r,convertkit_post_id:c})}).then(function(e){return convertkit_restrict_content.debug&&console.log(e),e.json()}).then(function(t){if(convertkit_restrict_content.debug&&console.log(t),!t.success)return document.querySelector("#convertkit-restrict-content-modal-content").innerHTML=t.data,document.querySelector("#convertkit-restrict-content-modal-loading").style.display="none",void e();window.location=t.url}).catch(function(e){convertkit_restrict_content.debug&&console.error(e)}),!1;var n,o,r,c;!function(t,n,o,r,c){fetch(convertkit_restrict_content.subscriber_authentication_url,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":t},body:JSON.stringify({convertkit_email:n,convertkit_resource_type:o,convertkit_resource_id:r,convertkit_post_id:c})}).then(function(e){return convertkit_restrict_content.debug&&console.log(e),e.json()}).then(function(t){convertkit_restrict_content.debug&&console.log(t),void 0!==t.code?document.querySelector("#convertkit-restrict-content-modal-content").innerHTML=t.message:document.querySelector("#convertkit-restrict-content-modal-content").innerHTML=t.data,document.querySelector("#convertkit-restrict-content-modal-loading").style.display="none",e()}).catch(function(e){convertkit_restrict_content.debug&&console.error(e)})}(convertkit_restrict_content.nonce,t.target.querySelector('input[name="convertkit_email"]').value,t.target.querySelector('input[name="convertkit_resource_type"]').value,t.target.querySelector('input[name="convertkit_resource_id"]').value,t.target.querySelector('input[name="convertkit_post_id"]').value)}(t))});const t=document.querySelector("#convertkit-restrict-content-modal-close");null!==t&&t.addEventListener("click",function(e){e.preventDefault(),document.querySelector("#convertkit-restrict-content-modal-background").style.display="none",document.querySelector("#convertkit-restrict-content-modal-loading").style.display="none",document.querySelector("#convertkit-restrict-content-modal").style.display="none"})})}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var c=t[o]={exports:{}};return e[o](c,c.exports,n),c.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";n(184),n(509),n(688)})()})(); \ No newline at end of file +(()=>{var t={184:()=>{document.addEventListener("DOMContentLoaded",function(){document.addEventListener("click",function(t){if(t.target.matches("ul.convertkit-broadcasts-pagination a")){t.preventDefault();const e=t.target.closest("div.convertkit-broadcasts");!function(t,e){convertkit_broadcasts.debug&&(console.log("convertKitBroadcastsRender()"),console.log(e)),t.classList.add("convertkit-broadcasts-loading");const n=new URLSearchParams(e),o=`${convertkit_broadcasts.ajax_url}?${n.toString()}`;fetch(o).then(function(t){return convertkit_broadcasts.debug&&console.log(t),t.json()}).then(function(e){convertkit_broadcasts.debug&&console.log(e),t.classList.remove("convertkit-broadcasts-loading"),t.innerHTML=e}).catch(function(e){convertkit.debug&&console.error(e),t.classList.remove("convertkit-broadcasts-loading")})}(e,{display_date:e.dataset.displayDate,date_format:e.dataset.dateFormat,display_image:e.dataset.displayImage,display_description:e.dataset.displayDescription,display_read_more:e.dataset.displayReadMore,read_more_label:e.dataset.readMoreLabel,limit:e.dataset.limit,paginate:e.dataset.paginate,paginate_label_prev:e.dataset.paginateLabelPrev,paginate_label_next:e.dataset.paginateLabelNext,link_color:e.dataset.linkColor,page:t.target.dataset.page})}})})},509:()=>{function t(t,e){const n=new CustomEvent(t,{detail:e});document.dispatchEvent(n)}window.convertKitRecaptchaFormSubmit=function(t){document.querySelector('[type="submit"][data-callback="convertKitRecaptchaFormSubmit"]').closest("form").submit()},document.addEventListener("DOMContentLoaded",function(){!function(e){const n=new URL(e),o=n.searchParams.get("ck_subscriber_id");if(null===o)return;n.searchParams.delete("ck_subscriber_id");const r=document.getElementsByTagName("title")[0].innerHTML;let c=n.searchParams.toString();c.length>0&&(c="?"+c),window.history.replaceState(null,r,n.pathname+c+n.hash),t("kit_subscriber_id_removed_from_url",{id:o})}(window.location.href),document.addEventListener("click",function(e){if(!(e.target.matches(".formkit-submit")||e.target.parentElement&&e.target.parentElement.matches(".formkit-submit")))return void(convertkit.debug&&console.log("not a ck form"));const n=document.querySelector('input[name="email_address"]').value;n.length?/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(n.toLowerCase())?(function(){const t=(new Date).getTime();for(let e=0;e<1e7&&!((new Date).getTime()-t>2e3);e++);}(),function(e){convertkit.debug&&(console.log("convertStoreSubscriberEmailAsIDInCookie"),console.log(e)),fetch(convertkit.ajaxurl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","X-WP-Nonce":convertkit.nonce},body:new URLSearchParams({email:e})}).then(function(t){return convertkit.debug&&console.log(t),t.json()}).then(function(n){convertkit.debug&&console.log(n),t("convertkit_user_subscribed",{id:n.id,email:e})}).catch(function(t){convertkit.debug&&console.error(t)})}(n)):convertkit.debug&&console.log("email not an email address"):convertkit.debug&&console.log("email empty")}),document.querySelectorAll('script[data-kit-limit-per-session="1"]').length>0&&(document.cookie="ck_non_inline_form_displayed=1; path=/",convertkit.debug&&console.log("Set `ck_non_inline_form_displayed` cookie for non-inline form limit"))})},688:()=>{function t(){const t=document.querySelector("#convertkit-subscriber-code");null!==t&&t.addEventListener("input",function(){t.style.setProperty("--_otp-digit",t.value.length),6===t.value.length&&(t.setSelectionRange(0,0),t.blur(),document.querySelector("#convertkit-restrict-content-form").requestSubmit())})}document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(".convertkit-restrict-content-modal-open").forEach(function(t){t.addEventListener("click",function(t){t.preventDefault(),document.querySelector("#convertkit-restrict-content-modal-background").style.display="block",document.querySelector("#convertkit-restrict-content-modal").style.display="block"})}),document.addEventListener("submit",function(e){e.target.matches("form#convertkit-restrict-content-form")&&(e.preventDefault(),function(e){if(document.querySelectorAll('input[type="text"], input[type="email"], input[type="submit"]').forEach(function(t){t.setAttribute("disabled","disabled")}),document.querySelector("#convertkit-restrict-content-modal-loading").style.display="block",null!==document.querySelector("input#convertkit-subscriber-code"))return n=convertkit_restrict_content.nonce,o=e.target.querySelector('input[name="subscriber_code"]').value,r=e.target.querySelector('input[name="token"]').value,c=e.target.querySelector('input[name="convertkit_post_id"]').value,fetch(convertkit_restrict_content.subscriber_verification_url,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":n},body:JSON.stringify({subscriber_code:o,token:r,convertkit_post_id:c})}).then(function(t){return convertkit_restrict_content.debug&&console.log(t),t.json()}).then(function(e){if(convertkit_restrict_content.debug&&console.log(e),!e.success)return document.querySelector("#convertkit-restrict-content-modal-content").innerHTML=e.data,document.querySelector("#convertkit-restrict-content-modal-loading").style.display="none",void t();window.location=e.url}).catch(function(t){convertkit_restrict_content.debug&&console.error(t)}),!1;var n,o,r,c;!function(e,n,o,r,c){fetch(convertkit_restrict_content.subscriber_authentication_url,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":e},body:JSON.stringify({convertkit_email:n,convertkit_resource_type:o,convertkit_resource_id:r,convertkit_post_id:c})}).then(function(t){return convertkit_restrict_content.debug&&console.log(t),t.json()}).then(function(e){convertkit_restrict_content.debug&&console.log(e),void 0!==e.code?document.querySelector("#convertkit-restrict-content-modal-content").innerHTML=e.message:document.querySelector("#convertkit-restrict-content-modal-content").innerHTML=e.data,document.querySelector("#convertkit-restrict-content-modal-loading").style.display="none",t()}).catch(function(t){convertkit_restrict_content.debug&&console.error(t)})}(convertkit_restrict_content.nonce,e.target.querySelector('input[name="convertkit_email"]').value,e.target.querySelector('input[name="convertkit_resource_type"]').value,e.target.querySelector('input[name="convertkit_resource_id"]').value,e.target.querySelector('input[name="convertkit_post_id"]').value)}(e))});const e=document.querySelector("#convertkit-restrict-content-modal-close");null!==e&&e.addEventListener("click",function(t){t.preventDefault(),document.querySelector("#convertkit-restrict-content-modal-background").style.display="none",document.querySelector("#convertkit-restrict-content-modal-loading").style.display="none",document.querySelector("#convertkit-restrict-content-modal").style.display="none"})})}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var c=e[o]={exports:{}};return t[o](c,c.exports,n),c.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{"use strict";n(184),n(509),n(688)})()})(); \ No newline at end of file From 829f51d447c00eebc60b122b6c1ab1da5f46433b Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 19 Feb 2026 17:17:35 +0800 Subject: [PATCH 3/3] Explain why `convertKitRecaptchaFormSubmit` is scoped --- resources/frontend/js/convertkit.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/frontend/js/convertkit.js b/resources/frontend/js/convertkit.js index 533d4a181..7d1eb2a3f 100644 --- a/resources/frontend/js/convertkit.js +++ b/resources/frontend/js/convertkit.js @@ -155,6 +155,9 @@ function convertKitRecaptchaFormSubmit(token) { // Submit the form. form.submit(); } + +// Scope the function to the window object as webpack will wrap everything in a closure, +// resulting in the function not being available globally. window.convertKitRecaptchaFormSubmit = convertKitRecaptchaFormSubmit; /* eslint-enable no-unused-vars */