add_menu_classes()WP 2.7.0

Adds CSS classes for top-level administration menu items.

The list of added classes includes .menu-top-first and .menu-top-last.

Хуки из функции

Возвращает

Массив. The array of administration menu items with the CSS classes added.

Использование

add_menu_classes( $menu );
$menu(массив) (обязательный)
The array of administration menu items.

Список изменений

С версии 2.7.0 Введена.

Код add_menu_classes() WP 6.1.1

function add_menu_classes( $menu ) {
	$first_item  = false;
	$last_order  = false;
	$items_count = count( $menu );
	$i           = 0;

	foreach ( $menu as $order => $top ) {
		$i++;

		if ( 0 == $order ) { // Dashboard is always shown/single.
			$menu[0][4] = add_cssclass( 'menu-top-first', $top[4] );
			$last_order = 0;
			continue;
		}

		if ( 0 === strpos( $top[2], 'separator' ) && false !== $last_order ) { // If separator.
			$first_item             = true;
			$classes                = $menu[ $last_order ][4];
			$menu[ $last_order ][4] = add_cssclass( 'menu-top-last', $classes );
			continue;
		}

		if ( $first_item ) {
			$classes           = $menu[ $order ][4];
			$menu[ $order ][4] = add_cssclass( 'menu-top-first', $classes );
			$first_item        = false;
		}

		if ( $i == $items_count ) { // Last item.
			$classes           = $menu[ $order ][4];
			$menu[ $order ][4] = add_cssclass( 'menu-top-last', $classes );
		}

		$last_order = $order;
	}

	/**
	 * Filters administration menu array with classes added for top-level items.
	 *
	 * @since 2.7.0
	 *
	 * @param array $menu Associative array of administration menu items.
	 */
	return apply_filters( 'add_menu_classes', $menu );
}