MyBB Community Forums

Full Version: Rework header menu for plugin friendliness
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Instead of the current method of forcing plugins to hackily go in and beat at the templates and hope their edits fit, perhaps add in a new template and a hook that lets plugins not have to worry about that?

I was thinking something like this:

$toplinks = array(
    array('class' => "help", 'link' => "{$mybb->settings['bburl']}/misc.php?action=help", 'content' => "$lang->toplinks_help"));

// conditional stuff for adding the other things

$plugins->run_hooks('global_header_menu', &$toplinks);

$headermenu = '';

foreach($toplinks as $link)
{
    $headermenu .= eval($templates->render("header_menu_item"));
}

// continue as normal

Most likely someone will come up with better names for all this...

This would necessitate adding the "header_menu_item" template (basically a generic version of one of the existing menu templates).

This would allow plugins to add themselves to the header menu without resorting to potentially fragile template modifications (i.e. what if the header template had <nav><a...>... instead of the current <ul><li><a...>...).
It's too late for such a change... MyBB 1.8 is feature frozen and adding this in later releases is almost impossible without breaking plugins and themes.
This would also make it difficult to remove links from the header without either a plugin or core edit.
@StefanT: I was afraid of such, but worth a try

@Euan T: I considered that, wasn't too sure how much of a problem it may be. Another option might be something database-related? On installation a plugin might insert it's menu item into say 'topmenu' and there would be an AdminCP module for toggling menu items (and maybe even adding new ones manually?). All I know is right now it's horribly fragile.
A menu manager would be a better option, but would be a massive change. XenForo is adding this I believe, and it's maybe something we can look into for 2.0.
I already wrote such a plugin for 1.6. But there are so many different ways to design a menu that it's hard to get it working with every design. Probably I'll release it here after I get it working with 1.8...