LLMS_Nav_Menus::menu_item_classes( array $menu_items )

Add “active” classes to menu items for LLMS catalog pages.


Parameters Parameters

$menu_items

(array) (Required) Menu items.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/class.llms.nav.menus.php

	public function menu_item_classes( $menu_items ) {

		if ( ! function_exists( 'is_lifterlms' ) || ! is_lifterlms() ) {
			return $menu_items;
		}

		$courses_id     = llms_get_page_id( 'courses' );
		$memberships_id = llms_get_page_id( 'memberships' );
		$blog_id        = absint( get_option( 'page_for_posts', 0 ) );

		foreach ( $menu_items as $key => $item ) {

			$classes   = $item->classes;
			$object_id = absint( $item->object_id );

			// Remove active class from blog archive.
			if ( $blog_id === $object_id ) {

				$menu_items[ $key ]->current = false;
				foreach ( array( 'current_page_parent', 'current-menu-item' ) as $class ) {
					if ( in_array( $class, $classes, true ) ) {
						unset( $classes[ array_search( $class, $classes, true ) ] );
					}
				}
			} elseif ( 'page' === $item->object && ( ( is_courses() && $courses_id === $object_id ) || ( is_memberships() && $memberships_id === $object_id ) ) ) {

				$menu_items[ $key ]->current = true;
				$classes[]                   = 'current-menu-item';
				$classes[]                   = 'current_page_item';

				// Set parent links for courses & memberships.
			} elseif ( ( $courses_id === $object_id && ( is_singular( 'course' ) || is_course_taxonomy() ) ) || ( $memberships_id === $object_id && ( is_singular( 'llms_membership' ) || is_membership_taxonomy() ) ) ) {

				$classes[] = 'current_page_parent';

			}

			$menu_items[ $key ]->classes = array_unique( $classes );

		}

		return $menu_items;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.12.0 Make sure is_lifterlms() exists before calling it.
3.37.12 Use strict comparisons. Cast page_for_posts option to int in order to use strict comparisons.
3.22.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.