Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Nav_Menu_Item - missing "current" class. #243

@Chrico

Description

@Chrico

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

	}
);

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions