wp_update_nav_menu hook is not fired when nav menu item is auto-added
|Reported by:||inderpreet99||Owned by:|
WP calls the action hook 'wp_update_nav_menu' when a navigation menu is updated. For example, go to Site Design -> Custom Menus -> Click the "Save Menu" button on a menu.
Next to the Menu title, the Custom Menus provide the user to "Automatically add new top-level pages". When this option is checked, and a new top-level page is created, the 'wp_update_nav_menu' hook is not fired. So the attached nav-menu-hooks.diff patch fixes that.
I would also suggest that we do not use the same hook 'wp_update_nav_menu' twice (as it is currently being done) with different amount of arguments, because this causes a PHP Warning
PHP Warning: Missing argument 2 for x_save_footer() in /var/www/branches/x.trunk/wp-content/themes/x/functions.php on line 815, referer: http://x.com/x/wp-admin/nav-menus.php
add_action('wp_update_nav_menu', 'x_save_footer', 10, 2);
So, the hook call at nav-menu.php:255 has 2 parameters and the call at nav-menus.php:383 has 1 parameter.
As a fix, the action hook in nav-menu.php should be named something else, like 'wp_update_nav_menu_object' (because it is updating the object), as done in the attached nav-menu-hooks.diff patch. This will also prevent the same hook from being fired twice when updating the nav menus.
Change History (5)
comment:2 in reply to: ↑ 1 mark8barnes — 23 months ago
- Cc mark@… added
- Type changed from enhancement to defect (bug)