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.