Skip to content

Commit ead3970

Browse files
authored
Merge pull request #107 from kidunot89/release-v0.2.0-cleanup
Release v0.2.0 code cleanup
2 parents 6406e41 + 158e7ff commit ead3970

33 files changed

+223
-308
lines changed

includes/class-actions.php

-185
This file was deleted.

includes/class-filters.php includes/class-core-schema-filters.php

+5-76
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22
/**
3-
* Filters
4-
*
5-
* Filter callbacks for executing filters on the GraphQL Schema
3+
* Adds filters that modify core schema.
64
*
75
* @package \WPGraphQL\Extensions\WooCommerce
86
* @since 0.0.1
@@ -12,15 +10,13 @@
1210

1311
use WPGraphQL\Extensions\WooCommerce\Data\Connection\Post_Connection_Resolver;
1412
use WPGraphQL\Extensions\WooCommerce\Data\Connection\WC_Terms_Connection_Resolver;
15-
use WPGraphQL\Extensions\WooCommerce\Data\Factory;
1613
use WPGraphQL\Extensions\WooCommerce\Data\Loader\WC_Customer_Loader;
1714
use WPGraphQL\Extensions\WooCommerce\Data\Loader\WC_Post_Crud_Loader;
18-
use WPGraphQL\Extensions\WooCommerce\Utils\QL_Session_Handler;
1915

2016
/**
21-
* Class Filters
17+
* Class Core_Schema_Filters
2218
*/
23-
class Filters {
19+
class Core_Schema_Filters {
2420
/**
2521
* Stores instance WC_Customer_Loader
2622
*
@@ -35,24 +31,17 @@ class Filters {
3531
*/
3632
private static $post_crud_loader;
3733

38-
/**
39-
* Stores instance session header name.
40-
*
41-
* @var string
42-
*/
43-
private static $session_header;
44-
4534
/**
4635
* Register filters
4736
*/
48-
public static function load() {
37+
public static function add_filters() {
4938
// Registers WooCommerce taxonomies.
5039
add_filter( 'register_taxonomy_args', array( __CLASS__, 'register_taxonomy_args' ), 10, 2 );
5140

5241
// Add data-loaders to AppContext.
5342
add_filter( 'graphql_data_loaders', array( __CLASS__, 'graphql_data_loaders' ), 10, 2 );
5443

55-
// Filter core connection resolutions.
44+
// Adds connection resolutions for WooGraphQL type to WPGraphQL type connections.
5645
add_filter(
5746
'graphql_post_object_connection_query_args',
5847
array( __CLASS__, 'graphql_post_object_connection_query_args' ),
@@ -65,15 +54,6 @@ public static function load() {
6554
10,
6655
5
6756
);
68-
69-
// Setup QL session handler.
70-
if ( ! defined( 'NO_QL_SESSION_HANDLER' ) ) {
71-
self::$session_header = apply_filters( 'woocommerce_session_header_name', 'woocommerce-session' );
72-
add_filter( 'woocommerce_cookie', array( __CLASS__, 'woocommerce_cookie' ) );
73-
add_filter( 'woocommerce_session_handler', array( __CLASS__, 'init_ql_session_handler' ) );
74-
add_filter( 'graphql_response_headers_to_send', array( __CLASS__, 'add_session_header_to_expose_headers' ) );
75-
add_filter( 'graphql_access_control_allow_headers', array( __CLASS__, 'add_session_header_to_allow_headers' ) );
76-
}
7757
}
7858

7959
/**
@@ -204,55 +184,4 @@ public static function graphql_post_object_connection_query_args( $query_args, $
204184
public static function graphql_term_object_connection_query_args( $query_args, $source, $args, $context, $info ) {
205185
return WC_Terms_Connection_Resolver::get_query_args( $query_args, $source, $args, $context, $info );
206186
}
207-
208-
/**
209-
* Filters WooCommerce cookie key to be used as a HTTP Header on GraphQL HTTP requests
210-
*
211-
* @param string $cookie WooCommerce cookie key.
212-
*
213-
* @return string
214-
*/
215-
public static function woocommerce_cookie( $cookie ) {
216-
return self::$session_header;
217-
}
218-
219-
/**
220-
* Filters WooCommerce session handler class on GraphQL HTTP requests
221-
*
222-
* @param string $session_class Classname of the current session handler class.
223-
*
224-
* @return string
225-
*/
226-
public static function init_ql_session_handler( $session_class ) {
227-
return QL_Session_Handler::class;
228-
}
229-
230-
/**
231-
* Append session header to the exposed headers in GraphQL responses
232-
*
233-
* @param array $headers GraphQL responser headers.
234-
*
235-
* @return array
236-
*/
237-
public static function add_session_header_to_expose_headers( $headers ) {
238-
if ( empty( $headers['Access-Control-Expose-Headers'] ) ) {
239-
$headers['Access-Control-Expose-Headers'] = apply_filters( 'woocommerce_cookie', self::$session_header );
240-
} else {
241-
$headers['Access-Control-Expose-Headers'] .= ', ' . apply_filters( 'woocommerce_cookie', self::$session_header );
242-
}
243-
244-
return $headers;
245-
}
246-
247-
/**
248-
* Append the session header to the allowed headers in GraphQL responses
249-
*
250-
* @param array $allowed_headers The existing allowed headers.
251-
*
252-
* @return array
253-
*/
254-
public static function add_session_header_to_allow_headers( array $allowed_headers ) {
255-
$allowed_headers[] = self::$session_header;
256-
return $allowed_headers;
257-
}
258187
}

0 commit comments

Comments
 (0)