-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stabilize the PreSavePost and SavePost filters #64198
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If anyone ever registers an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't seem like it'd be as effective as a deprecation message on a call to There's no JS equivalent unfortunately, so it'd need to be implemented in the hooks package, which makes this a bit more involved. 😅 I guess the reason it's not handled on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, It needs to be added to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a |
||
} catch ( err ) { | ||
error = err; | ||
} ); | ||
} | ||
} | ||
|
||
if ( ! error ) { | ||
try { | ||
await doActionAsync( 'editor.savePost', options ); | ||
} catch ( err ) { | ||
error = err; | ||
} | ||
} | ||
dispatch( { type: 'REQUEST_POST_UPDATE_FINISH', options } ); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning here previously didn't make much sense, and that's why we're removing it, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously we were returning a promise, so that the next filter can
.then
on it. Now this is all handled by the async runner: it will ensure that the next handler runs only after the previous one finished and succeeded.That's also why this hook is no longer a filter, but an action. Action handlers don't return anything.