diff --git a/src/class-config.php b/src/class-config.php index 91d2dc6..07eabc5 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -122,6 +122,32 @@ public static function camel_case( $str, array $no_strip = [] ) { return $str; } + /** + * Add attribute to the ACF screen data. + * + * When ACF checks the location rules we need a way to know it's from this + * file. + */ + public function add_wp_graphql_acf_to_acf_screen($screen, $field_group) { + $screen['wp-graphql-acf'] = true; + return $screen; + } + + /** + * Get ACF field groups. + * + * Get the field groups associated with the post type + */ + protected function get_acf_field_groups($args = array()) { + add_filter('acf/location/screen', array( $this, 'add_wp_graphql_acf_to_acf_screen' ), 10, 2); + + $field_groups = acf_get_field_groups($args); + + remove_filter('acf/location/screen', array( $this, 'add_wp_graphql_acf_to_acf_screen' ), 10); + + return $field_groups; + } + /** * Add ACF Fields to Post Object Types. * @@ -150,7 +176,7 @@ protected function add_acf_fields_to_post_object_types() { /** * Get the field groups associated with the post type */ - $field_groups = acf_get_field_groups( + $field_groups = $this->get_acf_field_groups( [ 'post_type' => $post_type, ] @@ -1145,7 +1171,7 @@ protected function add_acf_fields_to_term_objects() { /** * Get the field groups associated with the taxonomy */ - $field_groups = acf_get_field_groups( + $field_groups = $this->get_acf_field_groups( [ 'taxonomy' => $taxonomy, ] @@ -1204,7 +1230,7 @@ protected function add_acf_fields_to_comments() { /** * Get the field groups associated with the taxonomy */ - $field_groups = acf_get_field_groups(); + $field_groups = $this->get_acf_field_groups(); foreach ( $field_groups as $field_group ) { if ( ! empty( $field_group['location'] ) && is_array( $field_group['location'] ) ) { @@ -1265,7 +1291,7 @@ protected function add_acf_fields_to_menus() { /** * Get the field groups associated with the taxonomy */ - $field_groups = acf_get_field_groups(); + $field_groups = $this->get_acf_field_groups(); foreach ( $field_groups as $field_group ) { if ( ! empty( $field_group['location'] ) && is_array( $field_group['location'] ) ) { @@ -1327,7 +1353,7 @@ protected function add_acf_fields_to_menu_items() { /** * Get the field groups associated with the taxonomy */ - $field_groups = acf_get_field_groups(); + $field_groups = $this->get_acf_field_groups(); foreach ( $field_groups as $field_group ) { if ( ! empty( $field_group['location'] ) && is_array( $field_group['location'] ) ) { foreach ( $field_group['location'] as $locations ) { @@ -1386,7 +1412,7 @@ protected function add_acf_fields_to_media_items() { /** * Get the field groups associated with the taxonomy */ - $field_groups = acf_get_field_groups(); + $field_groups = $this->get_acf_field_groups(); foreach ( $field_groups as $field_group ) { if ( ! empty( $field_group['location'] ) && is_array( $field_group['location'] ) ) { @@ -1441,7 +1467,7 @@ protected function add_acf_fields_to_individual_posts() { /** * Get the field groups associated with the taxonomy */ - $field_groups = acf_get_field_groups(); + $field_groups = $this->get_acf_field_groups(); $allowed_post_types = get_post_types( [ 'show_ui' => true, @@ -1544,14 +1570,14 @@ protected function add_acf_fields_to_users() { /** * Get the field groups associated with the User edit form */ - $user_edit_field_groups = acf_get_field_groups( [ + $user_edit_field_groups = $this->get_acf_field_groups( [ 'user_form' => 'edit', ] ); /** * Get the field groups associated with the User register form */ - $user_register_field_groups = acf_get_field_groups( [ + $user_register_field_groups = $this->get_acf_field_groups( [ 'user_form' => 'register', ] ); @@ -1624,7 +1650,7 @@ protected function add_acf_fields_to_options_pages() { /** * Get the field groups associated with the options page */ - $field_groups = acf_get_field_groups( + $field_groups = $this->get_acf_field_groups( [ 'options_page' => $options_page['menu_slug'], ]