Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ Please make sure you make a backup of your database before updating any version
== Changelog ==

= 2.6.4 =
* Fixed: on sites using WPML (or another multilingual plugin) with a directory per language, the Domain Name could be pre-filled with the language directory included (e.g. example.com/fr), which made the Plugin Token show as invalid.
* Fixed: for user roles that aren't tracked (administrators by default), some integrations still loaded the tracker without initializing it, which caused a "window.plausible is not a function" error, e.g. on search results, 404 and checkout pages. They no longer load anything for those roles.
* Fixed: events sent from the server (WooCommerce and Easy Digital Downloads add to cart, remove from cart and EDD checkout, and Contact Form 7 and Gravity Forms submissions) were also sent for user roles that aren't tracked.
* Changed: logged-in users without a role on the site (e.g. multisite super admins visiting a subsite) are no longer tracked, as none of their roles is enabled under "Track analytics for user roles". Previously they were tracked like logged-out visitors.
Expand Down
6 changes: 5 additions & 1 deletion src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ public static function get_domain() {
return $settings['domain_name']['default'];
}

$url = home_url();
/**
* Multilingual plugins (e.g. WPML in "different languages in directories" mode) filter home_url() to include the
* current language's directory e.g., https://example.com/fr, so use the unfiltered value instead.
*/
$url = untrailingslashit( get_option( 'home' ) );

return preg_replace( '/^http(s?):\/\/(www\.)?/i', '', $url );
}
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ public function testGetDomain() {
}
}

/**
* @see Helpers::get_domain()
* @return void
*/
public function testGetDomainIgnoresLanguageDirectoryInHomeUrl() {
update_option( 'plausible_analytics_settings', [ 'domain_name' => [ 'default' => '' ] ] );

$filter_home = function ( $url ) {
return untrailingslashit( $url ) . '/fr';
};

add_filter( 'home_url', $filter_home );

try {
$expected = preg_replace( '/^http(s?):\/\/(www\.)?/i', '', untrailingslashit( get_option( 'home' ) ) );

$this->assertStringEndsWith( '/fr', home_url() );
$this->assertEquals( $expected, Helpers::get_domain() );
} finally {
remove_filter( 'home_url', $filter_home );
}
}

/**
* @see Helpers::get_domain()
* @return void
Expand Down
Loading