acf_form_front::pre_save_post()publicACF 5.4.0

pre_save_post

description

Метод класса: acf_form_front{}

Хуков нет.

Возвращает

$post_id. (int)

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

$acf_form_front = new acf_form_front();
$acf_form_front->pre_save_post( $post_id, $form );
$post_id (обязательный)
-
$form (обязательный)
-

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

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

Код acf_form_front::pre_save_post() ACF 6.0.4

function pre_save_post( $post_id, $form ) {

	// vars
	$save = array(
		'ID' => 0,
	);

	// determine save data
	if ( is_numeric( $post_id ) ) {

		// update post
		$save['ID'] = $post_id;

	} elseif ( $post_id == 'new_post' ) {

		// merge in new post data
		$save = array_merge( $save, $form['new_post'] );

	} else {

		// not post
		return $post_id;

	}

	// phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified in check_submit_form().
	// save post_title
	if ( isset( $_POST['acf']['_post_title'] ) ) {

		$save['post_title'] = acf_extract_var( $_POST['acf'], '_post_title' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized by WP when saved.

	}

	// save post_content
	if ( isset( $_POST['acf']['_post_content'] ) ) {

		$save['post_content'] = acf_extract_var( $_POST['acf'], '_post_content' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized by WP when saved.

	}
	// phpcs:enable WordPress.Security.NonceVerification.Missing

	// honeypot
	if ( ! empty( $_POST['acf']['_validate_email'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Data not used; presence indicates spam.
		return false;
	}

	// validate
	if ( count( $save ) == 1 ) {

		return $post_id;

	}

	// save
	if ( $save['ID'] ) {

		wp_update_post( $save );

	} else {

		$post_id = wp_insert_post( $save );

	}

	// return
	return $post_id;

}