From ccf02dbf8f6adcaaf76d027d6526a01b8898849e Mon Sep 17 00:00:00 2001 From: Matthias Kittsteiner Date: Mon, 2 Dec 2024 10:59:12 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Make=20sure=20clicking=20on=20th?= =?UTF-8?q?e=20language=20switcher=20doesn't=20redirect=20Closes=20#4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/class-switcher.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/inc/class-switcher.php b/inc/class-switcher.php index 0cdc8ba..8cf23a5 100644 --- a/inc/class-switcher.php +++ b/inc/class-switcher.php @@ -3,6 +3,8 @@ namespace epiphyt\Multisite_Auto_Language_Switcher; +use lloc\Msls\MslsLink; + /** * Switcher functionality. * @@ -18,6 +20,7 @@ public static function init(): void { \add_action( 'init', [ self::class, 'set_cookie' ] ); \add_action( 'wp', [ self::class, 'maybe_redirect' ] ); \add_filter( 'msls_options_get_permalink', [ self::class, 'add_redirected_parameter' ] ); + \add_filter( 'msls_output_get', [ self::class, 'set_language_switcher_link' ], 10, 3 ); } /** @@ -165,4 +168,18 @@ public static function set_cookie(): void { \setcookie( $parameter_name, '1', $cookie_options ); } + + /** + * Set language switcher link. + * + * @param string $url Current URL + * @param \lloc\Msls\MslsLink $link Multisite Language Switcher link object + * @param bool $is_current_blog Whether it's the current blog + * @return string Updated URL + */ + public static function set_language_switcher_link( string $url, MslsLink $link, bool $is_current_blog ): string { + $url = self::add_redirected_parameter( $url ); + + return \sprintf( '%4$s', $url, $link->txt, $is_current_blog ? ' class="current_language"' : '', $link ); + } }