The Menubar PHP item type allows you to conditionally create a menu item and dynamically generate both the link label and the link destination URL.
You can enter in the PHP code field any PHP code returning an array with your dynamically generated label and URL; you may also return an empty value, and in this case Menubar will generate no menu item at all.
Two examples will show the potential of this feature.
1) Let’s say you wish to add a menu item that lets you logout when you are logged in, and login when you are logged out.
That’s simple. Add to your Menubar menu a new item with type PHP, and enter in the PHP code field the following PHP snippet:
if (is_user_logged_in()) return array ('Log out', wp_logout_url()); else return array ('Log in', wp_login_url());
This means that, if you are logged in, you’ll get a menu item labeled Log out and pointing to your site logout URL, otherwise you’ll get a menu item labeled Log in and pointing to your site login URL.
2) Now let’s make a menu item which brings you to the admin dashboard, if you are already logged in.
The code to enter in the PHP code field is:
if (is_user_logged_in()) return array ('Site Admin', admin_url()); else return false;
This means that, if you are logged in, you’ll get a menu item labeled Site Admin and pointing to your dashboard URL, otherwise you’ll get no menu item at all.
I think these examples show the potential of the PHP item type, and I hope you find them useful. If you need help, or if you wish to share your ideas on this Menubar feature, please use the Support Forum.