Nav_Menu_Item - missing "current" class. #243

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

Projects

None yet

2 participants

@Chrico
Member
Chrico commented Nov 22, 2016 edited

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 Chrico was assigned by tfrommen Dec 16, 2016
@tfrommen tfrommen added this to the v3.0.0 milestone Dec 16, 2016
@Chrico
Member
Chrico commented Dec 22, 2016

Will this also be included in new release?

@tfrommen tfrommen modified the milestone: v2.5.0, v3.0.0 Dec 23, 2016
@tfrommen
Member

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