acf_upgrade_500_field_group() ACF 5.7.4
Upgrades a ACF4 field group to ACF5
Хуки из функции
Возвращает
Массив. $nfg The new field group array.
Использование
acf_upgrade_500_field_group( $ofg );
- $ofg (обязательный)
- -
Список изменений
С версии 5.7.4 | Введена. |
Код acf_upgrade_500_field_group() acf upgrade 500 field group ACF 5.9.1
function acf_upgrade_500_field_group( $ofg ) {
// log
acf_dev_log('ACF Upgrade 5.0.0 Field Group.', $ofg);
// vars
$nfg = array(
'ID' => 0,
'title' => $ofg->post_title,
'menu_order' => $ofg->menu_order,
);
// construct the location rules
$rules = get_post_meta($ofg->ID, 'rule', false);
$anyorall = get_post_meta($ofg->ID, 'allorany', true);
if( is_array($rules) ) {
// if field group was duplicated, rules may be a serialized string!
$rules = array_map('maybe_unserialize', $rules);
// convert rules to groups
$nfg['location'] = acf_convert_rules_to_groups( $rules, $anyorall );
}
// settings
if( $position = get_post_meta($ofg->ID, 'position', true) ) {
$nfg['position'] = $position;
}
if( $layout = get_post_meta($ofg->ID, 'layout', true) ) {
$nfg['layout'] = $layout;
}
if( $hide_on_screen = get_post_meta($ofg->ID, 'hide_on_screen', true) ) {
$nfg['hide_on_screen'] = maybe_unserialize($hide_on_screen);
}
// save field group
// acf_upgrade_field_group will call the acf_get_valid_field_group function and apply 'compatibility' changes
$nfg = acf_update_field_group( $nfg );
// log
acf_dev_log('> Complete.', $nfg);
// action for 3rd party
do_action('acf/upgrade_500_field_group', $nfg, $ofg);
// upgrade fields
acf_upgrade_500_fields( $ofg, $nfg );
// trash?
if( $ofg->post_status == 'trash' ) {
acf_trash_field_group( $nfg['ID'] );
}
// return
return $nfg;
}