Skip to content

Commit

Permalink
Stabilize the PreSavePost and SavePost filters
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Aug 2, 2024
1 parent 6533c32 commit 19c6326
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const savePost =
}

const previousRecord = select.getCurrentPost();
const edits = {
let edits = {
id: previousRecord.id,
...registry
.select( coreStore )
Expand All @@ -199,9 +199,9 @@ export const savePost =

let error = false;
try {
error = await applyFilters(
'editor.__unstablePreSavePost',
Promise.resolve( false ),
edits = await applyFilters(
'editor.PreSavePost',
Promise.resolve( edits ),
options
);
} catch ( err ) {
Expand Down Expand Up @@ -236,14 +236,29 @@ 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 applyFilters(
'editor.SavePost',
Promise.resolve(),
options
);
} catch ( err ) {
error = err;
}
}
dispatch( { type: 'REQUEST_POST_UPDATE_FINISH', options } );

Expand Down

0 comments on commit 19c6326

Please sign in to comment.