-
-
Save dgoze/ab025022d9f784f64881f16f54311d8b to your computer and use it in GitHub Desktop.
Adds ACF Field Group location rule for Post Type Support.
This file contains hidden or 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 | |
/** | |
* Plugin Name: Field Group Location: Post Type Supports | |
* Plugin URI: http://qwp6t.me/acf-post-type-supports | |
* Description: Adds ACF Field Group location rule for Post Type Support. NOTE: You must first declare the supported feature in your theme. | |
* Version: 1.0.0 | |
* Author: QWp6t | |
* Author URI: http://qwp6t.me | |
* License: MIT License | |
*/ | |
add_filter('acf/location/rule_types', function ($choices) { | |
$choices[__('Post', 'acf')]['post_type_supports'] = __('Post Type Supports', 'qwp6t'); | |
return $choices; | |
}); | |
add_filter('acf/location/rule_values/post_type_supports', function ($choices = []) { | |
foreach ($GLOBALS['_wp_post_type_features'] as $post_type) { | |
foreach ($post_type as $feature => $args) { | |
$choices[$feature] = $feature; | |
} | |
} | |
$choices = array_unique($choices); | |
asort($choices); | |
return $choices; | |
}, 10, 1); | |
add_filter('acf/location/rule_match/post_type_supports', function ($match, array $rule, array $options) { | |
if (!$options['post_id'] || $match) { | |
return false; | |
} | |
$post_type = $options['post_type'] ?: get_post_type($options['post_id']); | |
$match = post_type_supports($post_type, $rule['value']); | |
return ($rule['operator'] == "!=") ? !$match : $match; | |
}, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment