Multisite-Language-Switcher icon indicating copy to clipboard operation
Multisite-Language-Switcher copied to clipboard

Ability to customize admin language identifier

Open Idealien opened this issue 4 years ago • 2 comments

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):

  • OS: Linux
  • PHP Version: 7.2
  • Plugin Version 2.3 / 2.4.3

Idealien avatar Apr 07 '20 14:04 Idealien

Excellent input. Thanks!

lloc avatar Apr 07 '20 15:04 lloc

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;
}

Idealien avatar Apr 07 '20 15:04 Idealien