• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql-woocommerce / 23228201207

18 Mar 2026 03:49AM UTC coverage: 83.184% (-0.4%) from 83.59%
23228201207

push

github

web-flow
fix: inverted logic in pop_transaction_id() causes cart session corruption (#971)

* fix: resolve REQUEST_URI fatal error and JWT key length issues in CI

QLSessionHandlerTest::tearDown() was calling unset($_SERVER) which
destroyed the entire superglobal. WordPress cron.php then fataled on
shutdown when accessing $_SERVER['REQUEST_URI']. Changed to only unset
the specific HTTP_WOOCOMMERCE_SESSION key.

Also updated JWT secret keys to meet firebase/php-jwt v7's minimum
32-byte requirement for HS256 in both test config and Docker entrypoint.

* fix: the rest of the files added

* devops: php7.4 removed from matrix

* chore: Linter compliances met

* devops: More broken test updated

* devops: Tests updated for CI

* fix: QLSessionHandlerCest fixed

* fix: QLSessionHandlerCest fixed

* devops: CI fixed

3 of 59 new or added lines in 2 files covered. (5.08%)

526 existing lines in 17 files now uncovered.

12594 of 15140 relevant lines covered (83.18%)

75.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.57
/includes/admin/class-general.php
1
<?php
2
/**
3
 * Defines WooGraphQL's general settings.
4
 *
5
 * @package WPGraphQL\WooCommerce\Admin
6
 */
7

8
namespace WPGraphQL\WooCommerce\Admin;
9

10
/**
11
 * General class
12
 */
13
class General extends Section {
14
        /**
15
         * Returns the other nonce values besides the one provided.
16
         *
17
         * @param string $excluded  Slug of nonce value to be excluded.
18
         *
19
         * @return array
20
         */
21
        public static function get_other_nonce_values( $excluded ) {
22
                $nonce_values = apply_filters(
×
23
                        'woographql_authorizing_url_nonce_values',
×
24
                        [
×
25
                                'cart_url'               => woographql_setting( 'cart_url_nonce_param', '_wc_cart' ),
×
26
                                'checkout_url'           => woographql_setting( 'checkout_url_nonce_param', '_wc_checkout' ),
×
27
                                'account_url'            => woographql_setting( 'account_url_nonce_param', '_wc_account' ),
×
28
                                'add_payment_method_url' => woographql_setting( 'add_payment_method_url_nonce_param', '_wc_payment' ),
×
29
                        ]
×
30
                );
×
31

32
                return array_values( array_diff_key( $nonce_values, [ $excluded => '' ] ) );
×
33
        }
34

35
        /**
36
         * Returns the enabled authorizing URL fields.
37
         *
38
         * @return array
39
         */
40
        public static function enabled_authorizing_url_fields_value() {
41
                return apply_filters(
157✔
42
                        'woographql_enabled_authorizing_url_fields',
157✔
43
                        [
157✔
44
                                'cart_url'               => 'cart_url',
157✔
45
                                'checkout_url'           => 'checkout_url',
157✔
46
                                'account_url'            => 'account_url',
157✔
47
                                'add_payment_method_url' => 'add_payment_method_url',
157✔
48
                        ]
157✔
49
                );
157✔
50
        }
51

52
        /**
53
         * Returns General settings fields.
54
         *
55
         * @return array
56
         */
57
        public static function get_fields() {
58
                $custom_endpoint                = apply_filters( 'woographql_authorizing_url_endpoint', null );
×
59
                $enabled_authorizing_url_fields = woographql_setting( 'enable_authorizing_url_fields', [] );
×
60
                $enabled_authorizing_url_fields = ! empty( $enabled_authorizing_url_fields ) ? array_keys( $enabled_authorizing_url_fields ) : [];
×
61
                $all_urls_checked               = self::enabled_authorizing_url_fields_value();
×
62

63
                $cart_url_hardcoded               = defined( 'CART_URL_NONCE_PARAM' ) && ! empty( constant( 'CART_URL_NONCE_PARAM' ) );
×
64
                $checkout_url_hardcoded           = defined( 'CHECKOUT_URL_NONCE_PARAM' ) && ! empty( constant( 'CHECKOUT_URL_NONCE_PARAM' ) );
×
65
                $account_url_hardcoded            = defined( 'ACCOUNT_URL_NONCE_PARAM' ) && ! empty( constant( 'ACCOUNT_URL_NONCE_PARAM' ) );
×
66
                $add_payment_method_url_hardcoded = defined( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) && ! empty( constant( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) );
×
67

68
                $enable_auth_urls_hardcoded = defined( 'WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS' ) && ! empty( constant( 'WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS' ) );
×
69

70
                return [
×
71
                        [
×
72
                                'name'     => 'disable_ql_session_handler',
×
73
                                'label'    => __( 'Disable QL Session Handler', 'wp-graphql-woocommerce' ),
×
74
                                'desc'     => __( 'The QL Session Handler takes over management of WooCommerce Session Management on WPGraphQL request replacing the usage of HTTP Cookies with JSON Web Tokens.', 'wp-graphql-woocommerce' )
×
75
                                        . ( defined( 'NO_QL_SESSION_HANDLER' ) ? __( ' This setting is disabled. The "NO_QL_SESSION_HANDLER" flag has been triggered with code', 'wp-graphql-woocommerce' ) : '' ),
×
76
                                'type'     => 'checkbox',
×
77
                                'value'    => defined( 'NO_QL_SESSION_HANDLER' ) ? 'on' : woographql_setting( 'disable_ql_session_handler', 'off' ),
×
78
                                'disabled' => defined( 'NO_QL_SESSION_HANDLER' ),
×
79
                        ],
×
80
                        [
×
81
                                'name'     => 'enable_ql_session_handler_on_ajax',
×
82
                                'label'    => __( 'Enable QL Session Handler on WC AJAX requests.', 'wp-graphql-woocommerce' ),
×
83
                                'desc'     => __( 'Enabling this will enable JSON Web Tokens usage on WC AJAX requests.', 'wp-graphql-woocommerce' )
×
84
                                        . ( defined( 'NO_QL_SESSION_HANDLER' ) ? __( ' This setting is disabled. The "NO_QL_SESSION_HANDLER" flag has been triggered with code', 'wp-graphql-woocommerce' ) : '' ),
×
85
                                'type'     => 'checkbox',
×
86
                                'value'    => defined( 'NO_QL_SESSION_HANDLER' ) ? 'off' : woographql_setting( 'enable_ql_session_handler_on_ajax', 'off' ),
×
87
                                'disabled' => defined( 'NO_QL_SESSION_HANDLER' ),
×
88
                        ],
×
89
                        [
×
90
                                'name'     => 'enable_ql_session_handler_on_rest',
×
91
                                'label'    => __( 'Enable QL Session Handler on WP REST requests.', 'wp-graphql-woocommerce' ),
×
92
                                'desc'     => __( 'Enabling this will enable JSON Web Tokens usage on WP REST requests.', 'wp-graphql-woocommerce' )
×
93
                                        . ( defined( 'NO_QL_SESSION_HANDLER' ) ? __( ' This setting is disabled. The "NO_QL_SESSION_HANDLER" flag has been triggered with code', 'wp-graphql-woocommerce' ) : '' ),
×
94
                                'type'     => 'checkbox',
×
95
                                'value'    => defined( 'NO_QL_SESSION_HANDLER' ) ? 'off' : woographql_setting( 'enable_ql_session_handler_on_rest', 'off' ),
×
96
                                'disabled' => defined( 'NO_QL_SESSION_HANDLER' ),
×
97
                        ],
×
98
                        [
×
99
                                'name'     => 'set_session_token_type',
×
100
                                'label'    => __( 'Session Token Type', 'wp-graphql-woocommerce' ),
×
101
                                'desc'     => __( 'Choose which session token type(s) to generate. "Legacy" uses GraphQL session tokens only. "Store API" uses WooCommerce Blocks Cart-Token only (requires WooCommerce 5.5.0+). "Both" generates both token types for maximum compatibility with headless implementations using WooCommerce Blocks.', 'wp-graphql-woocommerce' )
×
102
                                        . ( defined( 'NO_QL_SESSION_HANDLER' ) ? __( ' This setting is disabled. The "NO_QL_SESSION_HANDLER" flag has been triggered with code', 'wp-graphql-woocommerce' ) : '' ),
×
103
                                'type'     => 'select',
×
104
                                'options'  => [
×
105
                                        'legacy'    => __( 'Legacy (GraphQL Session Token only)', 'wp-graphql-woocommerce' ),
×
106
                                        'store-api' => __( 'Store API (Cart-Token only)', 'wp-graphql-woocommerce' ),
×
107
                                        'both'      => __( 'Both (GraphQL + Store API)', 'wp-graphql-woocommerce' ),
×
108
                                ],
×
109
                                'default'  => 'legacy',
×
110
                                'disabled' => defined( 'NO_QL_SESSION_HANDLER' ),
×
111
                        ],
×
112
                        [
×
113
                                'name'    => 'enable_unsupported_product_type',
×
114
                                'label'   => __( 'Enable Unsupported types', 'wp-graphql-woocommerce' ),
×
115
                                'desc'    => __( 'Substitute unsupported product types with SimpleProduct', 'wp-graphql-woocommerce' ),
×
116
                                'type'    => 'checkbox',
×
117
                                'default' => 'off',
×
118
                        ],
×
119
                        [
×
120
                                'name'              => 'enable_authorizing_url_fields',
×
121
                                'label'             => __( 'Enable User Session transferring URLs', 'wp-graphql-woocommerce' ),
×
122
                                'desc'              => __( 'URL fields to add to the <strong>Customer</strong> type.', 'wp-graphql-woocommerce' )
×
123
                                        . ( $enable_auth_urls_hardcoded ? __( ' This setting is disabled. The "WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS" flag has been triggered with code', 'wp-graphql-woocommerce' ) : '' ),
×
124
                                'type'              => 'multicheck',
×
UNCOV
125
                                'options'           => apply_filters(
×
UNCOV
126
                                        'woographql_settings_enable_authorizing_url_options',
×
127
                                        [
×
128
                                                'cart_url'               => __( 'Cart URL. Field name: <strong>cartUrl</strong>', 'wp-graphql-woocommerce' ),
×
129
                                                'checkout_url'           => __( 'Checkout URL. Field name: <strong>checkoutUrl</strong>', 'wp-graphql-woocommerce' ),
×
130
                                                'account_url'            => __( 'Account URL. Field name: <strong>accountUrl</strong>', 'wp-graphql-woocommerce' ),
×
131
                                                'add_payment_method_url' => __( 'Add Payment Method URL. Field name: <strong>addPaymentMethodUrl</strong>', 'wp-graphql-woocommerce' ),
×
132
                                        ]
×
133
                                ),
×
UNCOV
134
                                'value'             => $enable_auth_urls_hardcoded ? $all_urls_checked : woographql_setting( 'enable_authorizing_url_fields', [] ),
×
135
                                'disabled'          => $enable_auth_urls_hardcoded,
×
136
                                'sanitize_callback' => static function ( $value ) {
×
137
                                        if ( empty( $value ) ) {
×
138
                                                return [];
×
139
                                        }
140

141
                                        return $value;
×
142
                                },
×
143
                        ],
×
144
                        [
×
145
                                'name'     => 'authorizing_url_endpoint',
×
146
                                'label'    => __( 'Endpoint for Authorizing URLs', 'wp-graphql-woocommerce' ),
×
147
                                'desc'     => sprintf(
×
148
                                        /* translators: %1$s: Site URL, %2$s: WooGraphQL Auth Endpoint */
149
                                        __( 'The endpoint (path) for transferring user sessions on the site. <a target="_blank" href="%1$s/%2$s">%1$s/%2$s</a>.', 'wp-graphql-woocommerce' ),
×
150
                                        site_url(),
×
151
                                        woographql_setting( 'authorizing_url_endpoint', 'transfer-session' )
×
152
                                ),
×
153
                                'type'     => 'text',
×
154
                                'default'  => ! empty( $custom_endpoint ) ? $custom_endpoint : 'transfer-session',
×
155
                                'disabled' => empty( $enabled_authorizing_url_fields ),
×
156
                        ],
×
157
                        [
×
158
                                'name'              => 'cart_url_nonce_param',
×
159
                                'label'             => __( 'Cart URL nonce name', 'wp-graphql-woocommerce' ),
×
UNCOV
160
                                'desc'              => __( 'Query parameter name of the nonce included in the "cartUrl" field', 'wp-graphql-woocommerce' )
×
161
                                        . ( $cart_url_hardcoded ? __( ' This setting is disabled. The "CART_URL_NONCE_PARAM" flag has been set with code', 'wp-graphql-woocommerce' ) : '' ),
×
UNCOV
162
                                'type'              => 'text',
×
UNCOV
163
                                'value'             => $cart_url_hardcoded ? CART_URL_NONCE_PARAM : woographql_setting( 'cart_url_nonce_param', '_wc_cart' ),
×
164
                                'disabled'          => defined( 'CART_URL_NONCE_PARAM' ) || ! in_array( 'cart_url', $enabled_authorizing_url_fields, true ),
×
165
                                'sanitize_callback' => static function ( $value ) {
×
166
                                        $other_nonces = self::get_other_nonce_values( 'cart_url' );
×
167
                                        if ( in_array( $value, $other_nonces, true ) ) {
×
168
                                                add_settings_error(
×
169
                                                        'cart_url_nonce_param',
×
170
                                                        'unique',
×
171
                                                        __( 'The <strong>Cart URL nonce name</strong> field must be unique', 'wp-graphql-woocommerce' ),
×
172
                                                        'error'
×
173
                                                );
×
174

175
                                                return '_wc_cart';
×
176
                                        }
177

178
                                        return $value;
×
179
                                },
×
180
                        ],
×
181
                        [
×
182
                                'name'              => 'checkout_url_nonce_param',
×
183
                                'label'             => __( 'Checkout URL nonce name', 'wp-graphql-woocommerce' ),
×
UNCOV
184
                                'desc'              => __( 'Query parameter name of the nonce included in the "checkoutUrl" field', 'wp-graphql-woocommerce' )
×
185
                                        . ( $checkout_url_hardcoded ? __( ' This setting is disabled. The "CHECKOUT_URL_NONCE_PARAM" flag has been set with code', 'wp-graphql-woocommerce' ) : '' ),
×
UNCOV
186
                                'type'              => 'text',
×
UNCOV
187
                                'value'             => $checkout_url_hardcoded ? CHECKOUT_URL_NONCE_PARAM : woographql_setting( 'checkout_url_nonce_param', '_wc_checkout' ),
×
188
                                'disabled'          => defined( 'CHECKOUT_URL_NONCE_PARAM' ) || ! in_array( 'checkout_url', $enabled_authorizing_url_fields, true ),
×
189
                                'sanitize_callback' => static function ( $value ) {
×
190
                                        $other_nonces = self::get_other_nonce_values( 'checkout_url' );
×
191
                                        if ( in_array( $value, $other_nonces, true ) ) {
×
192
                                                add_settings_error(
×
193
                                                        'checkout_url_nonce_param',
×
194
                                                        'unique',
×
195
                                                        __( 'The <strong>Checkout URL nonce name</strong> field must be unique', 'wp-graphql-woocommerce' ),
×
196
                                                        'error'
×
197
                                                );
×
198

199
                                                return '_wc_checkout';
×
200
                                        }
201

202
                                        return $value;
×
203
                                },
×
204
                        ],
×
205
                        [
×
206
                                'name'              => 'account_url_nonce_param',
×
207
                                'label'             => __( 'Account URL nonce name', 'wp-graphql-woocommerce' ),
×
UNCOV
208
                                'desc'              => __( 'Query parameter name of the nonce included in the "accountUrl" field', 'wp-graphql-woocommerce' )
×
209
                                        . ( $account_url_hardcoded ? __( ' This setting is disabled. The "ACCOUNT_URL_NONCE_PARAM" flag has been set with code', 'wp-graphql-woocommerce' ) : '' ),
×
UNCOV
210
                                'type'              => 'text',
×
UNCOV
211
                                'value'             => $account_url_hardcoded ? ACCOUNT_URL_NONCE_PARAM : woographql_setting( 'account_url_nonce_param', '_wc_account' ),
×
212
                                'disabled'          => defined( 'ACCOUNT_URL_NONCE_PARAM' ) || ! in_array( 'account_url', $enabled_authorizing_url_fields, true ),
×
213
                                'sanitize_callback' => static function ( $value ) {
×
214
                                        $other_nonces = self::get_other_nonce_values( 'account_url' );
×
215
                                        if ( in_array( $value, $other_nonces, true ) ) {
×
216
                                                add_settings_error(
×
217
                                                        'account_url_nonce_param',
×
218
                                                        'unique',
×
219
                                                        __( 'The <strong>Account URL nonce name</strong> field must be unique', 'wp-graphql-woocommerce' ),
×
220
                                                        'error'
×
221
                                                );
×
222

223
                                                return '_wc_account';
×
224
                                        }
225

226
                                        return $value;
×
227
                                },
×
228
                        ],
×
229
                        [
×
230
                                'name'              => 'add_payment_method_url_nonce_param',
×
231
                                'label'             => __( 'Add Payment Method URL nonce name', 'wp-graphql-woocommerce' ),
×
UNCOV
232
                                'desc'              => __( 'Query parameter name of the nonce included in the "addPaymentMethodUrl" field', 'wp-graphql-woocommerce' )
×
233
                                        . ( $add_payment_method_url_hardcoded ? __( ' This setting is disabled. The "ADD_PAYMENT_METHOD_URL_NONCE_PARAM" flag has been set with code', 'wp-graphql-woocommerce' ) : '' ),
×
UNCOV
234
                                'type'              => 'text',
×
UNCOV
235
                                'value'             => $add_payment_method_url_hardcoded ? ADD_PAYMENT_METHOD_URL_NONCE_PARAM : woographql_setting( 'add_payment_method_url_nonce_param', '_wc_payment' ),
×
236
                                'disabled'          => defined( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) || ! in_array( 'add_payment_method_url', $enabled_authorizing_url_fields, true ),
×
237
                                'sanitize_callback' => static function ( $value ) {
×
238
                                        $other_nonces = self::get_other_nonce_values( 'add_payment_method_url' );
×
239
                                        if ( in_array( $value, $other_nonces, true ) ) {
×
UNCOV
240
                                                add_settings_error(
×
UNCOV
241
                                                        'add_payment_method_url_nonce_param',
×
UNCOV
242
                                                        'unique',
×
UNCOV
243
                                                        __( 'The <strong>Add Payment Method URL nonce name</strong> field must be unique', 'wp-graphql-woocommerce' ),
×
UNCOV
244
                                                        'error'
×
UNCOV
245
                                                );
×
246

UNCOV
247
                                                return '_wc_payment';
×
248
                                        }
249

UNCOV
250
                                        return $value;
×
UNCOV
251
                                },
×
UNCOV
252
                        ],
×
UNCOV
253
                ];
×
254
        }
255
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc