Updating a metabox after Gutenberg updates

When press on “Update” refresh a custom metabox under gutenberg editor.

Dicembre 4, 2022

Javascript code to add in a WordPress metabox to trigger the refresh of the metabox content which doesn’t update after Gutenberg saving process.

<script>
	const appuntiStatusChange = ( function(){
		const isSavingMetaBoxes = wp.data.select( 'core/edit-post' ).isSavingMetaBoxes;
		var wasSaving = false;
		return {
			refreshMetabox: function(){
				var isSaving = isSavingMetaBoxes();
				if ( wasSaving && ! isSaving ) {
					alert("Post changed and saved, call your metabox refresh function here.");
				}
				wasSaving = isSaving;
			},
		}
	})();
	wp.data.subscribe( appuntiStatusChange.refreshMetabox );
</script>

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Recommended

WP Gutenberg notes

Collection of notes and thoughts on Wordpress Gutenberg blocks development.

Gennaio 9, 2023

Test page for Bright Links plugin

To test the plugin hover your mouse to a link, or tap the link on mobile device.

Dicembre 4, 2022

WP doesn’t send email? try this

Snippets for sending emails with Wordpress

Febbraio 8, 2020

Two post types share the same taxonomy in WordPress

Sharing a WordPress taxonomy between two post types is useful especially if you want to create a relation between different…

Novembre 14, 2019

Modify the language attribute based on category in WordPress

How to modify the language attribute in your Wordpress theme using a specific value

Novembre 7, 2019

WordPress Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0

How I've beat the php mysterious fatal error unknown in Wordpress caused by caching plugin WP Fastest Cache