acf_revisions::acf_validate_post_id()publicACF 5.5.10

acf_validate_post_id

This function will modify the $post_id and allow loading values from a revision

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

Хуков нет.

Возвращает

$post_id. (int)

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

$acf_revisions = new acf_revisions();
$acf_revisions->acf_validate_post_id( $post_id, $_post_id );
$post_id (обязательный)
-
$_post_id (обязательный)
-

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

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

Код acf_revisions::acf_validate_post_id() ACF 6.0.4

function acf_validate_post_id( $post_id, $_post_id ) {

	// phpcs:disable WordPress.Security.NonceVerification.Recommended
	// bail early if no preview in URL
	if ( ! isset( $_GET['preview'] ) ) {
		return $post_id;
	}

	// bail early if $post_id is not numeric
	if ( ! is_numeric( $post_id ) ) {
		return $post_id;
	}

	// vars
	$k          = $post_id;
	$preview_id = 0;

	// check cache
	if ( isset( $this->cache[ $k ] ) ) {
		return $this->cache[ $k ];
	}

	// validate
	if ( isset( $_GET['preview_id'] ) ) {

		$preview_id = (int) $_GET['preview_id'];

	} elseif ( isset( $_GET['p'] ) ) {

		$preview_id = (int) $_GET['p'];

	} elseif ( isset( $_GET['page_id'] ) ) {

		$preview_id = (int) $_GET['page_id'];

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

	// bail early id $preview_id does not match $post_id
	if ( $preview_id != $post_id ) {
		return $post_id;
	}

	// attempt find revision
	$revision = acf_get_post_latest_revision( $post_id );

	// save
	if ( $revision && $revision->post_parent == $post_id ) {

		$post_id = (int) $revision->ID;

	}

	// set cache
	$this->cache[ $k ] = $post_id;

	// return
	return $post_id;

}