From 0c8e9b6ee226aceb0a192a1d48983f229adb8112 Mon Sep 17 00:00:00 2001 From: Marcello Perathoner Date: Mon, 8 Jan 2024 17:02:15 +0100 Subject: [PATCH] Remove unsupported plugin menu visibility. --- themes/Capitularia/functions-include.php | 25 ++++++++++++++++++++++++ themes/Capitularia/functions.php | 1 + 2 files changed, 26 insertions(+) diff --git a/themes/Capitularia/functions-include.php b/themes/Capitularia/functions-include.php index fc6c1a45..ac591136 100644 --- a/themes/Capitularia/functions-include.php +++ b/themes/Capitularia/functions-include.php @@ -529,6 +529,31 @@ function on_do_parse_request ($do_parse, $wp, $extra_query_vars) // phpcs:ignore return $do_parse; } +/** + * Removes the login menu if already logged in. + * + * This assumes the menu entry is a top-level one with an URL of: #cap_login_menu# + * + * @param array $items An array of menu item post objects. + * @param object $menu The menu object. + * @param array $args An array of arguments used to retrieve menu item objects. + * + * @return array The modified array of menu item post objects. + */ +function on_wp_get_nav_menu_items ($items, $menu, $args) { + foreach ($items as $key => $item) { + if (isset ($item->url)) { + if (strcmp ($item->url, MAGIC_LOGIN) === 0) { + if (is_user_logged_in()) { + unset ($items[$key]); + } + } + } + } + return $items; +} + + /** * Add dynamic url to login menu. Remove text from twitter and fb logos. * diff --git a/themes/Capitularia/functions.php b/themes/Capitularia/functions.php index 58d08586..90399a96 100644 --- a/themes/Capitularia/functions.php +++ b/themes/Capitularia/functions.php @@ -117,6 +117,7 @@ function () { /* add login url to menu */ if (!is_admin ()) { add_filter ('nav_menu_link_attributes', ns ('on_nav_menu_link_attributes'), 20, 4); + add_filter ('wp_get_nav_menu_items', ns ('on_wp_get_nav_menu_items' ), 10, 3 ); } /* allow SVG uploads */