ACF_Form_Post::allow_save_postpublicACF 5.3.8

Checks if the $post is allowed to be saved. Used to avoid triggering "acf/save_post" on dynamically created posts during save.

Method of the class: ACF_Form_Post{}

No Hooks.

Returns

true|false.

Usage

$ACF_Form_Post = new ACF_Form_Post();
$ACF_Form_Post->allow_save_post( $post );
$post(WP_Post) (required)
The post to check.

Changelog

Since 5.3.8 Introduced.

ACF_Form_Post::allow_save_post() code ACF 6.8.8

function allow_save_post( $post ) {

	// vars
	$allow = true;

	// restrict post types
	$restrict = array( 'auto-draft', 'revision', 'acf-field', 'acf-field-group' );
	if ( in_array( $post->post_type, $restrict ) ) {
		$allow = false;
	}

	// disallow if the $_POST ID value does not match the $post->ID
	$form_post_id = (int) acf_maybe_get_POST( 'post_ID' );
	if ( $form_post_id && $form_post_id !== $post->ID ) {
		$allow = false;
	}

	// revision (preview)
	if ( $post->post_type == 'revision' ) {

		// allow if doing preview and this $post is a child of the $_POST ID
		if ( acf_maybe_get_POST( 'wp-preview' ) == 'dopreview' && $form_post_id === $post->post_parent ) {
			$allow = true;
		}
	}

	// return
	return $allow;
}