acf/validate_save_post

Overview

This action is fired during the validation process (triggered when publishing a post) and allows you to review and modify validation errors or perform other logic.

If you intend to validate a field, please use the acf/validate_value filter.

This action is fired after all fields have been validated (via the above filter) and before any response is returned (JSON).

Changelog

  • Added in v5.0.0

Parameters

This action accepts no parameters.

All validation errors are stored in a global array $GLOBALS['acf_validation_errors'] which can be modified through this action.

Usage

This example demonstrates how the action could be used to bypass validation for an administrator

functions.php

<?php 

add_action('acf/validate_save_post', 'my_acf_validate_save_post', 10, 0);

function my_acf_validate_save_post() {
	
	// check if user is an administrator
	if( current_user_can('manage_options') ) {
		
		// clear all errors
		$GLOBALS['acf_validation_errors'] = array();
		
	}
	
}
	
?>

Related