From ed145668d214a3797db1e4285e905e7c13245943 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Tue, 24 Sep 2019 11:00:58 -0400 Subject: [PATCH 1/2] "product_connection_catalog_visibility" hook implemented. --- .../class-product-connection-resolver.php | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/includes/data/connection/class-product-connection-resolver.php b/includes/data/connection/class-product-connection-resolver.php index 5450f68c..ce91fda5 100644 --- a/includes/data/connection/class-product-connection-resolver.php +++ b/includes/data/connection/class-product-connection-resolver.php @@ -33,6 +33,18 @@ class Product_Connection_Resolver extends AbstractConnectionResolver { */ protected $post_type; + /** + * Holds default catalog visibility tax query. + * + * @var array + */ + public static $default_visibility = array( + 'taxonomy' => 'product_visibility', + 'field' => 'slug', + 'terms' => array( 'exclude-from-catalog', 'exclude-from-search' ), + 'operator' => 'NOT IN', + ); + /** * Refund_Connection_Resolver constructor. * @@ -245,12 +257,30 @@ class Product_Connection_Resolver extends AbstractConnectionResolver { if ( empty( $query_args['tax_query'] ) ) { $query_args['tax_query'] = array(); // WPCS: slow query ok. } - $query_args['tax_query'][] = array( - 'taxonomy' => 'product_visibility', - 'field' => 'slug', - 'terms' => array( 'exclude-from-catalog', 'exclude-from-search' ), - 'operator' => 'NOT IN', + + /** + * Filters the default catalog visibility tax query for non-adminstrator requests. + * + * @param array $default_visibility Default catalog visibility tax query. + * @param array $query_args The args that will be passed to the WP_Query + * @param mixed $source The source that's passed down the GraphQL queries + * @param array $args The inputArgs on the field + * @param AppContext $context The AppContext passed down the GraphQL tree + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree + */ + $catalog_visibility = apply_filters( + 'product_connection_catalog_visibility', + self::$default_visibility, + $query_args, + $this->source, + $this->args, + $this->context, + $this->info ); + + if ( ! empty( $catalog_visibility ) ) { + $query_args['tax_query'][] = $catalog_visibility; + } } /** @@ -270,7 +300,7 @@ class Product_Connection_Resolver extends AbstractConnectionResolver { } /** - * Filter the $query args to allow folks to customize queries programmatically + * Filter the $query_args to allow folks to customize queries programmatically * * @param array $query_args The args that will be passed to the WP_Query * @param mixed $source The source that's passed down the GraphQL queries From b679b00689d6ccde3b66342a8630a2e535e0e0bd Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Tue, 24 Sep 2019 11:23:16 -0400 Subject: [PATCH 2/2] "hook renamed" --- .../class-product-connection-resolver.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/includes/data/connection/class-product-connection-resolver.php b/includes/data/connection/class-product-connection-resolver.php index ce91fda5..fa5e9b7e 100644 --- a/includes/data/connection/class-product-connection-resolver.php +++ b/includes/data/connection/class-product-connection-resolver.php @@ -262,14 +262,14 @@ class Product_Connection_Resolver extends AbstractConnectionResolver { * Filters the default catalog visibility tax query for non-adminstrator requests. * * @param array $default_visibility Default catalog visibility tax query. - * @param array $query_args The args that will be passed to the WP_Query - * @param mixed $source The source that's passed down the GraphQL queries - * @param array $args The inputArgs on the field - * @param AppContext $context The AppContext passed down the GraphQL tree - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree + * @param array $query_args The args that will be passed to the WP_Query. + * @param mixed $source The source that's passed down the GraphQL queries. + * @param array $args The inputArgs on the field. + * @param AppContext $context The AppContext passed down the GraphQL tree. + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree. */ $catalog_visibility = apply_filters( - 'product_connection_catalog_visibility', + 'graphql_product_connection_catalog_visibility', self::$default_visibility, $query_args, $this->source, @@ -300,13 +300,13 @@ class Product_Connection_Resolver extends AbstractConnectionResolver { } /** - * Filter the $query_args to allow folks to customize queries programmatically + * Filter the $query_args to allow folks to customize queries programmatically. * - * @param array $query_args The args that will be passed to the WP_Query - * @param mixed $source The source that's passed down the GraphQL queries - * @param array $args The inputArgs on the field - * @param AppContext $context The AppContext passed down the GraphQL tree - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree + * @param array $query_args The args that will be passed to the WP_Query. + * @param mixed $source The source that's passed down the GraphQL queries. + * @param array $args The inputArgs on the field. + * @param AppContext $context The AppContext passed down the GraphQL tree. + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree. */ $query_args = apply_filters( 'graphql_product_connection_query_args', $query_args, $this->source, $this->args, $this->context, $this->info );