Skip to content

Commit ce84c73

Browse files
committed
Merge commit '9a81fa17be2b21ee72cb8a1bcdb21ed0b0df47b6' into release/v2.3.0
2 parents 6500524 + 9a81fa1 commit ce84c73

21 files changed

+65155
-316
lines changed

.github/workflows/testing-integration.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ jobs:
2424
wpgraphql_content_blocks: [ false ]
2525
acf_version: [ 5.12.4, 6.1.8 ]
2626
include:
27+
- php: '8.2'
28+
wordpress: '6.5'
29+
acf_pro: true
30+
wpgraphql_content_blocks: true
2731
- php: '8.2'
2832
wordpress: '6.4.0'
2933
acf_pro: true

composer.lock

Lines changed: 248 additions & 245 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/app.setup.sh

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ ACF_VERSION=${ACF_VERSION-"latest"}
1010
ACF_PRO=${ACF_PRO-false}
1111
WPGRAPHQL_CONTENT_BLOCKS=${WPGRAPHQL_CONTENT_BLOCKS-false}
1212
WPGRAPHQL_CONTENT_BLOCKS_VERSION=${WPGRAPHQL_CONTENT_BLOCKS_VERSION-"latest"}
13+
WPGRAPHQL_GIT_REPO=${WPGRAPHQL_GIT_REPO-}
14+
WPGRAPHQL_GIT_BRANCH=${WPGRAPHQL_GIT_BRANCH-"develop"}
1315

1416
#// fallback to hello.php as a hack. dont love this, but we have to pass a slug.
1517
export WPGRAPHQL_CONTENT_BLOCKS_PLUGIN_SLUG=${WPGRAPHQL_CONTENT_BLOCKS_PLUGIN_SLUG-'hello.php'}
@@ -36,15 +38,31 @@ apt-get -y update
3638
apt-get -y install jq
3739

3840
if [ ! -f "${PLUGINS_DIR}/wp-graphql/wp-graphql.php" ]; then
39-
# WPGRAPHQL_VERSION in format like v1.2.3 or latest
40-
echo "Install wp-graphql version (${WPGRAPHQL_VERSION})"
41-
if [[ -z ${WPGRAPHQL_VERSION} || "${WPGRAPHQL_VERSION}" == "latest" ]]; then
42-
echo "Installing latest WPGraphQL from WordPress.org"
43-
wp plugin install wp-graphql --activate --allow-root
44-
else
45-
echo "Installing WPGraphQL from Github"
46-
wp plugin install "https://downloads.wordpress.org/plugin/wp-graphql.${WPGRAPHQL_VERSION-1.4.3}.zip" --allow-root --activate
47-
fi
41+
42+
43+
# if WPGRAPHQL_GIT_REPO is set, we'll install from the repo
44+
if [[ -n ${WPGRAPHQL_GIT_REPO} ]]; then
45+
echo "Installing WPGraphQL from GitHub repo ${WPGRAPHQL_GIT_REPO}"
46+
# Clone the repository
47+
git clone -b ${WPGRAPHQL_GIT_BRANCH} ${WPGRAPHQL_GIT_REPO} "${PLUGINS_DIR}/wp-graphql"
48+
# Navigate to the plugin directory
49+
cd "${PLUGINS_DIR}/wp-graphql"
50+
# Install dependencies with Composer
51+
composer install --no-dev
52+
# Optionally activate the plugin using wp-cli
53+
wp plugin activate wp-graphql --allow-root
54+
else
55+
# WPGRAPHQL_VERSION in format like v1.2.3 or latest
56+
echo "Install wp-graphql version (${WPGRAPHQL_VERSION})"
57+
if [[ -z ${WPGRAPHQL_VERSION} || "${WPGRAPHQL_VERSION}" == "latest" ]]; then
58+
echo "Installing latest WPGraphQL from WordPress.org"
59+
wp plugin install wp-graphql --activate --allow-root
60+
else
61+
echo "Installing WPGraphQL from Github"
62+
wp plugin install "https://downloads.wordpress.org/plugin/wp-graphql.${WPGRAPHQL_VERSION-1.4.3}.zip" --allow-root --activate
63+
fi
64+
fi
65+
4866
fi
4967

5068
# Activate the plugin

phpstan/constants.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
* Constants defined in this file are to help phpstan analyze code where constants outside the plugin (WordPress core constants, etc) are being used
44
*/
55

6-
define( 'WP_LANG_DIR', true );
76
define( 'SAVEQUERIES', true );
87
define( 'WPGRAPHQL_PLUGIN_URL', true );
9-
define( 'WP_CONTENT_DIR', true );
10-
define( 'WP_PLUGIN_DIR', true );
118
define( 'PHPSTAN', true );

readme.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
=== WPGraphQL for ACF ===
22
Contributors: jasonbahl, wpgraphql
33
Tags: GraphQL, ACF, API, NextJS, Faust, Headless, Decoupled, React, Vue, Svelte, JSON, REST
4-
Requires at least: 6.0
5-
Tested up to: 6.4
6-
Requires PHP: 7.4
4+
Requires at least: 5.9
5+
Tested up to: 6.5
6+
Requires PHP: 7.3
77
Stable Tag: 2.2.0
88
License: GPL-3
99
License URI: https://www.gnu.org/licenses/gpl-3.0.html

src/Admin/Settings.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,39 +139,45 @@ function ( $acf_field ) use ( $field_type ) {
139139
* Handle the AJAX callback for converting ACF Location settings to GraphQL Types
140140
*/
141141
public function graphql_types_ajax_callback(): void {
142-
if ( ! isset( $_POST['data'] ) ) {
142+
if ( ! isset( $_REQUEST['data'] ) ) {
143143
echo esc_html( __( 'No location rules were found', 'wpgraphql-acf' ) );
144144

145145
/** @noinspection ForgottenDebugOutputInspection */
146146
wp_die();
147147
}
148148

149+
if ( empty( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_REQUEST['nonce'] ), 'wp_graphql_acf' ) ) {
150+
wp_send_json_error();
151+
}
152+
149153
$form_data = [];
150-
$sanitized_post_data = wp_strip_all_tags( $_POST['data'] );
154+
$sanitized_post_data = wp_strip_all_tags( $_REQUEST['data'] );
151155

152156
parse_str( $sanitized_post_data, $form_data );
153157

154-
if ( empty( $form_data ) || ! isset( $form_data['acf_field_group'] ) ) {
158+
if ( empty( $form_data ) ) {
155159
wp_send_json( __( 'No form data.', 'wpgraphql-acf' ) );
156160
}
157161

158-
if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ), 'wp_graphql_acf' ) ) {
159-
wp_send_json_error();
162+
if ( empty( $form_data['acf_field_group']['location'] ) ) {
163+
wp_send_json( __( 'No field group locations found.', 'wpgraphql-acf' ) );
160164
}
161165

162166
$field_group = $form_data['acf_field_group'];
163-
$rules = new LocationRules( [ $field_group ] );
167+
168+
$rules = new LocationRules( [ $field_group ] );
164169
$rules->determine_location_rules();
165170

166-
$group_title = $field_group['title'] ?? '';
171+
$group_title = $form_data['post_title'] ?? '';
167172
$group_name = $field_group['graphql_field_name'] ?? $group_title;
168173
$group_name = \WPGraphQL\Utils\Utils::format_field_name( $group_name, true );
169174

170175
$all_rules = $rules->get_rules();
171-
if ( isset( $all_rules[ $group_name ] ) ) {
176+
177+
if ( isset( $all_rules[ strtolower( $group_name ) ] ) ) {
172178
wp_send_json(
173179
[
174-
'graphql_types' => array_values( $all_rules[ $group_name ] ),
180+
'graphql_types' => array_values( $all_rules[ strtolower( $group_name ) ] ),
175181
]
176182
);
177183
}

src/FieldConfig.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ public function get_parent_graphql_type_name( array $acf_field, ?string $prepend
105105
} elseif ( ! empty( $parent_group ) ) {
106106
$type_name = $this->registry->get_field_group_graphql_type_name( $parent_group );
107107
$type_name = $this->get_parent_graphql_type_name( $parent_group, $type_name );
108-
} else {
109-
$type_name = $this->get_parent_graphql_type_name( $acf_field, '' );
110108
}
111109
}
112110

@@ -411,6 +409,11 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI
411409
return $this->prepare_acf_field_value( $root[ $field_config['__key'] ], $node, $node_id, $field_config );
412410
}
413411

412+
// Else check if the values are being passed down via the name
413+
if ( isset( $field_config['name'] ) && ! empty( $root[ '_' . $field_config['name'] ] ) ) {
414+
return $this->prepare_acf_field_value( $root[ '_' . $field_config['name'] ], $node, $node_id, $field_config );
415+
}
416+
414417
// Else check if the values are being passed down via the name
415418
if ( isset( $field_config['name'] ) && ! empty( $root[ $field_config['name'] ] ) ) {
416419
return $this->prepare_acf_field_value( $root[ $field_config['name'] ], $node, $node_id, $field_config );
@@ -603,7 +606,9 @@ public function register_graphql_connections( array $config ): void {
603606
}
604607

605608
// Register the connection to the Field Group Type
606-
register_graphql_connection( $connection_config );
609+
if ( defined( 'WPGRAPHQL_VERSION' ) && version_compare( WPGRAPHQL_VERSION, '1.23.0', '<=' ) ) {
610+
register_graphql_connection( $connection_config );
611+
}
607612

608613
// Register the connection to the Field Group Fields Interface
609614
register_graphql_connection( array_merge( $connection_config, [ 'fromType' => $type_name . '_Fields' ] ) );

src/FieldType/CloneField.php

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ public static function register_field_type(): void {
1515
'clone',
1616
[
1717
'graphql_type' => static function ( FieldConfig $field_config, AcfGraphQLFieldType $acf_field_type ) {
18+
1819
$sub_field_group = $field_config->get_raw_acf_field();
1920
$parent_type = $field_config->get_parent_graphql_type_name( $sub_field_group );
2021
$field_name = $field_config->get_graphql_field_name();
21-
$registry = $field_config->get_registry();
2222
$type_name = Utils::format_type_name( $parent_type . ' ' . $field_name );
2323
$prefix_name = $sub_field_group['prefix_name'] ?? false;
2424

25+
// If the "Clone" field has not set a "prefix_name",
26+
// return NULL to prevent registering a new type
27+
// The cloned
28+
if ( ! $prefix_name ) {
29+
return 'NULL';
30+
}
31+
2532
$cloned_fields = array_filter(
2633
array_map(
2734
static function ( $cloned ) {
@@ -45,37 +52,16 @@ static function ( $cloned ) use ( $field_config ) {
4552
);
4653

4754
if ( ! empty( $cloned_group_interfaces ) ) {
48-
if ( ! $prefix_name ) {
49-
register_graphql_interfaces_to_types( $cloned_group_interfaces, [ $parent_type ] );
50-
} else {
51-
$type_name = self::register_prefixed_clone_field_type( $type_name, $sub_field_group, $cloned_fields, $field_config );
52-
register_graphql_interfaces_to_types( $cloned_group_interfaces, [ $type_name ] );
53-
return $type_name;
54-
}
55+
$type_name = self::register_prefixed_clone_field_type( $type_name, $sub_field_group, $cloned_fields, $field_config );
56+
register_graphql_interfaces_to_types( $cloned_group_interfaces, [ $type_name ] );
57+
return $type_name;
5558
}
5659

57-
5860
// If the "Clone" field has cloned individual fields
5961
if ( ! empty( $cloned_fields ) ) {
60-
61-
// If the clone field is NOT set to use "prefix_name"
62-
if ( ! $prefix_name ) {
63-
64-
// Map over the cloned fields and register them to the parent type
65-
foreach ( $cloned_fields as $cloned_field ) {
66-
$field_config = $registry->map_acf_field_to_graphql( $cloned_field, $sub_field_group );
67-
if ( ! empty( $field_config['name'] ) ) {
68-
register_graphql_field( $parent_type, $field_config['name'], $field_config );
69-
}
70-
}
71-
72-
// If the Clone field is set to use "prefix_name"
73-
// Register a new Object Type with the cloned fields, and return
74-
// the new type.
75-
} else {
76-
return self::register_prefixed_clone_field_type( $type_name, $sub_field_group, $cloned_fields, $field_config );
77-
}
62+
return self::register_prefixed_clone_field_type( $type_name, $sub_field_group, $cloned_fields, $field_config );
7863
}
64+
7965
// Bail by returning a NULL type
8066
return 'NULL';
8167
},

src/FieldType/FlexibleContent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static function ( $field ) use ( $layout ) {
6969

7070
return isset( $field['parent_layout'] ) && $layout['key'] === $field['parent_layout'] ? $field : null;
7171
},
72-
acf_get_raw_fields( $layout['key'] )
72+
acf_get_fields( $layout['key'] )
7373
)
7474
);
7575

src/FieldType/Group.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,59 @@ public static function register_field_type(): void {
2626
$sub_field_group['graphql_field_name'] = $type_name;
2727
$sub_field_group['parent'] = $sub_field_group['key'];
2828

29+
// Determine if the group is a clone field
30+
$cloned_type = null;
31+
32+
// if the field group is actually a cloned field group, we
33+
// can return the GraphQL Type of the cloned field group
34+
if ( isset( $sub_field_group['_clone'] ) ) {
35+
$cloned_from = acf_get_field( $sub_field_group['_clone'] );
36+
37+
if ( ! empty( $cloned_from['clone'] ) && is_array( $cloned_from['clone'] ) ) {
38+
foreach ( $cloned_from['clone'] as $clone_field ) {
39+
$cloned_group = acf_get_field_group( $clone_field );
40+
41+
// if there is no cloned group, continue to the next clone field
42+
if ( ! $cloned_group ) {
43+
continue;
44+
}
45+
46+
// if the cloned group is not an ACF field group, continue to the next clone field
47+
if ( ! acf_is_field_group( $cloned_group ) ) {
48+
continue;
49+
}
50+
51+
// if the cloned group should not show in GraphQL, continue to the next clone field
52+
if ( ! $field_config->get_registry()->should_field_group_show_in_graphql( $cloned_group ) ) {
53+
continue;
54+
}
55+
56+
// determine the GraphQL Type of the cloned field group
57+
$cloned_type = $field_config->get_registry()->get_field_group_graphql_type_name( $cloned_group );
58+
break;
59+
}
60+
}
61+
}
62+
63+
// If the group is a clone field, return the cloned type instead of registering
64+
// another Type in the registry
65+
if ( $cloned_type ) {
66+
$cloned_type_name = Utils::format_type_name( $cloned_type . ' ' . $field_name );
67+
if ( $field_config->get_registry()->has_registered_field_group( $cloned_type_name ) ) {
68+
return $cloned_type_name;
69+
}
70+
71+
$sub_field_group['graphql_type_name'] = $cloned_type_name;
72+
$sub_field_group['graphql_field_name'] = $cloned_type_name;
73+
$field_config->get_registry()->register_acf_field_groups_to_graphql(
74+
[
75+
$sub_field_group,
76+
]
77+
);
78+
79+
return $cloned_type_name;
80+
}
81+
2982
$field_config->get_registry()->register_acf_field_groups_to_graphql(
3083
[
3184
$sub_field_group,

0 commit comments

Comments
 (0)