Menubar 4.10
Menubar 4.10 is a bug fixing release that removes some compatibility problems with the qTranslate plugin.
As usual, this new version is available on the WordPress Plugin Directory. Enjoy!
Menubar 4.10 is a bug fixing release that removes some compatibility problems with the qTranslate plugin.
As usual, this new version is available on the WordPress Plugin Directory. Enjoy!
Do you need to add an item like Log in, Log out, Register, Site Admin to your Menubar menu? Now, with the new PHP item type in Menubar 4.9, you can!
A) 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 ());
That 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.
B) What if you need a menu item to allow visitors to register to your site? Of course that item should be present only if the visitor is not already logged in.
That’s the content to write into the PHP code field:
if (!is_user_logged_in () && get_option ('users_can_register'))
return array ('Register', site_url ('wp-login.php?action=register', 'login'));
else
return false;
That means that, if the visitor is not logged in and user registration is enabled, you’ll get a menu item labeled Register and pointing to your site signup URL, otherwise you’ll get no menu item at all.
C) Now let’s make a menu item which brings you to the admin dashboard, if you are already logged in.
The code you need to put in the PHP code field is:
if (is_user_logged_in ())
return array ('Site Admin', admin_url ());
else
return false;
That 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 hope you find these examples useful, and I think they help to show the potential of the PHP item type available in Menubar 4.9. If you find other interesting applications, please share them in the comments!
Menubar 4.9 enhances the PHP item type, allowing you to create a menu item and dynamically generate both the link label and the link destination URL.
The PHP item type was introduced in Menubar 4.8, but you could dinamically generate only the link destination, while the link label was specified statically in the Name field.
Now 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.
A sample of the PHP code you can insert in the PHP code field is as follows:
// content of the PHP code field
$someurl = some expression;
$otherurl = other expression;
if (some-condition)
return array ('somelabel', $someurl);
else if (other-condition)
return array ('otherlabel', $otherurl);
else
return false;
This PHP snippet generates:
a) a menu item labeled ‘somelabel’ and pointing to $someurl if (some-condition) is met;
b) a menu item labeled ‘otherlabel’ and pointing to $otherurl if (other-condition) is met;
c) no menu item otherwise.
Menubar 4.9 also fixes a bug that prevented highlighting in an External or PHP menu item type, when the page URL contained a querystring.
Thank you for your support of Menubar!
I have just learnt of a great video tutorial covering the installation and use of Menubar, the WordPress plugin that allows you to add configurable menus to your site.
You can find this 13 minute tutorial on Codes Scripts. The author is Patrick Hamy, and he has made a very good job of explaining carefully and clearly all the steps needed to install Menubar and start using it. The tutorial is in French, but I think it’s going to be useful to non French speakers too.
Thank you Patrick!
This new Menubar version supports a new menu item type, named PHP. With this type you can dynamically generate a menu item using PHP code, so its applications are limited only by your imagination.
You can enter in the URL field any PHP code which returns your dynamically generated URL; you may also return an empty value, and in this case Menubar will generate no menu item at all.
A sample of the PHP code you can insert in the URL field is as follows:
// content of the URL field
$someurl = some expression;
$otherurl = other expression;
if (some-condition)
return $someurl;
else if (other-condition)
return $otherurl;
else
return '';
This PHP snippet generates:
a) a menu item pointing to $someurl if (some-condition) is met;
b) a menu item pointing to $otherurl if (other-condition) is met;
c) no menu item otherwise.
This is only a sample, you can use any PHP code and return the URL you need or no URL at all. Happy menus with Menubar!
Recent Comments