Yes, but you have to do it Redux- way. Subscribe to post saving action (there are separate actions for save and auto-save) and dispatch a message using dispatch function.
Edit:
Inside blocks, there are better hooks to use, like useSelect. But, outside the block, in general block editor environmentm you have to use subscribe. In subsbscribe you are subscribed to every action dispatched to block editor. Inside the listener function you use wp.data.select to test current state of the store. You want to test isSavingPost
and isAutosavingPost
selectors.
https://developer.wordpress.org/block-editor/reference-guides
https://developer.wordpress.org/block-editor/reference-guides/data/data-core-editor/#issavingpost/data/data-core-editor/#isautosavingpost
To wrap everything up:
const unsuscribe = wp.data.subscribe(() =>
{
if (wp.data.select('core/editor').isSavingPost() || wp.data.select('core/editor').isAutosavingPost()) {
// your code
}
});
Related Posts:
- lodash dependency in a Gutenberg plugin
- creating elements/innerblocks via rangecontrol
- Looking for callback function after Gutenberg is rendered?
- Gutenberg: useDispatch is not a function – @wordpress/data included
- Make a list with header and subtext in Gutenberg blocks
- Gutenberg – What is the best way to save/update post meta?
- How to prevent UNDO on guternberg block editor
- Do I have to worry about useState causing a re-render?
- Creating a custom Gutenberg block with columns
- Gutenberg: import dependency or assign from global variable?
- How to control an elements classes from multiple Gutenberg sidebar controls?
- Developing the save function in Gutenberg blocks
- Gutenberg – is it ok to load dependencies multiple times?
- Preventing double loading JS scripts (like React) when developing for Gutenberg
- Getting incorrect filepath inside custom block front-end output using @wordpress/create-block tutorial
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- Rerender core Templates with with ToggleControl but it doesnt recognize block type
- HTMLCollection not counting right in editor? / for loop not working on elements in DOM
- What happens/fires when you select a block in the editor?
- Is “document loaded” different on admin side than public side?
- How to use setAttributes outside of the edit function return
- why is apiFetch throwing Unhandled Promise Rejection: TypeError: Object is not a function
- Reading plugin settings in esnext wordpress block
- How can i add insertion point between inner blocks in my custom block like core blocks
- Reinitiate Gutenburg’s blocks using javascript
- Insert text programmatically in WordPress Gutenberg Editor
- Javascript function defined in view.js not reachable from save.js
- How to move custom gutenberg block controls from settings to styles tab?
- How to use useSelect to retrieve the currently default fontFamily?
- Event when Modal is opened/visible
- Cannot call a class as a function in block plugin react component
- useBlockProps() nests wrapper with class name inside block wrapper in the editor
- Gutenberg move post/page title to Editor sidebar document panel
- configure additonal build files in the @wordpress/create-block
- Is it possible to reuse wp.media.editor Modal for dialogs other than media
- check if Gutenberg is currently in use
- How to use PanelColorSettings in custom Gutenberg block?
- Hook the Keydown Event in the TinyMCE Post Editor
- How to save block attributes when the output doesn’t change
- How to remove unwanted panels inside InspectorControls from core blocks in Gutenberg
- Gutenberg ServerSideRender is deprecated, how to work with new wp.serverSideRender component?
- Can’t get JS code to work with shortcode
- Using the component outside the editor. select(‘core’) is null
- Gutenberg is there a way to know if the current block is reusable?
- How to allow core Gutenberg blocks selection only when you are inside a custom inner block
- How do I add a javascript file to all admin pages via a plugin?
- Saving data from block editor to the database
- How do I store information in a dynamic block in WordPress?
- How to create multiple Gutenberg blocks in one plugin
- How to get color name in PanelColorSettings in custom Gutenberg block?
- Gutenberg Block showing invalid content on edit
- Gutenberg blocks not getting styled on back end
- WordPress Plugin with a shortcode that dynamically generates javascript. Can I use add_action without wrapping the javascript in a function?
- Best way to save custom css for an block
- How can I listen to events in Gutenberg block?
- It’s possible to passing a ref to FormTokenField from parent component using forwardRef?
- WP Gutenberg Blocks – How to limit first/root blocks
- add javascript files only when plugin is called?
- Gutenberg table block with Bootstrap .table class
- How should I go about registering JavaScript that isn’t a file? [duplicate]
- How to add a gradient component to a custom block
- How to add template colors to custom block options in WordPress Gutenberg editor sidebar?
- How to properly package a block plugin
- Modify custom block plugin without losing content
- wp.media libary pdf type
- When setting styles to an extended block that was saved as a pattern, it doesn’t remove the style that was there
- Query String Filtering API
- How to extend SelectControl with data from my theme
- Multiple TinyMCE on button click is initialized and appended but why only last one is writeable?
- Gutenberg block breaks when showing new data
- converting a node.js project into a wp plugin
- How to re-render inspector controls?
- Where to save Gutenberg plugin data?
- Load script on frontend from widget plugin
- Gutenberg component in a plugin admin
- Append php file to footer
- Add custom html classes to gutenberg wrapper
- Filterable posts using categories
- Gutenberg and custom blocks messed up pagespeed score. What did I wrong?
- Gutenberg text field validation
- Undo operation not working in Rich text [Gutenberg]
- How to get the value entered in the input field in wordpres
- Gutenberg: – Call a function after Server Side Component is rendered
- Accept only PDF file for upload
- Help interpreting @wordpress/create-block-tutorial-template usage error
- How can I add a custom button to the post editor?
- How to get custom user meta by id in custom Gutenberg block
- Block Development: hamburger module throwing error in save function
- Adding a navigation with wp_nav_menu() to a custom block in the site editor
- Why isn’t custom sidebar panel not showing up in the Gutenberg Editor?
- Vanilla javascript in custom gutenberg block not working
- How can I include React useState in a custom gutenberg block plugin?
- Translations not making it into Block UI but work in the rest of the plugin
- How can I obtain an option (get_option) inside a block viewScript?
- How to apply a javascript code on certain parts of elementor made pages?
- move useState variable from edit.js to save.js. How do I do that?
- How to detect when the user clicks the publish/update button in Gutenberg Editor
- Extend backbone for add new custom Rest Api
- Gutenberg Static blocks: viewScript doesn’t import css for frontend?
- Custom Gutenberg block with nested InnerBlocks renderAppender not displaying add button