You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, for a plugin I'm currently developing I need to dynamically update the information displayed in a meta-box when the post content changes with the Gutenberg editor active. I did my researches and based on this post #4674 (comment) I ended up with this solution.
Can you please tell me if there are better methods to achieve this or if it's a valid solution in your opinion? (the code below works)
const {subscribe} = wp.data;
window.DAIM = {};
const unssubscribe = subscribe(() => {
if (wp.data.select('core/editor').getCurrentPostLastRevisionId() !== null &&
window.DAIM.currentPostLastRevisionId !== null &&
window.DAIM.currentPostLastRevisionId !== wp.data.select('core/editor').getCurrentPostLastRevisionId()) {
console.log('The revision is changed, dynamically update the meta-box based on the current post content.');
}
window.DAIM.currentPostLastRevisionId = wp.data.select('core/editor').getCurrentPostLastRevisionId();
});
The text was updated successfully, but these errors were encountered:
Thanks @daext, that code is exactly what I was looking for. I too would be interested in finding out if there is a better way to do this, perhaps with some sort of property change listener (not just the generic subscribe).
This will check whether there's a new revision. In terms of edits to the post content, you could also use something like the getEditedPostContent selector to detect changed content in the same way.
Hello, for a plugin I'm currently developing I need to dynamically update the information displayed in a meta-box when the post content changes with the Gutenberg editor active. I did my researches and based on this post #4674 (comment) I ended up with this solution.
Can you please tell me if there are better methods to achieve this or if it's a valid solution in your opinion? (the code below works)
The text was updated successfully, but these errors were encountered: