acf_validation::ajax_validate_save_post │ public │ ACF 5.0.9

Validates $_POST data via AJAX prior to save.

Method of the class: acf_validation{}

No Hooks.

Returns

void. Nothing (null).

Usage

$acf_validation = new acf_validation();
$acf_validation->ajax_validate_save_post();

Changelog

Since 5.0.9 Introduced.

acf_validation::ajax_validate_save_post() code ACF 6.8.8

public function ajax_validate_save_post() {
	if ( ! acf_verify_ajax() ) {
		if ( empty( $_REQUEST['nonce'] ) ) {
			$nonce_error = __( 'ACF was unable to perform validation because no nonce was received by the server.', 'acf' );
		} else {
			$nonce_error = __( 'ACF was unable to perform validation because the provided nonce failed verification.', 'acf' );
		}

		wp_send_json_success(
			array(
				'valid'  => 0,
				'errors' => array(
					array(
						'input'   => false,
						'message' => $nonce_error,
						'action'  => array(
							'label' => __( 'Learn more', 'acf' ),
							'url'   => acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/validation-nonce-errors/', 'docs', 'validation-nonce' ),
						),
					),
				),
			)
		);
	}

	$json = array(
		'valid'  => 1,
		'errors' => 0,
	);

	if ( acf_validate_save_post() ) {
		wp_send_json_success( $json );
	}

	$json['valid']  = 0;
	$json['errors'] = acf_get_validation_errors();

	wp_send_json_success( $json );
}