ContextInstitute / bfcom

http://bfn.context.org
GNU General Public License v3.0
4 stars 1 forks source link

Add functions for controlling submenu #66

Closed rgilman closed 5 years ago

rgilman commented 5 years ago

Since getting back from AZ I've been working on the submenu as described in #17. In the last few days I've had some breakthroughs and I'm now ready to offer these into the master.

I've added two functions to functions/bfc-functions.php, which is the place for us to add our bfcom-specific functions.

The first function - bfc_nav_configure() - comes from discovering the BuddyPress Codex article, Navigation API. (I've often been disappointed in the BuddyPress Codex so I'm not in the habit of looking there first but perhaps I should.) It allows us to change menu-item names, remove or add menu items and reorder menu-item positions. It's connected to the hook 'bp_actions'.

When I first activated this function, the results were erratic. Some configurations worked but others were getting overridden somehow. On further digging I found bp_nouveau_has_nav() which initiates the nav loop and is central to creating each menu. As written, this function depends on settings in the WordPress Customizer for BP-Nouveau. That was part of what was overriding the configuration in bfc_nav_configure(). So I copied bp_nouveau_has_nav() into functions/bfc-functions.php and renamed it bfc_nouveau_has_nav(). I also changed the reference in parts/nav-bfc-submenu.php to this new function.

With that in place, I was able to remove the dependence on the WordPress Customizer. One of the functions in bfc_nouveau_has_nav() is bp_nouveau_set_nav_item_order() which makes it easy to set any order we want. At some point we might want to be able to do this via a UI but for now I have no problem with hardcoding the order.

There was one more gotcha – a bug in the interaction between commons-in-a-box and bp-nouveau. Please go to Admin Dashboard > Commons In A Box Settings and make sure that Group Forum Default Tab is unchecked.

rgilman commented 5 years ago

My initial push just dealt with the group submenu. I've just modified the two functions so that they also control the member submenu.

iangilman commented 5 years ago

Great! As far as I'm concerned, controlling this via the code seems nicer than doing it via the database, since we don't have to all manually make changes. That said, it would be great to figure out an easy way to replicate database changes from some master version to all of our local versions.