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

		 * @param array $items Array of custom LifterLMS nav menu items.
		 */
		return apply_filters( 'llms_nav_menu_items', $items );

	}

	/**
	 * Add "active" classes to menu items for LLMS catalog pages.
	 *
	 * @since 3.22.0
	 * @since 3.37.12 Use strict comparisons.
	 *                Cast `page_for_posts` option to int in order to use strict comparisons.
	 * @since 4.12.0 Make sure `is_lifterlms()` exists before calling it.
	 *
	 * @param array $menu_items Menu items.
	 * @return array
	 */
	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 ) ) ) {



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.