acf_upgrade_500_fields()ACF 5.7.4

acf_upgrade_500_fields

Upgrades all ACF4 fields to ACF5 from a specific field group

Хуков нет.

Возвращает

null. Ничего.

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

acf_upgrade_500_fields( $ofg, $nfg );
$ofg(объект) (обязательный)
The old field group post object.
$nfg(массив) (обязательный)
The new field group array.

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

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

Код acf_upgrade_500_fields() ACF 5.10.2

function acf_upgrade_500_fields( $ofg, $nfg ) {

	// log
	acf_dev_log( 'ACF Upgrade 5.0.0 Fields.' );

	// global
	global $wpdb;

	// get field from postmeta
	$rows = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND meta_key LIKE %s", $ofg->ID, 'field_%' ), ARRAY_A );

	// check
	if ( $rows ) {

		// vars
		$checked = array();

		// loop
		foreach ( $rows as $row ) {

			// vars
			$field = $row['meta_value'];
			$field = maybe_unserialize( $field );
			$field = maybe_unserialize( $field ); // run again for WPML

			// bail early if key already migrated (potential duplicates in DB)
			if ( isset( $checked[ $field['key'] ] ) ) {
				continue;
			}
			$checked[ $field['key'] ] = 1;

			// add parent
			$field['parent'] = $nfg['ID'];

			// migrate field
			$field = acf_upgrade_500_field( $field );
		}
	}
}