Summary
msls_get_switcher() is the documented public template tag for rendering the
language switcher from theme code. Its signature requires a positional
argument, but the body already treats that argument as optional — any
non-array value is coerced to an empty array. As a result, the natural no-arg
call msls_get_switcher() throws a fatal ArgumentCountError even though it
would otherwise work fine.
Current behavior
includes/api.php (as of 3.0.0):
function msls_get_switcher( $attr ): string {
$arr = is_array( $attr ) ? $attr : array(); // non-array already → empty array
$obj = apply_filters( 'msls_get_output', null );
return ! is_null( $obj ) ? strval( $obj->set_tags( $arr ) ) : '';
}
Calling it without arguments:
echo msls_get_switcher();
fatals the page with:
ArgumentCountError: Too few arguments to function msls_get_switcher(),
0 passed and exactly 1 expected
Expected behavior
The no-arg call should work. Theme authors reasonably expect it to, because:
- the body already normalizes anything non-array to
array(), so $attr is
effectively optional;
- the sibling template tag
msls_the_switcher( array $arr = array() ) already
defaults its argument.
Use case
A theme rendering the switcher with default markup just wants:
echo msls_get_switcher();
Today it has to pass msls_get_switcher( array() ) purely to satisfy the
signature.
Proposed change
Give the parameter a default, matching msls_the_switcher():
function msls_get_switcher( $attr = array() ): string {
The parameter is intentionally left untyped so the existing is_array()
coercion keeps working. This preserves the [sc_msls] shortcode
(add_shortcode( 'sc_msls', 'msls_get_switcher' )), which WordPress invokes
with the empty string '' when no attributes are given — an array type hint
would break that case. Existing msls_get_switcher( $attr ) callers and the
deprecated get_the_msls( $attr ) shim are unaffected.
Backward compatible; no behavior change for any current caller.
Summary
msls_get_switcher()is the documented public template tag for rendering thelanguage switcher from theme code. Its signature requires a positional
argument, but the body already treats that argument as optional — any
non-array value is coerced to an empty array. As a result, the natural no-arg
call
msls_get_switcher()throws a fatalArgumentCountErroreven though itwould otherwise work fine.
Current behavior
includes/api.php(as of 3.0.0):Calling it without arguments:
fatals the page with:
Expected behavior
The no-arg call should work. Theme authors reasonably expect it to, because:
array(), so$attriseffectively optional;
msls_the_switcher( array $arr = array() )alreadydefaults its argument.
Use case
A theme rendering the switcher with default markup just wants:
Today it has to pass
msls_get_switcher( array() )purely to satisfy thesignature.
Proposed change
Give the parameter a default, matching
msls_the_switcher():The parameter is intentionally left untyped so the existing
is_array()coercion keeps working. This preserves the
[sc_msls]shortcode(
add_shortcode( 'sc_msls', 'msls_get_switcher' )), which WordPress invokeswith the empty string
''when no attributes are given — anarraytype hintwould break that case. Existing
msls_get_switcher( $attr )callers and thedeprecated
get_the_msls( $attr )shim are unaffected.Backward compatible; no behavior change for any current caller.