Skip to content

Commit 0afff94

Browse files
committed
feat(menu): add AuthMenuLinks class
1 parent cb544b1 commit 0afff94

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoWStarterTheme\Common\Menu;
6+
7+
/**
8+
* Handles url placeholders for auth links, like login, register, and logout.
9+
*
10+
* @phpstan-import-type MenuItem from MenuItemFilter
11+
*/
12+
class AuthMenuLinks extends MenuItemFilter
13+
{
14+
/**
15+
* Replaces URL in menu item.
16+
*
17+
* @param MenuItem $item Menu item.
18+
* @return MenuItem customized menu item with icons.
19+
*/
20+
public function filterItem($item)
21+
{
22+
// @phpstan-ignore assign.propertyReadOnly
23+
$item->url = match ($item->url) {
24+
'#logout' => wp_logout_url(),
25+
'#login' => wp_login_url(),
26+
'#register' => wp_registration_url(),
27+
default => $item->url,
28+
};
29+
30+
return $item;
31+
}
32+
}

0 commit comments

Comments
 (0)