0

I'm currently new to the Gutenberg block development. I was wondering if there is a way to detect when the user clicks the publish/update button?

Reason for this is that i need to call a custom function right after the button click.

The purpose for the custom function is to keep a copy of the original content. After succeeding publish/update click, the block will compare the updated content with the original content for certain keywords.

Thank you for replying.

2
  • what does your function do? It's unlikely that the answer will solve the problem you're trying to solve, and it's very very likely there's a better way to do it that's much easier. Even then the answer would depend on where you need to do this from. Any context you can add would be enormously helpful. Likewise clicking publish doesn't actually publish it opens a panel
    – Tom J Nowell
    Commented May 24, 2023 at 14:29
  • No, there's no default way to listen to publish/update button clicks in Guttenberg. But we can make our own! However, it's important to know what custom function to call after the button is clicked. If it's a JS function, we'll need to set up an event listener. If it's a PHP function, we can use hooks. Tell us what you're after, the answer depends on that.
    – alex
    Commented May 24, 2023 at 14:40

1 Answer 1

0

I think it's late for the party but there is an action is core/editor package of block editor called isSavingPost. Haven't used it but I think it's worth giving a try.

https://developer.wordpress.org/block-editor/reference-guides/data/data-core-editor/#issavingpost

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.