Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
2  
Hi, Phil, welcome to WPSE. Please, show the code you are trying to use. – brasofilo Jan 18 at 16:45
Hi. I have no code for what I'm trying to do. I have code for the part of my plugin that works (so I won't bother posting that). What I need are some ideas for how to selectively hide/remove all menu items that correspond to a given list of page IDs. – Phil Piper Jan 18 at 20:09
1  
Well, the filter is inside the function with the same name, see if you can get some inspiration from there. – brasofilo Jan 18 at 20:16

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.