__('Note'),
'name' => 'acfe_note',
'prefix' => 'acf_field_group',
'type' => 'textarea',
'instructions' => __('Personal note. Only visible to administrators'),
'value' => (isset($field_group['acfe_note'])) ? $field_group['acfe_note'] : '',
'required' => false,
));
}
/**
* Field Group Options: Data
*/
add_action('acf/field_group/admin_head', 'acfe_render_field_group_settings');
function acfe_render_field_group_settings(){
add_meta_box('acf-field-group-acfe', __('Data', 'acfe'), function(){
global $field_group;
acf_render_field_wrap(array(
'label' => __('Custom meta data'),
'name' => 'acfe_meta',
'key' => 'acfe_meta',
'instructions' => '',
'prefix' => 'acf_field_group',
'type' => 'repeater',
'button_label' => __('+ Add row'),
'required' => false,
'layout' => 'table',
'value' => (isset($field_group['acfe_meta'])) ? $field_group['acfe_meta'] : array(),
'sub_fields' => array(
array(
'label' => __('Key'),
'name' => 'acfe_meta_key',
'key' => 'acfe_meta_key',
'prefix' => '',
'_name' => '',
'_prepare' => '',
'type' => 'text',
'instructions' => false,
'required' => false,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
),
array(
'label' => __('Value'),
'name' => 'acfe_meta_value',
'key' => 'acfe_meta_value',
'prefix' => '',
'_name' => '',
'_prepare' => '',
'type' => 'text',
'instructions' => false,
'required' => false,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
),
)
));
acf_render_field_wrap(array(
'label' => __('Field group data'),
'instructions' => __('View raw data'),
'type' => 'acfe_dynamic_message',
'name' => 'acfe_data',
'prefix' => 'acf_field_group',
'value' => $field_group['key'],
));
?>
__('Display title', 'acfe'),
'instructions' => __('Render this title on edit post screen', 'acfe'),
'type' => 'text',
'name' => 'acfe_display_title',
'prefix' => 'acf_field_group',
'value' => (isset($field_group['acfe_display_title'])) ? $field_group['acfe_display_title'] : '',
'placeholder' => '',
'prepend' => '',
'append' => ''
));
if(acfe_is_field_group_json_desync($field_group)){
acf_render_field_wrap(array(
'label' => __('Json Desync'),
'instructions' => __('Local json file is different from this version. If you manually synchronize it, you will lose your current field group settings'),
'type' => 'acfe_dynamic_message',
'name' => 'acfe_sync_available',
'prefix' => 'acf_field_group',
'value' => $field_group['key'],
));
}
acf_render_field_wrap(array(
'label' => __('Auto Sync'),
'instructions' => '',
'type' => 'checkbox',
'name' => 'acfe_autosync',
'prefix' => 'acf_field_group',
'value' => (isset($field_group['acfe_autosync']) && !empty($field_group['acfe_autosync'])) ? $field_group['acfe_autosync'] : array(),
'choices' => array(
'php' => 'PHP',
'json' => 'Json',
)
));
acf_render_field_wrap(array(
'label' => __('Permissions'),
'name' => 'acfe_permissions',
'prefix' => 'acf_field_group',
'type' => 'checkbox',
'instructions' => __('Select user roles that are allowed to view and edit this field group in post edition'),
'required' => false,
'default_value' => false,
'choices' => acfe_get_roles(),
'value' => (isset($field_group['acfe_permissions'])) ? $field_group['acfe_permissions'] : array(),
'layout' => 'vertical'
));
?>
Synchronize';
}
/**
* Render: Sync Warnings
*/
add_action('acf/render_field', 'acfe_render_field_acfe_sync_warnings', 5);
function acfe_render_field_acfe_sync_warnings($field){
if($field['_name'] != 'acfe_autosync')
return;
global $field_group;
// PHP
// Fix to load local fiel groups
acf_enable_filters();
if(acfe_has_field_group_autosync($field_group, 'php') && !acf_get_setting('acfe_php_found')){
echo ' Folder /acfe-php was not found in your theme. You must create it to activate PHP Sync
';
}
elseif(!acfe_has_field_group_autosync($field_group, 'php') && acfe_has_field_group_autosync_file($field_group, 'php')){
echo ' This field group is registered via a third-party PHP code
';
}
elseif(acfe_has_field_group_autosync($field_group, 'php') && !acfe_has_field_group_autosync_file($field_group, 'php')){
echo ' This field group is not registered locally. Update it to resync PHP
';
}
// Re-disable filters, as natively
acf_disable_filters();
// Json
if(!acfe_has_field_group_autosync($field_group, 'json') && acfe_has_field_group_autosync_file($field_group, 'json')){
echo ' ' . $field_group['key'] . '.json was found. Activate Json sync to keep it updated
';
}
elseif(acfe_has_field_group_autosync($field_group, 'json') && !acfe_has_field_group_autosync_file($field_group, 'json')){
echo ' ' . $field_group['key'] . '.json was not found. Update this field group to regenerate it
';
}
}
/**
* Render: Data button
*/
add_action('acf/render_field/name=acfe_data', 'acfe_render_field_group_data');
function acfe_render_field_group_data($field){
$field_group = acf_get_field_group($field['value']);
if(!$field_group){
echo '' . __('Data') . '';
return;
}
echo '' . __('Data') . '';
echo '' . print_r($field_group, true) . '
';
}
/**
* Hooks: Display title (post edit)
*/
add_filter('acf/get_field_groups', 'acfe_render_field_groups', 999);
function acfe_render_field_groups($field_groups){
$check_current_screen = acf_is_screen(array(
'edit-acf-field-group',
'acf-field-group',
'acf_page_acf-tools'
));
if($check_current_screen)
return $field_groups;
foreach($field_groups as &$field_group){
if(!isset($field_group['acfe_display_title']) || empty($field_group['acfe_display_title']))
continue;
$field_group['title'] = $field_group['acfe_display_title'];
}
return $field_groups;
}
/**
* Hooks: Permissions (post edit)
*/
add_filter('acf/get_field_groups', 'acfe_permissions_field_groups', 999);
function acfe_permissions_field_groups($field_groups){
$check_current_screen = acf_is_screen(array(
'edit-acf-field-group',
'acf-field-group',
'acf_page_acf-tools'
));
if($check_current_screen)
return $field_groups;
$current_user_roles = acfe_get_current_user_roles();
foreach($field_groups as $key => $field_group){
if(!isset($field_group['acfe_permissions']) || empty($field_group['acfe_permissions']))
continue;
$render_field_group = false;
foreach($current_user_roles as $current_user_role){
foreach($field_group['acfe_permissions'] as $field_group_role){
if($current_user_role !== $field_group_role)
continue;
$render_field_group = true;
break;
}
if($render_field_group)
break;
}
if(!$render_field_group)
unset($field_groups[$key]);
}
return $field_groups;
}
/**
* Hooks: Default label placement - Left
*/
add_filter('acf/validate_field_group', 'acfc_field_group_default_options');
function acfc_field_group_default_options($field_group){
if(!isset($field_group['location']) || empty($field_group['location']))
$field_group['label_placement'] = 'left';
return $field_group;
}