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(
diff --git a/readme.txt b/readme.txt
index 5c8d9b0..cf71be2 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,39 +17,7 @@ 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.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.
-
+SEE: https://github.com/wp-graphql/wp-graphql-acf/releases
== Upgrade Notice ==
diff --git a/src/class-acfsettings.php b/src/class-acfsettings.php
index ff8292e..c796626 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
@@ -110,7 +114,10 @@ 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
);
/**
@@ -126,7 +133,10 @@ 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
);
acf_render_field_wrap(
@@ -138,7 +148,10 @@ 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();
@@ -152,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
);
?>
@@ -164,7 +180,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 +233,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..6053398 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
*
@@ -636,7 +645,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;
},
@@ -689,12 +698,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;
},
];
@@ -1340,7 +1351,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()));
}
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 = [
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'
] );
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