Skip to content

Instantly share code, notes, and snippets.

@hwkdev
Last active December 23, 2017 17:51
Show Gist options
  • Save hwkdev/52cfd495f1de1c66b4757b5dcc6dbaa8 to your computer and use it in GitHub Desktop.
Save hwkdev/52cfd495f1de1c66b4757b5dcc6dbaa8 to your computer and use it in GitHub Desktop.
<?php
if(!function_exists('wp_parse_args_recursive')){
function wp_parse_args_recursive($args, $default, $preserve_integer_keys = true){
if (!is_array($default) && !is_object($default))
return wp_parse_args($args, $default);
$is_object = ( is_object($args) || is_object($default) );
$output = array();
foreach(array($default, $args) as $elements){
foreach((array) $elements as $key => $element){
if (is_integer($key) && !$preserve_integer_keys){
$output[] = $element;
}elseif(isset($output[$key]) && (is_array($output[$key]) || is_object($output[$key])) && (is_array($element) || is_object($element)) ){
$output[ $key ] = wp_parse_args_recursive( $element, $output[ $key ], $preserve_integer_keys );
}else{
$output[ $key ] = $element;
}
}
}
return $is_object ? (object) $output: $output;
}
}
function hwk_acf_flexible_content_generate($flexible = array()){
if(empty($flexible))
return;
foreach($flexible as $args){
$args = wp_parse_args_recursive((array) $args, array(
'key' => 'group_hwk_contenu_flexible',
'title' => 'Contenu Flexible',
'fields' => array(
array(
'key' => 'field_hwk_contenu_flexible',
'label' => 'Contenu Flexible',
'name' => 'hwk_contenu_flexible',
'type' => 'flexible_content',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'hide_admin' => 0,
'layouts' => array(),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'user_roles' => array(
0 => 'all',
),
'button_label' => 'Ajouter une section',
'min' => '',
'max' => '',
),
),
'location' => array(),
'menu_order' => 0,
'position' => 'acf_after_title',
'style' => 'seamless',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
// Filtre: Layouts
$layouts = $args['fields'][0]['layouts'];
$args['fields'][0]['layouts'] = apply_filters($args['key'] . '_layouts', $layouts);
// Filtre: Locations
$location = $args['location'];
$args['location'] = apply_filters($args['key'] . '_location', $location);
acf_add_local_field_group($args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment