How to fire function after a menu is saved (4 posts)

  1. Aaron Wagner
    Posted 4 years ago #

    I won't go into the ugly details on why I need this, but I need to fire an event (a PHP function) after a menu is saved (new or updated). I need to have access at a point after the save happens so that I can get the new menu to output.

    I have tried:

    add_action('wp_update_nav_menu', 'fwp_save_nav', 999);

    This almost does what I want, but it fires before the save. Anyone have any thoughts?

  2. keith1000
    Posted 3 years ago #

    Yeah that just what I want too, did you figure out a solution and if so what is it?

  3. Aaron Wagner
    Posted 3 years ago #

    I ended up hooking into the admin_notices action, and then testing for certain conditions when my function fired.

    Something along these lines:

    function my_function(){
      global $current_screen;
      if($current_screen == 'nav-menus' && isset($_POST['menu'])):
        #Update code here

    This basically allowed me to do some action after a menu was saved. It's perhaps not the *ideal* way to do it, but the menus are something that are only updated by admins (specifically, me), and done very seldom. In my specific case, the hook in the OP was too soon.

  4. keith1000
    Posted 3 years ago #

    Thanks, I concluded that the action I wanted was not set up so I’ve created my own do_action in admin/nav-menus.php. This seems to work find., but it does mean I’m exposed when I update the WordPress version.

    The code I add is

    if( $action != 'edit' )
    	do_action( 'wp_changed_nav_menu', trim( esc_html( $_POST['menu-name'] ) ) );

    Located just after the action switch.

Topic Closed

This topic has been closed to new replies.

About this Topic