Updating a metabox after Gutenberg updates

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

December 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.

Comments on “Updating a metabox after Gutenberg updates”

Leave a Reply

Your email address will not be published. Required fields are marked with an *

Recommended

WP Gutenberg notes

Collection of notes and thoughts on Wordpress Gutenberg blocks development.

January 9, 2023

Test page for Bright Link Preview plugin

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

December 4, 2022

WP doesn’t send email? try this

Snippets for sending emails with Wordpress

February 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…

November 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

November 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