diff --git a/packages/edit-post/src/store/actions.js b/packages/edit-post/src/store/actions.js index d00f7472382f80..1dc0401baf21c3 100644 --- a/packages/edit-post/src/store/actions.js +++ b/packages/edit-post/src/store/actions.js @@ -8,7 +8,7 @@ import { privateApis as editorPrivateApis, } from '@wordpress/editor'; import deprecated from '@wordpress/deprecated'; -import { addFilter } from '@wordpress/hooks'; +import { addAction } from '@wordpress/hooks'; import { store as coreStore } from '@wordpress/core-data'; /** @@ -478,21 +478,14 @@ export const initializeMetaBoxes = metaBoxesInitialized = true; // Save metaboxes on save completion, except for autosaves. - addFilter( - 'editor.__unstableSavePost', + addAction( + 'editor.savePost', 'core/edit-post/save-metaboxes', - ( previous, options ) => - previous.then( () => { - if ( options.isAutosave ) { - return; - } - - if ( ! select.hasMetaBoxes() ) { - return; - } - - return dispatch.requestMetaBoxUpdates(); - } ) + async ( options ) => { + if ( ! options.isAutosave && select.hasMetaBoxes() ) { + await dispatch.requestMetaBoxUpdates(); + } + } ); dispatch( { diff --git a/packages/editor/src/store/actions.js b/packages/editor/src/store/actions.js index 4b519a9d8f6cc3..fa720e1fc7d347 100644 --- a/packages/editor/src/store/actions.js +++ b/packages/editor/src/store/actions.js @@ -12,7 +12,11 @@ import { import { store as noticesStore } from '@wordpress/notices'; import { store as coreStore } from '@wordpress/core-data'; import { store as blockEditorStore } from '@wordpress/block-editor'; -import { applyFilters } from '@wordpress/hooks'; +import { + applyFilters, + applyFiltersAsync, + doActionAsync, +} from '@wordpress/hooks'; import { store as preferencesStore } from '@wordpress/preferences'; import { __ } from '@wordpress/i18n'; @@ -184,7 +188,7 @@ export const savePost = } const previousRecord = select.getCurrentPost(); - const edits = { + let edits = { id: previousRecord.id, ...registry .select( coreStore ) @@ -199,9 +203,9 @@ export const savePost = let error = false; try { - error = await applyFilters( - 'editor.__unstablePreSavePost', - Promise.resolve( false ), + edits = await applyFiltersAsync( + 'editor.preSavePost', + edits, options ); } catch ( err ) { @@ -236,14 +240,25 @@ export const savePost = ); } + // Run the hook with legacy unstable name for backward compatibility if ( ! error ) { - await applyFilters( - 'editor.__unstableSavePost', - Promise.resolve(), - options - ).catch( ( err ) => { + try { + await applyFilters( + 'editor.__unstableSavePost', + Promise.resolve(), + options + ); + } catch ( err ) { error = err; - } ); + } + } + + if ( ! error ) { + try { + await doActionAsync( 'editor.savePost', options ); + } catch ( err ) { + error = err; + } } dispatch( { type: 'REQUEST_POST_UPDATE_FINISH', options } );