mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
escape hatch finalized
This commit is contained in:
@@ -26,14 +26,13 @@ class WooCommerce_Filters {
|
||||
*/
|
||||
public static function add_filters() {
|
||||
// Setup QL session handler.
|
||||
$graphql_endpoint = '/' . apply_filters( 'graphql_endpoint', 'graphql' );
|
||||
if ( isset( $_SERVER['REQUEST_URI'] ) && $graphql_endpoint !== $_SERVER['REQUEST_URI'] ) {
|
||||
return;
|
||||
}
|
||||
if ( ! defined( 'NO_QL_SESSION_HANDLER' ) ) {
|
||||
// Check if request is a GraphQL POST request.
|
||||
self::$session_header = apply_filters( 'woocommerce_graphql_session_header_name', 'woocommerce-session' );
|
||||
add_filter( 'woocommerce_cookie', array( __CLASS__, 'woocommerce_cookie' ) );
|
||||
add_filter( 'woocommerce_session_handler', array( __CLASS__, 'init_ql_session_handler' ) );
|
||||
if ( self::is_graphql_post_request() ) {
|
||||
add_filter( 'woocommerce_cookie', array( __CLASS__, 'woocommerce_cookie' ) );
|
||||
add_filter( 'woocommerce_session_handler', array( __CLASS__, 'init_ql_session_handler' ) );
|
||||
}
|
||||
add_filter( 'graphql_response_headers_to_send', array( __CLASS__, 'add_session_header_to_expose_headers' ) );
|
||||
add_filter( 'graphql_access_control_allow_headers', array( __CLASS__, 'add_session_header_to_allow_headers' ) );
|
||||
}
|
||||
@@ -89,4 +88,24 @@ class WooCommerce_Filters {
|
||||
$allowed_headers[] = self::$session_header;
|
||||
return $allowed_headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm that the current uri is the GraphQL endpoint.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function is_graphql_post_request() {
|
||||
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
|
||||
$haystack = wp_unslash( $_SERVER['REQUEST_URI'] );
|
||||
$needle = apply_filters( 'graphql_endpoint', 'graphql' );
|
||||
$length = strlen( $needle );
|
||||
if ( 0 === $length ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ( substr( $haystack, -$length ) === $needle );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user