• Resolved crstauf

    (@crstauf)


    Ran into a problem this weekend, where my custom hook onto save_post action was not firing for pages, or custom post types. I’ve done some debugging this morning, and it seems that save_post is not firing at all for pages (and I would assume CPTs). I’ve deactivated all plugins and activated Twenty Fifteen, tried different variations of the hook (save_page,save_post_page), and the action does not fire. I’m using simple code to test:

    add_action('save_post','save_post_test');
    function save_post_test($post_id) {
    	exit('saving');
    }

    It does fire when saving a post, but not pages/CPTs. Is there something I’ve missed in 4.0.1?

    Edit: it gets weirder: i just edited wp-includes/post.php to exit() with output just before each (two) do_action('save_post'), but still nothing! how is that possible?? script does exit() when placed at beginning of wp_insert_post(), so I’m going to work my way down through the function and see where it returns. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter crstauf

    (@crstauf)

    oh, blah. found the little bugger. in wp_insert_post() there’s some code that checks if a page has been assigned a page template that is now invalid. it seems that if you assign a template to page, and then delete that template, that WordPress doesn’t clear the template assignment, which keeps save_post from firing, but doesn’t show a warning in the backend about the template missing. ??

    going to have to reset the page’s template property manually. bleh.

    Thread Starter crstauf

    (@crstauf)

    more info here: https://core.trac.www.ads-software.com/ticket/29269
    (sadly, i did not search Trac, only the forums)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘save_post not working for Pages/CPTs’ is closed to new replies.