Created
December 25, 2017 14:12
-
-
Save hawkidoki/927896e92f5310bdbcac9e6354083231 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
function hwk_acf_flexible_location_rules_values($choices){ | |
if($groups = hwk_acf_get_flexible()){ | |
foreach($groups as $group){ | |
if($field = acf_get_fields($group)) | |
$choices[$field[0]['name']] = (isset($field[0]['label']) && !empty($field[0]['label'])) ? $field[0]['label'] : $field[0]['name']; | |
} | |
} | |
return $choices; | |
} | |
// ACF: Location Rules Screen | |
add_filter('acf/location/screen', 'hwk_acf_flexible_location_screen', 10, 2); | |
function hwk_acf_flexible_location_screen($options, $group){ | |
foreach(hwk_acf_get_layouts() as $k => $group_keys){ | |
if(in_array($group['key'], $group_keys)){ | |
$options['hwk_flexible_content_rule'] = true; | |
break; | |
} | |
} | |
return $options; | |
} | |
// ACF: Location Rules Match | |
add_filter('acf/location/rule_match/hwk_flexible_content_rule', 'hwk_acf_flexible_location_rules_match', 10, 3); | |
function hwk_acf_flexible_location_rules_match($match, $rule, $options){ | |
if(isset($options['hwk_flexible_content_rule']) && $options['hwk_flexible_content_rule'] === true) | |
$match = true; | |
return $match; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment