本文整理汇总了PHP中acf_duplicate_fields函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_duplicate_fields函数的具体用法?PHP acf_duplicate_fields怎么用?PHP acf_duplicate_fields使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acf_duplicate_fields函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: duplicate_field
function duplicate_field($field)
{
// get sub fields
$sub_fields = acf_extract_var($field, 'sub_fields');
// save field to get ID
$field = acf_update_field($field);
// duplicate sub fields
acf_duplicate_fields($sub_fields, $field['ID']);
// return
return $field;
}
示例2: duplicate_field
function duplicate_field($field)
{
// vars
$sub_fields = array();
if (!empty($field['layouts'])) {
// loop through layouts
foreach ($field['layouts'] as $layout) {
// extract sub fields
$extra = acf_extract_var($layout, 'sub_fields');
// merge
if (!empty($extra)) {
$sub_fields = array_merge($sub_fields, $extra);
}
}
// foreach
}
// if
// save field to get ID
$field = acf_update_field($field);
// duplicate sub fields
acf_duplicate_fields($sub_fields, $field['ID']);
// return
return $field;
}
示例3: acf_duplicate_field_group
function acf_duplicate_field_group($selector = 0, $new_post_id = 0)
{
// disable JSON to avoid conflicts between DB and JSON
acf_disable_local();
// load the origional field gorup
$field_group = acf_get_field_group($selector);
// bail early if field group did not load correctly
if (empty($field_group)) {
return false;
}
// keep backup of field group
$orig_field_group = $field_group;
// update ID
$field_group['ID'] = $new_post_id;
$field_group['key'] = uniqid('group_');
// add (copy)
if (!$new_post_id) {
$field_group['title'] .= ' (' . __("copy", 'acf') . ')';
}
// save
$field_group = acf_update_field_group($field_group);
// get fields
$fields = acf_get_fields($orig_field_group);
// duplicate fields
acf_duplicate_fields($fields, $field_group['ID']);
// action for 3rd party customization
do_action('acf/duplicate_field_group', $field_group);
// return
return $field_group;
}