acf_revisions::acf_validate_post_id
Modifies the $post_id to allow loading values from a revision.
Метод класса: acf_revisions{}
Хуков нет.
Возвращает
mixed.
Использование
$acf_revisions = new acf_revisions(); $acf_revisions->acf_validate_post_id( $post_id, $_post_id );
- $post_id(разное) (обязательный)
- The post ID after being processed by acf_get_valid_post_id().
- $_post_id(разное) (обязательный)
- The post ID before being processed by acf_get_valid_post_id().
Список изменений
| С версии 5.5.10 | Введена. |
Код acf_revisions::acf_validate_post_id() acf revisions::acf validate post id ACF 6.8.11
public function acf_validate_post_id( $post_id, $_post_id ) {
// Bail early if not a well-formed WordPress preview context.
if ( ! is_preview() ) {
return $post_id;
}
// Bail early if $post_id is not numeric.
if ( ! is_numeric( $post_id ) ) {
return $post_id;
}
// Bail early if current user cannot edit this post.
if ( ! current_user_can( 'edit_post', (int) $post_id ) ) {
return $post_id;
}
$k = $post_id;
$preview_id = 0;
if ( isset( $this->cache[ $k ] ) ) {
return $this->cache[ $k ];
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended
// 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 if $preview_id does not match $post_id.
if ( $preview_id != $post_id ) {
return $post_id;
}
// Attempt to find the revision.
$revision = acf_get_post_latest_revision( $post_id );
if ( $revision && $revision->post_parent == $post_id ) {
$post_id = (int) $revision->ID;
}
$this->cache[ $k ] = $post_id;
return $post_id;
}