New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nav_Menu_Item - missing "current" class. #243

Closed
Chrico opened this Issue Nov 22, 2016 · 2 comments

Comments

2 participants
@Chrico
Member

Chrico commented Nov 22, 2016

Version Information

  • WordPress: 4.7x
  • MultilingualPress: 2.4.8

Steps to Reproduce

  1. Create a new Multsite with at least 2 connected Blogs.
  2. Create a new Nav-Menu in Blog 1 and add all available languages as items
  3. Navigate to frontend of Blog 1

What I Expected

The Nav-Menu-Item of "Blog 1" should have at least 1 "current"-class e.G. current-[language|blog|menu|...]-item

What Happened Instead

No "current"-class is added.

Screenshot

image

Howto fix

In Mlp_Nav_Menu_Frontend:prepare_item() the method should contain a check for get_current_blog() compared with the $site_id. If TRUE, we should add at least 1 "current" class to the given $item.

if ( get_current_blog() === $site_id ) {
    $item->classes[]  = "mlp-current-language-nav-item";
}

Link in 2.4 Branch: https://github.com/inpsyde/multilingual-press/blob/2.4/src/inc/nav-menu/Mlp_Nav_Menu_Frontend.php#L108

Quick mu-plugin to solve this problem directly:

Here's a mu-plugin which will fix this issue by adding a class mlp-current-language-nav-item to the current nav-item:

<?php
/**
 * Plugin Name: MLP current nav-item class.
 * Author: Christian Brückner
 * Author URI: https://www.chrico.info
 */

add_action(
	'muplugins_loaded',
	function () {

		add_action(
			'mlp_prepare_nav_menu_item_output',
			function ( WP_Post $item, Mlp_Translation_Interface $translation ) {

				if ( get_current_blog_id() === $translation->get_target_site_id() ) {
					$item->classes[] = 'mlp-current-language-nav-item';
				}

			},
			10,
			2
		);

	}
);
@Chrico

This comment has been minimized.

Show comment
Hide comment
@Chrico

Chrico Dec 22, 2016

Member

Will this also be included in new release?

Member

Chrico commented Dec 22, 2016

Will this also be included in new release?

@tfrommen

This comment has been minimized.

Show comment
Hide comment
@tfrommen

tfrommen Dec 23, 2016

Contributor

Closed with 6ea9abd.

@Chrico I renamed the class to mlp-current-language-item (and not *-nav-item).

Contributor

tfrommen commented Dec 23, 2016

Closed with 6ea9abd.

@Chrico I renamed the class to mlp-current-language-item (and not *-nav-item).

@tfrommen tfrommen closed this Dec 23, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment