WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Авторские Темы для WordPress
функция не описана

acf_field_clone::prepare_field_for_db() public ACF 5.5.0

description

{} Это метод класса: acf_field_clone{}

Хуков нет.

Возвращает

$post_id. (int)

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

$acf_field_clone = new acf_field_clone();
$acf_field_clone->prepare_field_for_db( $field );
$field (обязательный)
-

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

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

Код acf_field_clone::prepare_field_for_db() ACF 5.9.1

<?php
function prepare_field_for_db( $field ) {
	
	// bail early if no sub fields
	if( empty($field['sub_fields']) ) return $field;
	
	
	// bail early if name == _name
	// this is a parent clone field and does not require any modification to sub field names
	if( $field['name'] == $field['_name'] ) return $field;
	
	
	// this is a sub field
	// _name = 'my_field'
	//  name = 'rep_0_my_field'
	// modify all sub fields to add 'rep_0_' name prefix (prefix_name setting has already been applied)
	$length = strlen($field['_name']);
	$prefix = substr($field['name'], 0, -$length);
	
	
	// bail ealry if _name is not found at the end of name (unknown potential error)
	if( $prefix . $field['_name'] !== $field['name'] ) return $field;
	
	//acf_log('== prepare_field_for_db ==');
	//acf_log('- clone name:', $field['name']);
	//acf_log('- clone _name:', $field['_name']);
	
	// loop
	foreach( $field['sub_fields'] as &$sub_field ) {
		
		$sub_field['name'] = $prefix . $sub_field['name'];
		
	}
	
	// return
	return $field;

}