ada*_*aml 6 javascript wordpress-gutenberg
我正在构建一个古腾堡块,在保存/发布帖子时,我需要首先使用 API 保存一些块数据,然后使用 API 返回的 ID 更新块属性,最后将帖子保存在 Wordpress 中。
目前我正在使用下面的黑客来接管“发布”按钮,但我想要一个更好的解决方案。
setTimeout(function () {
jQuery(".editor-post-publish-button").click(function (event) {
// Send some requests to an API which returns an ID
// Update the post with new values
dispatch('core/block-editor').updateBlockAttributes(clientId, data);
// Finally save the Post
dispatch('core/editor').savePost();
})
});
}, 3000);
Run Code Online (Sandbox Code Playgroud)
在此解决方案之前,我尝试使用 subscribe() 并检查 isSavingPost 等事件,但没有成功。在此先感谢您的帮助!