[ 'class' => true, 'role' => true, 'aria-label' => true ], 'img' => [ 'src' => true, 'class' => true, 'alt' => true, 'role' => true, 'loading' => true ], ] ); $anchor_classes = [ 'trp-language-switcher', 'trp-ls-dropdown', 'trp-shortcode-switcher', 'trp-shortcode-anchor' ]; $overlay_classes = [ 'trp-language-switcher', 'trp-ls-dropdown', 'trp-shortcode-switcher', 'trp-shortcode-overlay' ]; $mode_class = $open_on_click ? 'trp-open-on-click' : 'trp-open-on-hover'; $anchor_classes[] = $mode_class; // harmless on anchor (layout only) $overlay_classes[] = $mode_class; // used by CSS/JS on overlay if ( ! empty( $is_opposite ) ) { $anchor_classes[] = 'trp-opposite-button'; $overlay_classes[] = 'trp-opposite-button'; } $current = $list[0]; $has_more = count( $list ) > 1; $list_id = 'trp-shortcode-dropdown-' . uniqid(); $render_header = static function( array $item, bool $show_arrow, bool $clickable, bool $is_opposite, string $flag_position, array $allowed_flag_html, bool $has_more, bool $as_control, string $list_id ): string { ob_start(); ?>
$classes, 'data-no-translation' => null, ]; if ( $as_control && ! $is_opposite ) { // Control (toggle): floated model $attrs['role'] = 'button'; $attrs['aria-expanded'] = 'false'; $attrs['tabindex'] = '0'; $attrs['aria-label'] = __( 'Change language', 'translangated' ); $attrs['aria-controls'] = $list_id; } else { // Language switcher link $attrs['href'] = $href; $attrs['title'] = esc_html( $item['name'] ); } echo '<' . tag_escape( $tag ); foreach ( $attrs as $k => $v ) { echo $v === null ? ' ' . esc_attr( $k ) : ' ' . esc_attr( $k ) . '="' . esc_attr( $v ) . '"'; } echo '>'; if ( $flag_position === 'before' ) echo wp_kses( (string) $item['flag'], $allowed_flag_html ); if ( $item['name'] !== '' ) echo '' . esc_html( $item['name'] ) . ''; if ( $flag_position === 'after' ) echo wp_kses( (string) $item['flag'], $allowed_flag_html ); echo ''; ?>