Skip to content

Commit

Permalink
💄 Make sure clicking on the language switcher doesn't redirect
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
MatzeKitt committed Dec 2, 2024
1 parent 59978c4 commit ccf02db
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions inc/class-switcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace epiphyt\Multisite_Auto_Language_Switcher;

use lloc\Msls\MslsLink;

/**
* Switcher functionality.
*
Expand All @@ -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 );
}

/**
Expand Down Expand Up @@ -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 {

Check failure on line 180 in inc/class-switcher.php

View workflow job for this annotation

GitHub Actions / test-phpstan

Parameter $link of method epiphyt\Multisite_Auto_Language_Switcher\Switcher::set_language_switcher_link() has invalid type lloc\Msls\MslsLink.

Check failure on line 180 in inc/class-switcher.php

View workflow job for this annotation

GitHub Actions / test-phpstan

Parameter $link of method epiphyt\Multisite_Auto_Language_Switcher\Switcher::set_language_switcher_link() has invalid type lloc\Msls\MslsLink.
$url = self::add_redirected_parameter( $url );

return \sprintf( '<a href="%1$s" title="%2$s"%3$s>%4$s</a>', $url, $link->txt, $is_current_blog ? ' class="current_language"' : '', $link );

Check failure on line 183 in inc/class-switcher.php

View workflow job for this annotation

GitHub Actions / test-phpstan

Access to property $txt on an unknown class lloc\Msls\MslsLink.

Check failure on line 183 in inc/class-switcher.php

View workflow job for this annotation

GitHub Actions / test-phpstan

Parameter #5 ...$values of function sprintf expects bool|float|int|string|null, lloc\Msls\MslsLink given.
}
}

0 comments on commit ccf02db

Please sign in to comment.