feature: Add ACF admin field group support with plugin fallback

This commit is contained in:
Keith Solomon
2026-05-13 15:35:56 -05:00
parent b450b7329d
commit 30c63e4479
4 changed files with 49 additions and 2 deletions
+38
View File
@@ -9,10 +9,48 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Check whether an ACF field group created in the admin targets the event post type.
*
* @return bool True if an external field group is assigned to events.
*/
function events_has_admin_field_group() {
if ( ! function_exists( 'acf_get_field_groups' ) ) {
return false;
}
$groups = acf_get_field_groups( array( 'post_type' => 'event' ) );
foreach ( $groups as $group ) {
if ( isset( $group['active'] ) && ! $group['active'] ) {
continue;
}
if (
isset( $group['key'], $group['local'] )
&& 'group_61b0c5f5a3e7e' === $group['key']
&& 'php' === $group['local']
) {
continue;
}
return true;
}
return false;
}
/**
* Register the ACF field group.
*
* Skips registration when an admin-created field group is already
* assigned to the event post type, allowing full editorial control.
*/
function events_register_acf_fields() {
if ( events_has_admin_field_group() ) {
return;
}
if ( function_exists( 'acf_add_local_field_group' ) ) :
acf_add_local_field_group(