@@ -267,12 +267,10 @@ public function determine_rules( string $field_group_name, string $param, string
267267 $ this ->determine_post_template_rules ( $ field_group_name , $ param , $ operator , $ value );
268268 break ;
269269 case 'post_status ' :
270- $ this ->determine_post_status_rules ( $ field_group_name , $ param , $ operator , $ value );
271270 break ;
272271 case 'post_format ' :
273272 case 'post_category ' :
274273 case 'post_taxonomy ' :
275- $ this ->determine_post_taxonomy_rules ( $ field_group_name , $ param , $ operator , $ value );
276274 break ;
277275 case 'post ' :
278276 $ this ->determine_post_rules ( $ field_group_name , $ param , $ operator , $ value );
@@ -489,37 +487,6 @@ public function determine_post_template_rules( string $field_group_name, string
489487 }
490488 }
491489
492- /**
493- * Determines how the ACF Rules should apply to the WPGraphQL Schema
494- *
495- * @param string $field_group_name The name of the ACF Field Group the rule applies to
496- * @param string $param The parameter of the rule
497- * @param string $operator The operator of the rule
498- * @param string $value The value of the rule
499- */
500- public function determine_post_status_rules ( string $ field_group_name , string $ param , string $ operator , string $ value ): void {
501- // @todo: Should post status affect the GraphQL Schema at all?
502- // If a field group is set to show on "post_status == publish" as the only rule, what post type does that apply to? All? 🤔
503- // If a field group is set to show on "post_status != draft" does that mean the field group should be available on all post types in the Schema by default?
504- // This seems like a very difficult rule to translate to the Schema.
505- // Like, lets say I add a field group called: "Editor Notes" that I want to show for any status that is not "publish". In theory, if that's my only rule, that seems like it should apply to all post types across the board, and show in the Admin in any state of the post, other than publish. 🤔
506-
507- // ACF Admin behavior seems to add it to the Admin on all post types, so WPGraphQL
508- // should respect this rule and also add it to all post types. The resolver should
509- // then determine whether to resolve the data or not, based on this rule.
510-
511- // If Post Status is used to qualify a field group location,
512- // It will be added to the Schema for any Post Type that is set to show in GraphQL
513- $ allowed_post_types = get_post_types ( [ 'show_in_graphql ' => true ] );
514- foreach ( $ allowed_post_types as $ post_type ) {
515- $ post_type_object = get_post_type_object ( $ post_type );
516- $ graphql_name = $ post_type_object ->graphql_single_name ?? null ;
517- if ( ! empty ( $ graphql_name ) ) {
518- $ this ->set_graphql_type ( $ field_group_name , $ graphql_name );
519- }
520- }
521- }
522-
523490 /**
524491 * Determines how the ACF Rules should apply to the WPGraphQL Schema
525492 *
@@ -551,21 +518,6 @@ public function determine_post_format_rules( string $field_group_name, string $p
551518 }
552519 }
553520
554- /**
555- * Determines how the ACF Rules should apply to the WPGraphQL Schema
556- *
557- * @param string $field_group_name The name of the ACF Field Group the rule applies to
558- * @param string $param The parameter of the rule
559- * @param string $operator The operator of the rule
560- * @param string $value The value of the rule
561- */
562- public function determine_post_taxonomy_rules ( string $ field_group_name , string $ param , string $ operator , string $ value ): void {
563-
564- // If Post Taxonomy is used to qualify a field group location,
565- // It will be added to the Schema for the Post post type
566- $ this ->set_graphql_type ( $ field_group_name , 'Post ' );
567- }
568-
569521 /**
570522 * Determines how the ACF Rules should apply to the WPGraphQL Schema
571523 *
@@ -580,35 +532,20 @@ public function determine_post_rules( string $field_group_name, string $param, s
580532 // It will be added to the Schema for the GraphQL Type for the post_type of the Post
581533 // it is assigned to
582534
583- if ( '== ' === $ operator ) {
584- if ( absint ( $ value ) ) {
585- $ post = get_post ( absint ( $ value ) );
586- if ( $ post instanceof \WP_Post ) {
587- $ post_type_object = get_post_type_object ( $ post ->post_type );
588- if ( $ post_type_object && true === $ post_type_object ->show_in_graphql && isset ( $ post_type_object ->graphql_single_name ) ) {
589- $ this ->set_graphql_type ( $ field_group_name , $ post_type_object ->graphql_single_name );
590- }
535+ if ( ( '== ' === $ operator ) && absint ( $ value ) ) {
536+ $ post = get_post ( absint ( $ value ) );
537+ if ( $ post instanceof \WP_Post ) {
538+ $ post_type_object = get_post_type_object ( $ post ->post_type );
539+ if ( $ post_type_object && true === $ post_type_object ->show_in_graphql && isset ( $ post_type_object ->graphql_single_name ) ) {
540+ $ this ->set_graphql_type ( $ field_group_name , $ post_type_object ->graphql_single_name );
591541 }
592542 }
593543 }
594544
595545 // If a single post is used as not equal,
596- // the field group should be added to ALL post types in the Schema
546+ // the field group should not be added to any type
597547 if ( '!= ' === $ operator ) {
598- $ allowed_post_types = get_post_types ( [ 'show_in_graphql ' => true ] );
599-
600- if ( empty ( $ allowed_post_types ) ) {
601- return ;
602- }
603-
604- // loop over and set all post types
605- foreach ( $ allowed_post_types as $ allowed_post_type ) {
606- $ post_type_object = get_post_type_object ( $ allowed_post_type );
607- $ graphql_name = $ post_type_object ->graphql_single_name ?? null ;
608- if ( ! empty ( $ graphql_name ) ) {
609- $ this ->set_graphql_type ( $ field_group_name , $ graphql_name );
610- }
611- }
548+ return ;
612549 }
613550 }
614551
@@ -627,30 +564,6 @@ public function determine_page_type_rules( string $field_group_name, string $par
627564 if ( in_array ( $ value , [ 'front_page ' , 'posts_page ' ], true ) ) {
628565 $ this ->set_graphql_type ( $ field_group_name , 'Page ' );
629566 }
630-
631- // If top_level, parent, or child is set as equal_to or not_equal_to
632- // then the field group should be shown on all hierarchical post types
633- if ( in_array ( $ value , [ 'top_level ' , 'parent ' , 'child ' ], true ) ) {
634- $ hierarchical_post_types = get_post_types (
635- [
636- 'show_in_graphql ' => true ,
637- 'hierarchical ' => true ,
638- ]
639- );
640-
641- if ( empty ( $ hierarchical_post_types ) ) {
642- return ;
643- }
644-
645- // loop over and set all post types
646- foreach ( $ hierarchical_post_types as $ allowed_post_type ) {
647- $ post_type_object = get_post_type_object ( $ allowed_post_type );
648- $ graphql_name = $ post_type_object ->graphql_single_name ?? null ;
649- if ( ! empty ( $ graphql_name ) ) {
650- $ this ->set_graphql_type ( $ field_group_name , $ graphql_name );
651- }
652- }
653- }
654567 }
655568
656569 /**
0 commit comments