Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

ACF Location screen context now has "wp-graphql-acf" set to true, thi… #134

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions src/class-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
]
Expand Down Expand Up @@ -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,
]
Expand Down Expand Up @@ -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'] ) ) {
Expand Down Expand Up @@ -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'] ) ) {
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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'] ) ) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
] );

Expand Down Expand Up @@ -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'],
]
Expand Down