• 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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Yeah that just what I want too, did you figure out a solution and if so what is it?

    Thread Starter Aaron Wagner

    (@ajwagner777)

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

    Something along these lines:

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

    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.

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to fire function after a menu is saved’ is closed to new replies.