ACF_Compatibility::validate_field_group
This function will provide compatibility with ACF4 field groups
Метод класса: ACF_Compatibility{}
Хуков нет.
Возвращает
$field_group.
Использование
$ACF_Compatibility = new ACF_Compatibility(); $ACF_Compatibility->validate_field_group( $field_group );
- $field_group(обязательный)
- .
Список изменений
| С версии 5.0.0 | Введена. |
Код ACF_Compatibility::validate_field_group() ACF Compatibility::validate field group ACF 6.4.2
function validate_field_group( $field_group ) {
// vars
$version = 5;
// field group key was added in version 5.0.0
// detect ACF4 data and generate key
if ( ! $field_group['key'] ) {
$version = 4;
$field_group['key'] = isset( $field_group['id'] ) ? "group_{$field_group['id']}" : uniqid( 'group_' );
}
// prior to version 5.0.0, settings were saved in an 'options' array
// extract and merge options into the field group
if ( isset( $field_group['options'] ) ) {
$options = acf_extract_var( $field_group, 'options' );
$field_group = array_merge( $field_group, $options );
}
// location data structure changed to groups in version 4.1.0
// convert previous data (rules, allorany) into groups
if ( isset( $field_group['location']['rules'] ) ) {
$field_group['location'] = acf_convert_rules_to_groups( $field_group['location']['rules'], $field_group['location']['allorany'] );
}
// some location rule names have changed in version 5.0.0
// loop over location data and modify rules
$replace = array(
'taxonomy' => 'post_taxonomy',
'ef_media' => 'attachment',
'ef_taxonomy' => 'taxonomy',
'ef_user' => 'user_role',
'user_type' => 'current_user_role', // 5.2.0
);
// only replace 'taxonomy' rule if is an ACF4 field group
if ( $version > 4 ) {
unset( $replace['taxonomy'] );
}
// loop over location groups
if ( $field_group['location'] ) {
foreach ( $field_group['location'] as $i => $group ) {
// loop over group rules
if ( $group ) {
foreach ( $group as $j => $rule ) {
// migrate param
if ( isset( $replace[ $rule['param'] ] ) ) {
$field_group['location'][ $i ][ $j ]['param'] = $replace[ $rule['param'] ];
}
}
}
}
}
// change layout to style (v5.0.0)
if ( isset( $field_group['layout'] ) ) {
$field_group['style'] = acf_extract_var( $field_group, 'layout' );
}
// change no_box to seamless (v5.0.0)
if ( $field_group['style'] === 'no_box' ) {
$field_group['style'] = 'seamless';
}
// return
return $field_group;
}