[Resolved] Extend Walker_Nav_Menu_Edit: How to proceed?
Yesterday, I wrote a little plugin – my first! 🙂 – and decided to submit it to wordpress.org. (http://wordpress.org/extend/plugins/category-posts-in-custom-menu/)
Today, I realised that adding configuration options would be a good thing, but I’m running into some newbie problems, I guess. Let’s start with what I want and what I DO know, questions are at the bottom.
When clicking Appearance > Menus, you can add Category Pages to a custom menu. In my own menu, I wanted to replace the Category Page by the list of posts in that category. I wrote a little plugin that replaces _all_ Category Pages and replaces them by the posts in that category _ordered ascending alphabetically_. You can see where I’m going: I would like to offer users the possibility of configuring this on a per-menu-item-basis and would like to give them the possibility of setting the ordering. (Later, I might extend this to Tags Pages and also offer a ‘number of posts’ option, but first things first.)
What I (think I) know: I’ll have to extend the Walker_Nav_Menu_Edit class, to generate an additional checkbox and a way to select the ordering (two dropdowns, one for asc/desc and one for the ordering field perhaps? Input is welcome.). I’ve gotten as far as overriding the start_el method (too bad there are no hooks in there) and adding a checkbox.
My reference: wp-admin/includes/nav-menu.php (@19074) lines 126 and 148.
- I’ll have to read the checkbox checked-state from a custom attribute. I’ll have to add such an attribute to menu items, and tie them in with my plugin’s custom checkbox. How do I add an attribute to menu items and where do I take care of updating it when the user clicks ‘Save Menu’? (I’ll then inspect this attribute when my wp_nav_menu_objects filter handler is called.)
- If applicable: Does adding a custom attribute to menu items generate additional database rows and if so, how do I make sure that when my plugin is uninstalled, they are removed?
- What’s the ‘right’ way to add the ordering controls and in the future the number of posts field? I’ve seen these fields before and I’m wondering if there is some ‘standard’ way of doing this so that the user input is validated automatically. If there is no such way, how should I do the validation? Should I do this only at the point where I inspect and apply the values, or is there a possibility to notify the user earlier that, for instance, the value they submitted is not a number?
- Why are there hidden input fields in the menu-item-settings div? What are they for and can they be of any use to me?
(Forgot to sign in when posting this the first time, sorry.)
- The topic ‘[Resolved] Extend Walker_Nav_Menu_Edit: How to proceed?’ is closed to new replies.