MyBB Community Forums

Full Version: Adding Menu items
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is it possible to add a menu item when creating and installing a plugin?

Or does this have to be done via a theme modification only?
You can do this with either way.

Editing templates is much more feasible.
ok, I'll bite......

So what are the basic steps to add/remove a menu item via a plugin? The goal is to let the plugin install do this work, and not to have the user editing a template or core file.
Actually take a look in the releases forum, i seem to remember this actually.
@OP: You can do this using the find_replace_templatesets function I believe it's that). I'd provide a code sample, but I'm currently on a loaned laptop with none of my work on it or anything. Somebody else might help instead though Wink
Thanks for the help and tips guys. And yes, i'm learning the find_replacement_templatesets is very useful.

But I can't seem to get the function to accept a variable from another function to be accepts as the replacement text.

I've setup the new function, and have indicated the replacement variable as global as well.

Let me wrap up some things here today, and I can post up some sample code as well where I'm currently stuck.

Thanks again to all for great and very fast help.
The find_replace_templatesets() function is a bit though to understand in the beginning. It helps if you already know regular expression but it's actually finding out what to replace is a bit tricky. You'll need to find something unique and general that is used in most themes.

To add links to the, so called, toplinks you will need to edit the header template. The toplinks are build with a unordered list (ul). If you want prepend your items to the list, search & replace the <ul>
$menuitem = '<li><a href="{$mybb->settings[\'bburl\']}/page.php"><img src="{$theme[\'imgdir\']}/toplinks/image.gif" alt="" title="" />Menu Text</a></li>';
find_replace_templatesets('header', "#\<ul\>#i", "<ul>".$menuitem);
If you want to append the menu item to the list, you'll need to replace </ul>:
$menuitem = '<li><a href="{$mybb->settings[\'bburl\']}/page.php"><img src="{$theme[\'imgdir\']}/toplinks/image.gif" alt="" title="" />Menu Text</a></li>';
find_replace_templatesets('header', "#\</ul\>#i", $menuitem."</ul>");

Altering templatesets is best done in the activate/deactivate functions of your plugin.