Skip to content

Commit

Permalink
Subscriptions / Verbum Comments: more strictly check for the site URL…
Browse files Browse the repository at this point in the history
… when handling the comment subscription modal (#40129)

* Subscriptions: be more strict in detect site URL on commenting

Internal reference: p1730381560559409-slack-CRA4UEQQ3

* Get site host from database instead

See Automattic/jetpack-sirt#12 (comment)

---------

Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/11783973774

Upstream-Ref: Automattic/jetpack@1a30464
  • Loading branch information
tbradsha authored and matticbot committed Nov 11, 2024
1 parent a5c8362 commit ef210f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This is an alpha version! The changes listed here are not final.
- Optimize the Sharing module hook callback.
- Remove old widget migration code.
- Search: add ability to customize order of results
- Subscriptions: ensure that we correct detect the site URL when handling the Subscription modal appearing leaving a comment.
- Sync: Added test for Full Sync sending modules in the order config is set
- Themes: Fix race condition when loading theme compatibility files.
- Updated composer.lock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,19 @@ public function __construct() {
* @return void
*/
public function enqueue_assets() {
if ( $this->should_user_see_modal() ) {
wp_enqueue_style( 'subscription-modal-css', plugins_url( 'subscription-modal.css', __FILE__ ), array(), JETPACK__VERSION );
wp_enqueue_script( 'subscription-modal-js', plugins_url( 'subscription-modal.js', __FILE__ ), array( 'wp-dom-ready' ), JETPACK__VERSION, true );
if ( ! $this->should_user_see_modal() ) {
return;
}

wp_enqueue_style( 'subscription-modal-css', plugins_url( 'subscription-modal.css', __FILE__ ), array(), JETPACK__VERSION );
wp_enqueue_script( 'subscription-modal-js', plugins_url( 'subscription-modal.js', __FILE__ ), array( 'wp-dom-ready' ), JETPACK__VERSION, true );
wp_localize_script(
'subscription-modal-js',
'subscriptionData',
array(
'homeUrl' => wp_parse_url( home_url(), PHP_URL_HOST ),
)
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global subscriptionData */
document.addEventListener( 'DOMContentLoaded', function () {
const modal = document.getElementsByClassName( 'jetpack-subscription-modal' )[ 0 ];

Expand Down Expand Up @@ -46,7 +47,7 @@ document.addEventListener( 'DOMContentLoaded', function () {
return;
}

if ( ! event.origin.includes( window.location.host ) ) {
if ( subscriptionData.homeUrl !== event.origin ) {
return;
}

Expand Down

0 comments on commit ef210f3

Please sign in to comment.