WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Получай пассивный доход от сайта с помощью браузерных PUSH уведомлений
функция не описана

acf_upgrade_500_field() ACF 5.7.4

Upgrades a ACF4 field to ACF5

Хуки из функции
Возвращает

Массив. $field The new field.

Использование

acf_upgrade_500_field( $field );
$field(массив) (обязательный)
The old field.

Список изменений

С версии 5.7.4 Введена.

Код acf_upgrade_500_field() ACF 5.9.1

<?php
function acf_upgrade_500_field( $field ) {
	
	// log
	acf_dev_log('ACF Upgrade 5.0.0 Field.', $field);
	
	// order_no is now menu_order
	$field['menu_order'] = acf_extract_var( $field, 'order_no', 0 );
	
	// correct very old field keys (field2 => field_2)
	if( substr($field['key'], 0, 6) !== 'field_' ) {
		$field['key'] = 'field_' . str_replace('field', '', $field['key']);
	}
	
	// extract sub fields
	$sub_fields = array();
	if( $field['type'] == 'repeater' ) {
		
		// loop over sub fields
		if( !empty($field['sub_fields']) ) {
			foreach( $field['sub_fields'] as $sub_field ) {
				$sub_fields[] = $sub_field;
			}
		}
		
		// remove sub fields from field
		unset( $field['sub_fields'] );
	
	} elseif( $field['type'] == 'flexible_content' ) {
		
		// loop over layouts
		if( is_array($field['layouts']) ) {
			foreach( $field['layouts'] as $i => $layout ) {
				
				// generate key
				$layout['key'] = uniqid('layout_');
				
				// loop over sub fields
				if( !empty($layout['sub_fields']) ) {
					foreach( $layout['sub_fields'] as $sub_field ) {
						$sub_field['parent_layout'] = $layout['key'];
						$sub_fields[] = $sub_field;
					}
				}
				
				// remove sub fields from layout
				unset( $layout['sub_fields'] );
				
				// update
				$field['layouts'][ $i ] = $layout;
				
			}
		}
	}
	
	// save field
	$field = acf_update_field( $field );
	
	// log
	acf_dev_log('> Complete.', $field);
	
	// sub fields
	if( $sub_fields ) {
		foreach( $sub_fields as $sub_field ) {
			$sub_field['parent'] = $field['ID'];
			acf_upgrade_500_field($sub_field);
		}
	}
	
	// action for 3rd party
	do_action('acf/update_500_field', $field);
	
	// return
	return $field;
}