Skip to content

Instantly share code, notes, and snippets.

@gemmadlou
Last active December 8, 2017 17:13
Show Gist options
  • Save gemmadlou/fa762d56582d394e6884420bf65b7e8e to your computer and use it in GitHub Desktop.
Save gemmadlou/fa762d56582d394e6884420bf65b7e8e to your computer and use it in GitHub Desktop.
ACF Flexible Content (Programmatically)
<?php
return [
'group_btm_flex_default',
[
'title' => 'Page Content Builder',
'label' => 'Add content',
'location' => [
[
[
'param' => 'post_type',
'operator' => '==',
'value' => 'page',
],
],
],
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => [
'comments',
'excerpt',
'discussion'
],
'fields' => [
[
'key' => 'field_btm_content_layout',
'name' => 'field_btm_content_layout',
'label' => 'Content Layout',
'type' => 'flexible_content',
'required' => 0,
'button_label' => 'Add content',
'layouts' => [
[
'key' => 'field_btm_panel',
'name' => 'field_btm_panel',
'label' => 'Panel',
'display' => 'block',
'min' => '',
'max' => '',
]
]
]
]
],
[
[
'key' => 'field_btm_panel_image',
'label' => 'Panel Image',
'type' => 'image',
'required' => 0,
'min_width' => 500,
'min_height' => 300,
'return_format'=> 'id',
'parent' => 'field_btm_content_layout', //flex field key
'parent_layout'=> 'field_btm_panel' // layout key
],
[
'key' => 'field_btm_panel_content',
'label' => 'Panel Content',
'type' => 'wysiwyg',
'required' => 0,
'parent' => 'field_btm_content_layout', //flex field key
'parent_layout'=> 'field_btm_panel' // layout key
]
]
];
?>
<?php
if (function_exists('create_meta_fields')) {
$acf_configs = [];
$acf_configs[] = include('acf-panel-config.php');
foreach ($acf_configs as $config) {
create_meta_fields($config);
}
}
?>
<?php
if (!function_exists('create_meta_fields')) {
function create_meta_fields($params) {
$groupname = $params[0];
$group = $params[1];
$fields = $params[2];
add_action( 'init', function() use ($groupname, $group, $fields) {
if ( function_exists( 'acf_add_local_field_group' ) ) {
$group['key'] = $groupname;
acf_add_local_field_group($group);
}
if ( function_exists( 'acf_add_local_field' ) ) {
foreach ($fields as $field) {
$field['name'] = $field['key'];
if (!isset($field['parent'])) {
$field['parent'] = $groupname;
}
acf_add_local_field($field);
}
}
});
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment