-
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
Add an async __unstablePreSavePost
hook; resolving with false prevents saving
#58022
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e684c39
Add an async `__unstablePreSavePost` hook; resolving with false preve…
adamsilverstein f2e65b8
Simplify preSave check
adamsilverstein 101c0d1
Merge branch 'trunk' into add/preSaveHook
adamsilverstein bcae174
Filter edits & enable throwing Error in `__unstablePreSavePost` filter
adamsilverstein da8196e
Merge branch 'trunk' into add/preSaveHook
adamsilverstein ff7d6b4
Pass Promise.resolve( edits ) instead of edits
adamsilverstein 4ead1ff
Move REQUEST_POST_UPDATE_START to before preSave async filter
adamsilverstein d5d7bfc
Update saveEntityRecord error handling to use try/catch
adamsilverstein a546cdd
Merge branch 'trunk' into add/preSaveHook
adamsilverstein 7764b36
Use explicit false check for error
adamsilverstein 2a0d9f2
reduce changes, test functionality, don’t pass data to filter
adamsilverstein 05b4852
whitespace
adamsilverstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thank you for starting to implement this! 🚀
Some further improvements would be nice:
Error( 'ACF validation failed' )
. The code further down thesavePost
function will then display a notice with that error.edits
, and maybe even change them. In addition to theoptions
that are already passed to it (in practice we inspectoptions.isAutosave
).The result would look like:
What do you think?
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.
👋 Thanks a lot for working on this, Adam! I was pointed to this PR by Jarda, as I have a somewhat related use case:
I have an entity (a
wp_navigation
postType) that is loaded viauseEntityRecords()
. The entity has a post meta field registered (which is returned by the endpoint). When saving the entity (after it has had some edits), I’d like to include the post meta, even if the latter doesn't have any edits. (See the bottom of this comment for more context.)It seems that an
__unstablePreSavePost
filter -- if Jarda's suggestion of allowing modifications toedits
is applied -- could solve that problem (although I'd need it to work in the Site Editor rather than in the Post Editor).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.
Do we need to add it there separately @ockham?
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.
My only goal here is to prevent saving, I don't thing we should enable changing the edits at this point, what would the use case for that feature be?
@ockham Ah, this does sound like a valid use case for being able to modify the edits before a save, have you already solved this elsewhere?
This would complicate the use of the proposed preSave hook as I intended - simply returning an error message to hook into the existing error handling logic to prevent saving.
Since this proposal changes the use case for the hook, I would prefer to consider it in a follow up issue, what do you think?