39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace RomhackPlaza\Theme\Extenders;
|
||
|
|
defined( '\ABSPATH' ) || exit;
|
||
|
|
|
||
|
|
use RomhackPlaza\Theme\Snippets;
|
||
|
|
class Nav_Menu extends Abstract_Extender {
|
||
|
|
|
||
|
|
public function can_extend(): bool {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function extend(): void {
|
||
|
|
|
||
|
|
$this->add_filter( 'nav_menu_item_title', [ $this, 'add_expand' ], 10, 4 );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param string $title The menu item's title.
|
||
|
|
* @param object $item The current menu item.
|
||
|
|
* @param array $args An array of wp_nav_menu() arguments.
|
||
|
|
* @param int $depth Depth of menu item. Used for padding.
|
||
|
|
* @return string $title The menu item's title with dropdown icon.
|
||
|
|
*/
|
||
|
|
public function add_expand( $title, $item, $args, $depth ): string {
|
||
|
|
|
||
|
|
if( $args->theme_location === 'primary' || $args->theme_location === 'secondary' ) {
|
||
|
|
foreach ( $item->classes as $value ) {
|
||
|
|
if( $value === 'menu-item-has-children' || $value === 'page_item_has_children' )
|
||
|
|
$title .= Snippets::svg_icon( 'expand' );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return $title;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|