Skip to content

Extensibility: Add a way for third parties to perform additional save validation #13413

@noisysocks

Description

@noisysocks

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

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions