Skip to content

Instantly share code, notes, and snippets.

<?php
add_filter('group_hwk_contenu_flexible_location', 'hwk_post_type_portfolio_contenu_flexible_location');
function hwk_post_type_portfolio_contenu_flexible_location($location){
$location[] = array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'portfolio',
)
);
<?php
add_filter('group_hwk_contenu_flexible_location', 'hwk_post_type_portfolio_contenu_flexible_location_complexe');
function hwk_post_type_portfolio_contenu_flexible_location_complexe($location){
// OR
$location[] = array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'portfolio',
<?php
add_action('acf/field_group/admin_head', 'hwk_acf_flexible_metabox');
function hwk_acf_flexible_metabox(){
global $field_group;
if(isset($field_group['hwk_flexible_dynamique']) && !empty($field_group['hwk_flexible_dynamique'])){
add_meta_box('acf-field-group-layouts-flexible', __('Flexible Layouts', 'acf'), function(){
global $field_group;
$group = $field_group;
<?php
add_action('acf/field_group/admin_head', 'hwk_acf_flexible_layout_metabox');
function hwk_acf_flexible_layout_metabox(){
global $field_group;
$match = false;
foreach($field_group['location'] as $location){
foreach($location as $rule){
if($rule['param'] == 'hwk_flexible_content_rule'){
$match = true;
<?php
// ACF: Location Rules Types
add_filter('acf/location/rule_types', 'hwk_acf_flexible_location_rules_types');
function hwk_acf_flexible_location_rules_types($choices){
$choices['Basic']['hwk_flexible_content_rule'] = 'Contenu Flexible';
return $choices;
}
// ACF: Location Rules Values
add_filter('acf/location/rule_values/hwk_flexible_content_rule', 'hwk_acf_flexible_location_rules_values', 99);
<?php
add_action('init', 'hwk_acf_flexible_create');
function hwk_acf_flexible_create(){
foreach(hwk_acf_get_flexible() as $parent){
$parent_title = $parent['title'];
$parent_name = str_replace('-', '_', sanitize_title($parent['title']));
$layouts = array();
<?php
add_filter('acf/load_field/type=flexible_content', 'hwk_acf_flexible_filter');
function hwk_acf_flexible_filter($field){
if(!is_admin() || wp_doing_ajax() || get_post_type() == 'acf-field-group')
return $field;
$parent = _acf_get_field_group_by_key($field['parent']);
if(!isset($parent['hwk_flexible_dynamique']) || empty($parent['hwk_flexible_dynamique']))
return $field;
<?php
// ACF: Flexible Get
function hwk_acf_get_flexible(){
$return = array();
acf_enable_filter('local');
foreach(acf_get_field_groups() as $group){
if(isset($group['hwk_flexible_dynamique']) && !empty($group['hwk_flexible_dynamique']))
$return[] = $group;
}
<?php
add_action('acf/input/admin_head', 'hwk_acf_flexible_head');
function hwk_acf_flexible_head(){ ?>
<script type="text/javascript">
jQuery(document).ready(function($){
$('[data-name="hwk_hidden_parent"]').each(function(){
$(this).closest('.acf-postbox').addClass('acf-hidden');
});
});