acf_form_front::decode_primary_form
Decrypts and verifies the primary _acf_form blob, enforcing token freshness (TTL) and binding to the current page render.
Returns the original $args map — with the internal _acf_token_* bookkeeping keys stripped — so callers see the same shape the pre-6.8.8 decrypt path produced.
Метод класса: acf_form_front{}
Хуки из метода
Возвращает
array|false. Decoded form args on success, false otherwise.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->decode_primary_form( $raw );
- $raw(разное) (обязательный)
- The raw
$_POST['_acf_form']value.
Список изменений
| С версии 6.8.10 | Введена. |
Код acf_form_front::decode_primary_form() acf form front::decode primary form ACF 6.8.11
protected function decode_primary_form( $raw ) {
if ( ! is_scalar( $raw ) ) {
return false;
}
$decoded = json_decode( acf_decrypt( sanitize_text_field( (string) $raw ), 'form_primary' ), true );
if ( ! is_array( $decoded ) ) {
return false;
}
if ( ! isset( $decoded['_acf_token_issued_at'] ) || ! is_numeric( $decoded['_acf_token_issued_at'] ) ) {
return false;
}
if ( ! isset( $decoded['_acf_token_render_id'] ) || ! is_string( $decoded['_acf_token_render_id'] ) || '' === $decoded['_acf_token_render_id'] ) {
return false;
}
/**
* Filters how long a primary `_acf_form` bearer token remains valid
* after the page that emitted it was rendered.
*
* @since 6.8.8
*
* @param int $ttl Allowed age of a primary form token, in seconds.
*/
$ttl = (int) apply_filters( 'acf/form/primary_ttl', DAY_IN_SECONDS );
// A non-positive TTL is a kill switch — reject every token
// unconditionally, including future-dated ones that would otherwise
// bypass the `age >= ttl` check because the age is negative.
if ( $ttl <= 0 ) {
return false;
}
if ( ( time() - (int) $decoded['_acf_token_issued_at'] ) >= $ttl ) {
return false;
}
$expected_render_id = $this->get_submitted_render_id();
if ( '' === $expected_render_id ) {
return false;
}
if ( ! hash_equals( $expected_render_id, (string) $decoded['_acf_token_render_id'] ) ) {
return false;
}
unset( $decoded['_acf_token_issued_at'], $decoded['_acf_token_render_id'] );
return $decoded;
}