I've started writing a plugin that allows the administrator to select specific pages and set them to be visible only to logged-in users; the plugin optionally applies the restriction to all child pages too. When a site visitor attempts to view any of these pages, they get redirected to the login page.
So far, so good. It all works to that point, and duplicates functionality I've seen in existing plugins.
However, what I also want to do is to automatically remove all of those pages (including child pages, where specified) from the front-end site's menus. I don't want them visible at all unless you're logged in.
I've seen solutions where people create two menus and switch between them depending on logged-in status, but that's an extra step I'd rather not have.
I thought I could perhaps approach this by adding a filter or action hook for 'wp_nav_menu_items' in the plugin code, but I've had no success with that yet.
Any thoughts?
Thanks Phil
Additional details (smaller chunk of the problem):
Here's some code from my plugin that I'm trying to use to hook into the menu items:
add_filter('wp_nav_menu_items','ppa_filter_visible_menus');
function ppa_filter_visible_menus($nav) {
die("filter menus");
}
The problem I have is that ppa_filter_visible_menus is not called.