-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Is your feature request related to a problem? Please describe.
Plugins like Advanced Custom Fields require a way to perform additional validation when a post is published or updated. This validation can be asynchronous.
Describe the solution you'd like
I'm thinking that the most flexible solution here would be to wrap the call to apiFetch() made by requestPostUpdate() with a filter. This will let third parties perform as much additional asynchronous validation as they would like, or even replace the entire API call with their own.
Example:
wp.hooks.addFilter( 'editor.updatePost', async ( options ) => {
if ( ! performPreSaveValidation() ) {
throw 'The post is invalid! A pre-save check failed.';
}
const response = await wp.apiFetch( options );
if ( ! performPostSaveValidation() ) {
throw 'The post is invalid! A post-save check failed.';
}
return response;
} );Describe alternatives you've considered
I considered an alternative approach using PluginPrePublishPanel but this does not handle the case where validation needs to happen on an update to an already published post.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status