lloc / Multisite-Language-Switcher

WordPress Plugin: Multisite Language Switcher
http://msls.co
134 stars 41 forks source link

Ability to customize admin language identifier #144

Closed Idealien closed 5 months ago

Idealien commented 4 years ago

Describe the bug On the Post Lists admin page (and Post Editor Switcher selector in Document sidebar) the flag icon applied for countries with multiple languages (en_CA, fr_CA) does not present suitable information to differentiate based on flag alone. The front-end functionality has a few filters including msls_options_get_flag_icon that support customization. It would be helpful if admin had similar.

To Reproduce

  1. Create multisite network with en_CA and fr_CA language based sub-sites
  2. Note that when moving between sub-sites the column on Posts > Edit both have the Canada Flag at top header of table of posts.

Expected behaviour A filter to modify the flag which is presented. Nice-to-have: Ability to replace entire flag concept with text.

Screenshots image

Environment (please complete the following information):

lloc commented 4 years ago

Excellent input. Thanks!

Idealien commented 4 years ago

I wasn't able to get a fork of GH version to operate from either master or tagged 2.4.3 as yet to submit via PR, but the following snippets give a good example.

New filter inside updated get_icon function multisite-language-switcher\includes\MslsAdminIcon.php

public function get_icon() {
        if ( 'flag' === $this->iconType ) {
            /**
            * Use your own filename for the flag-icon
            * @since 2.4.3-dev
            *
            * @param string $icon
            * @param string $language
            */
            $icon = apply_filters( 'msls_options_admin_get_flag_icon', $this, $this->language );
            return sprintf( '<span class="flag-icon %s">%s</span>',
                ( new IconSvg() )->get( $this->language ),
                $this->language
            );
        }

        if ( empty( $this->href ) ) {
            return '<span class="dashicons dashicons-plus"></span>';
        }

        return '<span class="dashicons dashicons-edit"></span>';
    }

And usage of it from a theme functions.php file

add_filter( 'msls_options_admin_get_flag_icon', 'cpg_msls_admin_flag_icon', 10, 2);
function cpg_msls_admin_flag_icon( $icon, $language ) {
    if ( $language == 'fr_CA' ) {
        $icon->set_language( 'fr' );
    } else {
        $icon->set_language( 'gb' );
    }
    return $icon;
}
lloc commented 5 months ago

https://github.com/lloc/Multisite-Language-Switcher/issues/152 was integrated and closed this issue.