From 3ed252ad81a3d7588371a5dc8c378b8d15f36b32 Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Fri, 10 Sep 2021 11:06:56 +0200 Subject: [PATCH 01/12] Update README.md Added highlight to the php code in Registering Fields in PHP section --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ad8cba..320adcd 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Setting the value of this field to "Yes" will show the field group in the WPGrap When registering ACF Fields in PHP, you need to add `show_in_graphql` and `graphql_field_name` when defining your field group. See below as an example. -``` +```php function my_acf_add_local_field_groups() { acf_add_local_field_group(array( From 53372add3104a12933a804f9079b5bb66fa1bd7f Mon Sep 17 00:00:00 2001 From: Esa-Matti Suuronen Date: Wed, 20 Oct 2021 15:28:01 +0300 Subject: [PATCH 02/12] Use date_i18n() to set correct timezone for date time fields --- src/class-config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class-config.php b/src/class-config.php index 927f2b3..e10c784 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -636,7 +636,7 @@ protected function register_graphql_field( string $type_name, string $field_name $value = $this->get_acf_field_value( $root, $acf_field, true ); if ( ! empty( $value ) && ! empty( $acf_field['return_format'] ) ) { - $value = date( $acf_field['return_format'], strtotime( $value ) ); + $value = date_i18n( $acf_field['return_format'], strtotime( $value ) ); } return ! empty( $value ) ? $value : null; }, From 56cd1d369e99a710afc7601be2817e3e76e94ccb Mon Sep 17 00:00:00 2001 From: rsm0128 Date: Wed, 10 Nov 2021 15:50:37 +0900 Subject: [PATCH 03/12] fix #300, #85, #100 --- src/class-config.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index 927f2b3..08c3c4b 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -689,12 +689,14 @@ protected function register_graphql_field( string $type_name, string $field_name $post_object = get_post( $post_id ); if ( $post_object instanceof \WP_Post ) { $post_model = new Post( $post_object ); - $relationship[] = $post_model; + if ( 'private' != $post_model->get_visibility() ) { + $relationship[] = $post_model; + } } } } - return isset( $value ) ? $relationship : null; + return empty( $relationship ) ? null : $relationship; }, ]; From 61b16a6dcb347ef865ca7a9cc764ddb5ed15497b Mon Sep 17 00:00:00 2001 From: rsm0128 Date: Wed, 10 Nov 2021 22:41:20 +0900 Subject: [PATCH 04/12] updated unite test --- tests/wpunit/ExplicitOptionsTest.php | 3 ++- tests/wpunit/PostObjectFieldsTest.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/wpunit/ExplicitOptionsTest.php b/tests/wpunit/ExplicitOptionsTest.php index 4ddfc78..0c255aa 100644 --- a/tests/wpunit/ExplicitOptionsTest.php +++ b/tests/wpunit/ExplicitOptionsTest.php @@ -89,6 +89,7 @@ public function testExplicitOptions() { 'show_in_graphql' => true, 'graphql_single_name' => 'acfCpt', 'graphql_plural_name' => 'acfCpts', + 'public' => true, ] ); @@ -148,7 +149,7 @@ public function testExplicitOptions() { ] ); - $expected_text_3 = 'test value2'; + $expected_text_3 = 'test value3'; update_field( 'acf_text_field', $expected_text_3, $cpt_id ); // post assert validation. diff --git a/tests/wpunit/PostObjectFieldsTest.php b/tests/wpunit/PostObjectFieldsTest.php index 13d8d0e..20e3816 100644 --- a/tests/wpunit/PostObjectFieldsTest.php +++ b/tests/wpunit/PostObjectFieldsTest.php @@ -1213,8 +1213,8 @@ public function testQueryMultipleSelectFieldWithNoValueSet() { public function testQueryFieldOnCustomPostType() { register_post_type( 'acf_test', [ - 'show_ui' => true, - 'show_in_graphql' => 'true', + 'public' => true, + 'show_in_graphql' => 'true', 'graphql_single_name' => 'acfTest', 'graphql_plural_name' => 'acfTests' ] ); From 4d054bdbdab1b44328f0116828cc0bd29a1a6f45 Mon Sep 17 00:00:00 2001 From: Daniel Seripap <683200+seripap@users.noreply.github.com> Date: Fri, 3 Dec 2021 14:11:03 -0500 Subject: [PATCH 05/12] Update to support true or false value instead of null --- src/class-config.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/class-config.php b/src/class-config.php index 13d326e..5b145c7 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -624,7 +624,18 @@ protected function register_graphql_field( string $type_name, string $field_name $field_config['type'] = 'Float'; break; case 'true_false': - $field_config['type'] = 'Boolean'; + $field_config = [ + 'type' => 'Boolean', + 'resolve' => function ($root, $args, $context, $info) use ($acf_field) { + + $value = $this->get_acf_field_value($root, $acf_field, true); + if (empty($value)) { + $value = false; + } + + return $value; + } + ]; break; case 'date_picker': case 'time_picker': From e324aa2c39a8c535ff693725bd7d417df49559e4 Mon Sep 17 00:00:00 2001 From: anavicente Date: Tue, 15 Feb 2022 16:05:11 +0000 Subject: [PATCH 06/12] filter returnes value with acf/format_value --- src/class-config.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/class-config.php b/src/class-config.php index 13d326e..92fb6c4 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -458,6 +458,15 @@ protected function get_acf_field_value( $root, $acf_field, $format = false ) { } + /** + * Filters the returned ACF field value using acf filters + * + * @param mixed $value The resolved ACF field value + * @param int $id The ID of the object + * @param array $acf_field The ACF field config + */ + $value = apply_filters('acf/format_value', $value, $id, $acf_field); + /** * Filters the returned ACF field value * From f2828e49218eb6d63576d399a0f32579b3160044 Mon Sep 17 00:00:00 2001 From: Konrad Fedorczyk Date: Mon, 7 Mar 2022 19:32:30 +0100 Subject: [PATCH 07/12] Fix deprecated error Deprecated: Required parameter $param follows optional parameter $and_params --- src/location-rules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/location-rules.php b/src/location-rules.php index af6f678..c9c3f31 100644 --- a/src/location-rules.php +++ b/src/location-rules.php @@ -206,7 +206,7 @@ public function check_for_conflicts( array $and_params, $param, $allowed_params * * @return bool */ - public function check_params_for_conflicts( array $and_params = [], $param ) { + public function check_params_for_conflicts( array $and_params = [], string $param = '' ) { switch ( $param ) { case 'post_type': $allowed_and_params = [ From 3140ca8b48fae28ac34e060c882a8e02a2882a80 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Thu, 15 Sep 2022 11:27:55 -0600 Subject: [PATCH 08/12] - add new render_field_wrap function to determine whether to use the ACF v6+ version of acf_reder_field_wrap or the older version - add space between Type name and label in field list - update JS that sets the "GraphQL Field Name" based on the Field Group title --- src/class-acfsettings.php | 40 ++++++++++++++++++++++++++++++--------- src/class-config.php | 2 +- src/js/main.js | 11 ++++++++++- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/class-acfsettings.php b/src/class-acfsettings.php index ff8292e..c5f7e03 100644 --- a/src/class-acfsettings.php +++ b/src/class-acfsettings.php @@ -14,11 +14,15 @@ */ class ACF_Settings { + protected $is_acf6_or_higher = false; + /** * Initialize ACF Settings for the plugin */ public function init() { + $this->is_acf6_or_higher = defined( 'ACF_MAJOR_VERSION' ) && version_compare( ACF_MAJOR_VERSION, 6, '>=' ); + /** * Add settings to individual fields to allow each field granular control * over how it's shown in the GraphQL Schema @@ -89,6 +93,26 @@ public function register_meta_boxes() { ], [ 'acf-field-group' ] ); } + /** + * Wrapper over the acf_render_field_wrap setting to support + * ACF >= v6 and ACF =< v5 + * + * @param array $config The field config to render + * + * @return void + */ + public function render_field_wrap( $config ) { + + // The signature for acf_render_field_wrap has changed, so we + // treat it different for versions < 6 and versions >= 6 + if ( $this->is_acf6_or_higher ) { + acf_render_field_wrap( $config, 'div', 'label', true ); + } else { + acf_render_field_wrap( $config ); + } + + } + /** * Display the GraphQL Settings Metabox on the Field Group admin page * @@ -101,7 +125,7 @@ public function display_metabox( $field_group_post_object ) { /** * Render a field in the Field Group settings to allow for a Field Group to be shown in GraphQL. */ - acf_render_field_wrap( + $this->render_field_wrap( [ 'label' => __( 'Show in GraphQL', 'acf' ), 'instructions' => __( 'If the field group is active, and this is set to show, the fields in this group will be available in the WPGraphQL Schema based on the respective Location rules.' ), @@ -116,7 +140,7 @@ public function display_metabox( $field_group_post_object ) { /** * Render a field in the Field Group settings to set the GraphQL field name for the field group. */ - acf_render_field_wrap( + $this->render_field_wrap( [ 'label' => __( 'GraphQL Field Name', 'acf' ), 'instructions' => __( 'The name of the field group in the GraphQL Schema. Names should not include spaces or special characters. Best practice is to use "camelCase".', 'wp-graphql-acf' ), @@ -129,7 +153,7 @@ public function display_metabox( $field_group_post_object ) { ] ); - acf_render_field_wrap( + $this->render_field_wrap( [ 'label' => __( 'Manually Set GraphQL Types for Field Group', 'acf' ), 'instructions' => __( 'By default, ACF Field groups are added to the GraphQL Schema based on the field group\'s location rules. Checking this box will let you manually control the GraphQL Types the field group should be shown on in the GraphQL Schema using the checkboxes below, and the Location Rules will no longer effect the GraphQL Types.', 'wp-graphql-acf' ), @@ -142,7 +166,7 @@ public function display_metabox( $field_group_post_object ) { ); $choices = Config::get_all_graphql_types(); - acf_render_field_wrap( + $this->render_field_wrap( [ 'label' => __( 'GraphQL Types to Show the Field Group On', 'wp-graphql-acf' ), 'instructions' => __( 'Select the Types in the WPGraphQL Schema to show the fields in this field group on', 'wp-graphql-acf' ), @@ -164,7 +188,7 @@ public function display_metabox( $field_group_post_object ) { if (typeof acf !== 'undefined') { acf.newPostbox({ 'id': 'wpgraphql-acf-meta-box', - 'label': 'left' + 'label': is_acf6_or_higher ? 'top' : "'left'"; ?> }); } @@ -217,14 +241,12 @@ public function add_field_settings( array $field ) { public function enqueue_graphql_acf_scripts( string $screen ) { global $post; - if ( $screen == 'post-new.php' || $screen == 'post.php' ) { - if ( 'acf-field-group' === $post->post_type ) { - wp_enqueue_script( 'graphql-acf', plugins_url( 'src/js/main.js', dirname( __FILE__ ) ), array( + if ( ( $screen === 'post-new.php' || $screen === 'post.php' ) && ( isset( $post->post_type ) && 'acf-field-group' === $post->post_type ) ) { + wp_enqueue_script( 'graphql-acf', plugins_url( 'src/js/main.js', __DIR__ ), array( 'jquery', 'acf-input', 'acf-field-group' ) ); - } } } diff --git a/src/class-config.php b/src/class-config.php index 927f2b3..22596e5 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -1340,7 +1340,7 @@ public static function get_all_graphql_types() { $graphql_types[ $interface_name ] = '' . $interface_name . ' Interface (' . $config['plural_label'] . ')'; $label = ' (' . $config['label'] . ')'; foreach ( $possible_types as $type ) { - $type_label = $type['name'] . $label; + $type_label = $type['name'] . ' ' . $label; $type_key = $type['name']; $graphql_types[ $type_key ] = $type_label; diff --git a/src/js/main.js b/src/js/main.js index 6a807b8..4cd46a9 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -201,7 +201,16 @@ $j(document).ready(function () { */ function setGraphqlFieldName() { var graphqlFieldNameField = $j('#acf_field_group-graphql_field_name'); - var fieldGroupTitle = $j('#titlediv #title'); + + // support for v6+ + if ( $j('#title.acf-headerbar-title-field').exists() ) { + var fieldGroupTitle = $j('#title.acf-headerbar-title-field'); + + // versions of ACF < v6 + } else { + var fieldGroupTitle = $j('#titlediv #title'); + } + if ('' === graphqlFieldNameField.val()) { graphqlFieldNameField.val(formatFieldName(fieldGroupTitle.val())); } From 6ce0160138d42e021059c42bb8c1ad4a64b3cf4e Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Thu, 15 Sep 2022 11:39:42 -0600 Subject: [PATCH 09/12] - remove abstraction around `acf_render_field_wrap` as passing additional arguments to the v5 version of acf_render_field_wrap is actually not an issue. The shape of the function didn't change, it just added more arguments. So we can pass the new arguments and v5 just wont do anything with them but v6 will use them. --- src/class-acfsettings.php | 48 ++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/src/class-acfsettings.php b/src/class-acfsettings.php index c5f7e03..c796626 100644 --- a/src/class-acfsettings.php +++ b/src/class-acfsettings.php @@ -93,26 +93,6 @@ public function register_meta_boxes() { ], [ 'acf-field-group' ] ); } - /** - * Wrapper over the acf_render_field_wrap setting to support - * ACF >= v6 and ACF =< v5 - * - * @param array $config The field config to render - * - * @return void - */ - public function render_field_wrap( $config ) { - - // The signature for acf_render_field_wrap has changed, so we - // treat it different for versions < 6 and versions >= 6 - if ( $this->is_acf6_or_higher ) { - acf_render_field_wrap( $config, 'div', 'label', true ); - } else { - acf_render_field_wrap( $config ); - } - - } - /** * Display the GraphQL Settings Metabox on the Field Group admin page * @@ -125,7 +105,7 @@ public function display_metabox( $field_group_post_object ) { /** * Render a field in the Field Group settings to allow for a Field Group to be shown in GraphQL. */ - $this->render_field_wrap( + acf_render_field_wrap( [ 'label' => __( 'Show in GraphQL', 'acf' ), 'instructions' => __( 'If the field group is active, and this is set to show, the fields in this group will be available in the WPGraphQL Schema based on the respective Location rules.' ), @@ -134,13 +114,16 @@ public function display_metabox( $field_group_post_object ) { 'prefix' => 'acf_field_group', 'value' => isset( $field_group['show_in_graphql'] ) ? (bool) $field_group['show_in_graphql'] : false, 'ui' => 1, - ] + ], + 'div', + 'label', + true ); /** * Render a field in the Field Group settings to set the GraphQL field name for the field group. */ - $this->render_field_wrap( + acf_render_field_wrap( [ 'label' => __( 'GraphQL Field Name', 'acf' ), 'instructions' => __( 'The name of the field group in the GraphQL Schema. Names should not include spaces or special characters. Best practice is to use "camelCase".', 'wp-graphql-acf' ), @@ -150,10 +133,13 @@ public function display_metabox( $field_group_post_object ) { 'required' => isset( $field_group['show_in_graphql'] ) ? (bool) $field_group['show_in_graphql'] : false, 'placeholder' => ! empty( $field_group['graphql_field_name'] ) ? $field_group['graphql_field_name'] : null, 'value' => ! empty( $field_group['graphql_field_name'] ) ? $field_group['graphql_field_name'] : null, - ] + ], + 'div', + 'label', + true ); - $this->render_field_wrap( + acf_render_field_wrap( [ 'label' => __( 'Manually Set GraphQL Types for Field Group', 'acf' ), 'instructions' => __( 'By default, ACF Field groups are added to the GraphQL Schema based on the field group\'s location rules. Checking this box will let you manually control the GraphQL Types the field group should be shown on in the GraphQL Schema using the checkboxes below, and the Location Rules will no longer effect the GraphQL Types.', 'wp-graphql-acf' ), @@ -162,11 +148,14 @@ public function display_metabox( $field_group_post_object ) { 'prefix' => 'acf_field_group', 'value' => isset( $field_group['map_graphql_types_from_location_rules'] ) ? (bool) $field_group['map_graphql_types_from_location_rules'] : false, 'ui' => 1, - ] + ], + 'div', + 'label', + true ); $choices = Config::get_all_graphql_types(); - $this->render_field_wrap( + acf_render_field_wrap( [ 'label' => __( 'GraphQL Types to Show the Field Group On', 'wp-graphql-acf' ), 'instructions' => __( 'Select the Types in the WPGraphQL Schema to show the fields in this field group on', 'wp-graphql-acf' ), @@ -176,7 +165,10 @@ public function display_metabox( $field_group_post_object ) { 'value' => ! empty( $field_group['graphql_types'] ) ? $field_group['graphql_types'] : [], 'toggle' => true, 'choices' => $choices, - ] + ], + 'div', + 'label', + true ); ?> From 8444a4df963187ed78dc913dd1af5ec8a6e11b4b Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Thu, 15 Sep 2022 15:17:15 -0600 Subject: [PATCH 10/12] - update version, changelog --- readme.txt | 36 ++++-------------------------------- wp-graphql-acf.php | 4 ++-- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/readme.txt b/readme.txt index 5c8d9b0..d5eb6a4 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://wpgraphql.com/acf Tags: WPGraphQL, GraphQL, API, Advanced Custom Fields, ACF Requires at least: 5.0 Tested up to: 5.1.1 -Stable tag: 0.5.3 +Stable tag: 0.6.0 License: GPL-3 License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -17,38 +17,10 @@ allowing for interacting with ACF field data using GraphQL Queries. == Changelog == -= 0.1.7 = -* Add support for User Edit and User Register form locations += 0.6.0 = -= 0.1.6 = -* Add support for Single Post / Page location rule for ACF Field Groups -* Fix bug with WYSIWYG field nested within repeaters/flex fields not properly getting wpautop applied -* Fix bug where Relationship fields were throwing errors when an item in the relationship had been deleted. Now the items are not included in the response at all and no errors are thrown - -= 0.1.5 = -* Fix bug where field groups would disappear when using acf-local-json - -= 0.1.4 = -* Fixes bug with WYSIWYG fields nested in Flex Fields and Repeater Fields not properly resolving -* Adds support for assigning ACF Field Groups to attachments (MediaItems) - -= 0.1.3 = - -* Adds support for the following locations: Menus, Menu Items, Taxonomies, Comments -* Fixed a bug where the "show_in_graphql" button wasn't showing on Radio Buttons - -= 0.1.2 = -* Fixes bug with Nested Fields not properly showing in the Schema. By defualt, fields are not supposed -to be exposed in the Schema if they are not set to "show_in_graphql", however there was a flaw in -logic causing nested fields of Flex Field layouts to not properly be exposed to the Schema. This -fixes that issue, so nested fields of Flex Field layouts can properly be queried and seen in the -Schema. - -= 0.1.1 = -* Fixes bug with Field groups not properly being exposed to the Schema for custom post types. - -= 0.1.0 = -* Initial public release. +- updates to work with the upcoming ACF v6.0 release +- == Upgrade Notice == diff --git a/wp-graphql-acf.php b/wp-graphql-acf.php index 1443961..cbecbae 100644 --- a/wp-graphql-acf.php +++ b/wp-graphql-acf.php @@ -7,7 +7,7 @@ * Author URI: https://www.wpgraphql.com * Text Domain: wp-graphql-acf * Domain Path: /languages - * Version: 0.5.3 + * Version: 0.6.0 * Requires PHP: 7.0 * GitHub Plugin URI: https://github.com/wp-graphql/wp-graphql-acf * @@ -26,7 +26,7 @@ * Define constants */ const WPGRAPHQL_REQUIRED_MIN_VERSION = '0.4.0'; -const WPGRAPHQL_ACF_VERSION = '0.5.3'; +const WPGRAPHQL_ACF_VERSION = '0.6.0'; /** * Initialize the plugin From 8b9bb245e65b695949ccd33a5f61e475fb7d4ca1 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Thu, 15 Sep 2022 15:17:53 -0600 Subject: [PATCH 11/12] - update changelog to point to releases (for now) --- readme.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/readme.txt b/readme.txt index d5eb6a4..cf71be2 100644 --- a/readme.txt +++ b/readme.txt @@ -17,11 +17,7 @@ allowing for interacting with ACF field data using GraphQL Queries. == Changelog == -= 0.6.0 = - -- updates to work with the upcoming ACF v6.0 release -- - +SEE: https://github.com/wp-graphql/wp-graphql-acf/releases == Upgrade Notice == From 2bd4316cb79586b93f9350cd7cfd27246878096c Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Thu, 15 Sep 2022 15:24:59 -0600 Subject: [PATCH 12/12] Revert "Returning false for true_false values" --- src/class-config.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index 9b65eba..6053398 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -633,18 +633,7 @@ protected function register_graphql_field( string $type_name, string $field_name $field_config['type'] = 'Float'; break; case 'true_false': - $field_config = [ - 'type' => 'Boolean', - 'resolve' => function ($root, $args, $context, $info) use ($acf_field) { - - $value = $this->get_acf_field_value($root, $acf_field, true); - if (empty($value)) { - $value = false; - } - - return $value; - } - ]; + $field_config['type'] = 'Boolean'; break; case 'date_picker': case 'time_picker':