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

Commit ee09e2f

Browse files
authored
Merge pull request #335 from wp-graphql/release/v0.6.0
Release/v0.6.0
2 parents 0ac0529 + a01a329 commit ee09e2f

File tree

9 files changed

+58
-55
lines changed

9 files changed

+58
-55
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Setting the value of this field to "Yes" will show the field group in the WPGrap
9494

9595
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.
9696

97-
```
97+
```php
9898
function my_acf_add_local_field_groups() {
9999

100100
acf_add_local_field_group(array(

readme.txt

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://wpgraphql.com/acf
44
Tags: WPGraphQL, GraphQL, API, Advanced Custom Fields, ACF
55
Requires at least: 5.0
66
Tested up to: 5.1.1
7-
Stable tag: 0.5.3
7+
Stable tag: 0.6.0
88
License: GPL-3
99
License URI: https://www.gnu.org/licenses/gpl-3.0.html
1010

@@ -17,39 +17,7 @@ allowing for interacting with ACF field data using GraphQL Queries.
1717

1818
== Changelog ==
1919

20-
= 0.1.7 =
21-
* Add support for User Edit and User Register form locations
22-
23-
= 0.1.6 =
24-
* Add support for Single Post / Page location rule for ACF Field Groups
25-
* Fix bug with WYSIWYG field nested within repeaters/flex fields not properly getting wpautop applied
26-
* 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
27-
28-
= 0.1.5 =
29-
* Fix bug where field groups would disappear when using acf-local-json
30-
31-
= 0.1.4 =
32-
* Fixes bug with WYSIWYG fields nested in Flex Fields and Repeater Fields not properly resolving
33-
* Adds support for assigning ACF Field Groups to attachments (MediaItems)
34-
35-
= 0.1.3 =
36-
37-
* Adds support for the following locations: Menus, Menu Items, Taxonomies, Comments
38-
* Fixed a bug where the "show_in_graphql" button wasn't showing on Radio Buttons
39-
40-
= 0.1.2 =
41-
* Fixes bug with Nested Fields not properly showing in the Schema. By defualt, fields are not supposed
42-
to be exposed in the Schema if they are not set to "show_in_graphql", however there was a flaw in
43-
logic causing nested fields of Flex Field layouts to not properly be exposed to the Schema. This
44-
fixes that issue, so nested fields of Flex Field layouts can properly be queried and seen in the
45-
Schema.
46-
47-
= 0.1.1 =
48-
* Fixes bug with Field groups not properly being exposed to the Schema for custom post types.
49-
50-
= 0.1.0 =
51-
* Initial public release.
52-
20+
SEE: https://github.com/wp-graphql/wp-graphql-acf/releases
5321

5422
== Upgrade Notice ==
5523

src/class-acfsettings.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
*/
1515
class ACF_Settings {
1616

17+
protected $is_acf6_or_higher = false;
18+
1719
/**
1820
* Initialize ACF Settings for the plugin
1921
*/
2022
public function init() {
2123

24+
$this->is_acf6_or_higher = defined( 'ACF_MAJOR_VERSION' ) && version_compare( ACF_MAJOR_VERSION, 6, '>=' );
25+
2226
/**
2327
* Add settings to individual fields to allow each field granular control
2428
* over how it's shown in the GraphQL Schema
@@ -110,7 +114,10 @@ public function display_metabox( $field_group_post_object ) {
110114
'prefix' => 'acf_field_group',
111115
'value' => isset( $field_group['show_in_graphql'] ) ? (bool) $field_group['show_in_graphql'] : false,
112116
'ui' => 1,
113-
]
117+
],
118+
'div',
119+
'label',
120+
true
114121
);
115122

116123
/**
@@ -126,7 +133,10 @@ public function display_metabox( $field_group_post_object ) {
126133
'required' => isset( $field_group['show_in_graphql'] ) ? (bool) $field_group['show_in_graphql'] : false,
127134
'placeholder' => ! empty( $field_group['graphql_field_name'] ) ? $field_group['graphql_field_name'] : null,
128135
'value' => ! empty( $field_group['graphql_field_name'] ) ? $field_group['graphql_field_name'] : null,
129-
]
136+
],
137+
'div',
138+
'label',
139+
true
130140
);
131141

132142
acf_render_field_wrap(
@@ -138,7 +148,10 @@ public function display_metabox( $field_group_post_object ) {
138148
'prefix' => 'acf_field_group',
139149
'value' => isset( $field_group['map_graphql_types_from_location_rules'] ) ? (bool) $field_group['map_graphql_types_from_location_rules'] : false,
140150
'ui' => 1,
141-
]
151+
],
152+
'div',
153+
'label',
154+
true
142155
);
143156

144157
$choices = Config::get_all_graphql_types();
@@ -152,7 +165,10 @@ public function display_metabox( $field_group_post_object ) {
152165
'value' => ! empty( $field_group['graphql_types'] ) ? $field_group['graphql_types'] : [],
153166
'toggle' => true,
154167
'choices' => $choices,
155-
]
168+
],
169+
'div',
170+
'label',
171+
true
156172
);
157173

158174
?>
@@ -164,7 +180,7 @@ public function display_metabox( $field_group_post_object ) {
164180
if (typeof acf !== 'undefined') {
165181
acf.newPostbox({
166182
'id': 'wpgraphql-acf-meta-box',
167-
'label': 'left'
183+
'label': <?php echo $this->is_acf6_or_higher ? 'top' : "'left'"; ?>
168184
});
169185
}
170186
</script>
@@ -217,14 +233,12 @@ public function add_field_settings( array $field ) {
217233
public function enqueue_graphql_acf_scripts( string $screen ) {
218234
global $post;
219235

220-
if ( $screen == 'post-new.php' || $screen == 'post.php' ) {
221-
if ( 'acf-field-group' === $post->post_type ) {
222-
wp_enqueue_script( 'graphql-acf', plugins_url( 'src/js/main.js', dirname( __FILE__ ) ), array(
236+
if ( ( $screen === 'post-new.php' || $screen === 'post.php' ) && ( isset( $post->post_type ) && 'acf-field-group' === $post->post_type ) ) {
237+
wp_enqueue_script( 'graphql-acf', plugins_url( 'src/js/main.js', __DIR__ ), array(
223238
'jquery',
224239
'acf-input',
225240
'acf-field-group'
226241
) );
227-
}
228242
}
229243
}
230244

src/class-config.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,15 @@ protected function get_acf_field_value( $root, $acf_field, $format = false ) {
458458

459459
}
460460

461+
/**
462+
* Filters the returned ACF field value using acf filters
463+
*
464+
* @param mixed $value The resolved ACF field value
465+
* @param int $id The ID of the object
466+
* @param array $acf_field The ACF field config
467+
*/
468+
$value = apply_filters('acf/format_value', $value, $id, $acf_field);
469+
461470
/**
462471
* Filters the returned ACF field value
463472
*
@@ -636,7 +645,7 @@ protected function register_graphql_field( string $type_name, string $field_name
636645
$value = $this->get_acf_field_value( $root, $acf_field, true );
637646

638647
if ( ! empty( $value ) && ! empty( $acf_field['return_format'] ) ) {
639-
$value = date( $acf_field['return_format'], strtotime( $value ) );
648+
$value = date_i18n( $acf_field['return_format'], strtotime( $value ) );
640649
}
641650
return ! empty( $value ) ? $value : null;
642651
},
@@ -689,12 +698,14 @@ protected function register_graphql_field( string $type_name, string $field_name
689698
$post_object = get_post( $post_id );
690699
if ( $post_object instanceof \WP_Post ) {
691700
$post_model = new Post( $post_object );
692-
$relationship[] = $post_model;
701+
if ( 'private' != $post_model->get_visibility() ) {
702+
$relationship[] = $post_model;
703+
}
693704
}
694705
}
695706
}
696707

697-
return isset( $value ) ? $relationship : null;
708+
return empty( $relationship ) ? null : $relationship;
698709

699710
},
700711
];
@@ -1340,7 +1351,7 @@ public static function get_all_graphql_types() {
13401351
$graphql_types[ $interface_name ] = '<span data-interface="'. $interface_name .'">' . $interface_name . ' Interface (' . $config['plural_label'] . ')</span>';
13411352
$label = '<span data-implements="'. $interface_name .'"> (' . $config['label'] . ')</span>';
13421353
foreach ( $possible_types as $type ) {
1343-
$type_label = $type['name'] . $label;
1354+
$type_label = $type['name'] . '&nbsp;' . $label;
13441355
$type_key = $type['name'];
13451356

13461357
$graphql_types[ $type_key ] = $type_label;

src/js/main.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,16 @@ $j(document).ready(function () {
201201
*/
202202
function setGraphqlFieldName() {
203203
var graphqlFieldNameField = $j('#acf_field_group-graphql_field_name');
204-
var fieldGroupTitle = $j('#titlediv #title');
204+
205+
// support for v6+
206+
if ( $j('#title.acf-headerbar-title-field').exists() ) {
207+
var fieldGroupTitle = $j('#title.acf-headerbar-title-field');
208+
209+
// versions of ACF < v6
210+
} else {
211+
var fieldGroupTitle = $j('#titlediv #title');
212+
}
213+
205214
if ('' === graphqlFieldNameField.val()) {
206215
graphqlFieldNameField.val(formatFieldName(fieldGroupTitle.val()));
207216
}

src/location-rules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function check_for_conflicts( array $and_params, $param, $allowed_params
206206
*
207207
* @return bool
208208
*/
209-
public function check_params_for_conflicts( array $and_params = [], $param ) {
209+
public function check_params_for_conflicts( array $and_params = [], string $param = '' ) {
210210
switch ( $param ) {
211211
case 'post_type':
212212
$allowed_and_params = [

tests/wpunit/ExplicitOptionsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function testExplicitOptions() {
8989
'show_in_graphql' => true,
9090
'graphql_single_name' => 'acfCpt',
9191
'graphql_plural_name' => 'acfCpts',
92+
'public' => true,
9293
]
9394
);
9495

@@ -148,7 +149,7 @@ public function testExplicitOptions() {
148149
]
149150
);
150151

151-
$expected_text_3 = 'test value2';
152+
$expected_text_3 = 'test value3';
152153
update_field( 'acf_text_field', $expected_text_3, $cpt_id );
153154

154155
// post assert validation.

tests/wpunit/PostObjectFieldsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,8 @@ public function testQueryMultipleSelectFieldWithNoValueSet() {
12131213
public function testQueryFieldOnCustomPostType() {
12141214

12151215
register_post_type( 'acf_test', [
1216-
'show_ui' => true,
1217-
'show_in_graphql' => 'true',
1216+
'public' => true,
1217+
'show_in_graphql' => 'true',
12181218
'graphql_single_name' => 'acfTest',
12191219
'graphql_plural_name' => 'acfTests'
12201220
] );

wp-graphql-acf.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Author URI: https://www.wpgraphql.com
88
* Text Domain: wp-graphql-acf
99
* Domain Path: /languages
10-
* Version: 0.5.3
10+
* Version: 0.6.0
1111
* Requires PHP: 7.0
1212
* GitHub Plugin URI: https://github.com/wp-graphql/wp-graphql-acf
1313
*
@@ -26,7 +26,7 @@
2626
* Define constants
2727
*/
2828
const WPGRAPHQL_REQUIRED_MIN_VERSION = '0.4.0';
29-
const WPGRAPHQL_ACF_VERSION = '0.5.3';
29+
const WPGRAPHQL_ACF_VERSION = '0.6.0';
3030

3131
/**
3232
* Initialize the plugin

0 commit comments

Comments
 (0)