Save_post action not triggered

Hello,

I need to implement an action after the Cornerstone save action finished.
Therefore I tried to use the action save_post provided by wordpress.

But this action is only triggerd if I use the save button in wordpress itself, not if I save the page through wordpress.

I’m aware of following threads in this support forum, but both did not lead to an solution:


I need this hook to clear the site cache, so the updated page is delivered to our visitors.
Is there an alternative to the save_post hook, that I can use to achieve this?

Kind Regards

@alexander: are there plans to fire the save_post hook if we save in pro/cornerstone?

@Janowsky and @RSMG

I can provide some additional context here. When saving Cornerstone content we use the wp_update_post function which is just a wrapper for wp_insert_post. The WordPress action save_post (and also wp_insert_post) fires as part of wp_insert_post so those actions do indeed get triggered when Cornerstone saves. Additionally, there’s a cornerstone_after_save_content hook that we run after the post is saved.

What I imagine is happening is that the add_action call attaching to save_post is only running in the admin side of things rather than the front end. Cornerstone uses a front end AJAX endpoint. If your code is only runs under is_admin it will never run during a Cornerstone save. This is a common technique because it is rare from save_post to be needed on the front end.

Hopefully this helps bring some clarity.

@alexander
Thanks for the quick reply.
For me it does not look like that save_post is triggered.
Or I’m unaware of the correct implementation.

At the moment, I define the hook I the functions.php of our child-theme (X-Theme), which is used for this site.

This is the debug code, I’m using at the moment:

function test_post_save_action($post_id) {
    error_log("Post was saved");
}
add_action ('save_post', 'test_post_save_action');
add_action ('cornerstone_after_save_content', 'test_post_save_action');

Hi Markus,

I copy and pasted your code and it is working for me (at least with the latest version). I’m not really sure what else could prevent it from working.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.