From 8f138bd2ea2dd6b341f40986fdfc9dc24c850d04 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh <18595395+Dan0sz@users.noreply.github.com> Date: Tue, 20 Oct 2026 11:19:40 +0200 Subject: [PATCH] Use the unfiltered home URL as the default Domain Name Multilingual plugins like WPML (directory per language) filter home_url() to include the current language's directory (e.g. example.com/fr). That ended up in the pre-filled Domain Name, so the Plugin Token never matched the site's domain and was reported as invalid. --- readme.txt | 1 + src/Helpers.php | 6 +++++- tests/integration/HelpersTest.php | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 7fd9b18c..b77d2f18 100644 --- a/readme.txt +++ b/readme.txt @@ -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. diff --git a/src/Helpers.php b/src/Helpers.php index 59778f99..3dd45303 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -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 ); } diff --git a/tests/integration/HelpersTest.php b/tests/integration/HelpersTest.php index 0d439887..eea89a00 100644 --- a/tests/integration/HelpersTest.php +++ b/tests/integration/HelpersTest.php @@ -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