acf_validate_save_post()ACF 5.0.0

acf_validate_save_post

This function will validate $_POST data and add errors

Хуки из функции

Возвращает

(true|false).

Использование

acf_validate_save_post( $show_errors );
$show_errors **
-
По умолчанию: false

Список изменений

С версии 5.0.0 Введена.

Код acf_validate_save_post() ACF 6.0.4

function acf_validate_save_post( $show_errors = false ) {

	// action
	do_action( 'acf/validate_save_post' );

	// vars
	$errors = acf_get_validation_errors();

	// bail early if no errors
	if ( ! $errors ) {
		return true;
	}

	// show errors
	if ( $show_errors ) {

		$message  = '<h2>' . __( 'Validation failed', 'acf' ) . '</h2>';
		$message .= '<ul>';
		foreach ( $errors as $error ) {

			$message .= '<li>' . $error['message'] . '</li>';

		}
		$message .= '</ul>';

		// die
		wp_die( $message, __( 'Validation failed', 'acf' ) );

	}

	// return
	return false;

}