acf_get_field_root_key()
Returns the top-level key a field's input is submitted under, relative to a form's base prefix.
Fields rendered with the base prefix submit under their own key. Seamless clone sub fields are rendered with the prefix {base}[{clone_key}], so they submit under the clone's key. Fields nested deeper (repeater rows, group sub fields) don't have a top-level key of their own.
Хуков нет.
Возвращает
string. The top-level key, or an empty string if the field doesn't submit directly under the base prefix.
Использование
acf_get_field_root_key( $field, $base );
- $field(массив) (обязательный)
- The field array, before acf_prepare_field() (which can change the key of clone sub fields).
- $base(строка)
- The form's base input prefix, such as
acf,widget-text[2][acf]ormenu-item-acf[12].
По умолчанию:'acf'
Список изменений
| С версии 6.8.11 | Введена. |
Код acf_get_field_root_key() acf get field root key ACF 6.8.11
function acf_get_field_root_key( $field, $base = 'acf' ) {
$prefix = $field['prefix'] ?? 'acf';
if ( ! is_string( $prefix ) || '' === $base ) {
return '';
}
if ( $prefix === $base ) {
return empty( $field['key'] ) ? '' : (string) $field['key'];
}
if ( preg_match( '/^' . preg_quote( $base, '/' ) . '\[([^\]]+)\]$/', $prefix, $matches ) ) {
return $matches[1];
}
return '';
}