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

wp-graphql / wp-graphql-woocommerce / 5603640472

pending completion
5603640472

push

github

web-flow
fix: clean up unnecessary variables and ternaries (#766)

21 of 21 new or added lines in 16 files covered. (100.0%)

10249 of 12438 relevant lines covered (82.4%)

54.02 hits per line

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

5.45
/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
        /**
16
         * Returns the other nonce values besides the one provided.
17
         *
18
         * @param string $excluded  Slug of nonce value to be excluded.
19
         *
20
         * @return array
21
         */
22
        public static function get_other_nonce_values( $excluded ) {
23
                $nonce_values = apply_filters(
×
24
                        'woographql_authorizing_url_nonce_values',
×
25
                        [
×
26
                                'cart_url'               => woographql_setting( 'cart_url_nonce_param', '_wc_cart' ),
×
27
                                'checkout_url'           => woographql_setting( 'checkout_url_nonce_param', '_wc_checkout' ),
×
28
                                'account_url'            => woographql_setting( 'account_url_nonce_param', '_wc_account' ),
×
29
                                'add_payment_method_url' => woographql_setting( 'add_payment_method_url_nonce_param', '_wc_payment' ),
×
30
                        ]
×
31
                );
×
32

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

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

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

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

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

71
                return [
×
72
                        [
×
73
                                'name'     => 'disable_ql_session_handler',
×
74
                                'label'    => __( 'Disable QL Session Handler', 'wp-graphql-woocommerce' ),
×
75
                                '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' )
×
76
                                        . ( defined( 'NO_QL_SESSION_HANDLER' ) ? __( ' This setting is disabled. The "NO_QL_SESSION_HANDLER" flag has been triggered with code', 'wp-graphql-woocommerce' ) : '' ),
×
77
                                'type'     => 'checkbox',
×
78
                                'value'    => defined( 'NO_QL_SESSION_HANDLER' ) ? 'on' : woographql_setting( 'disable_ql_session_handler', 'off' ),
×
79
                                'disabled' => defined( 'NO_QL_SESSION_HANDLER' ),
×
80
                        ],
×
81
                        [
×
82
                                'name'    => 'enable_unsupported_product_type',
×
83
                                'label'   => __( 'Enable Unsupported types', 'wp-graphql-woocommerce' ),
×
84
                                'desc'    => __( 'Substitute unsupported product types with SimpleProduct', 'wp-graphql-woocommerce' ),
×
85
                                'type'    => 'checkbox',
×
86
                                'default' => 'off',
×
87
                        ],
×
88
                        [
×
89
                                'name'              => 'enable_authorizing_url_fields',
×
90
                                'label'             => __( 'Enable User Session transferring URLs', 'wp-graphql-woocommerce' ),
×
91
                                'desc'              => __( 'URL fields to add to the <strong>Customer</strong> type.', 'wp-graphql-woocommerce' )
×
92
                                        . ( $enable_auth_urls_hardcoded ? __( ' This setting is disabled. The "WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS" flag has been triggered with code', 'wp-graphql-woocommerce' ) : '' ),
×
93
                                'type'              => 'multicheck',
×
94
                                'options'           => apply_filters(
×
95
                                        'woographql_settings_enable_authorizing_url_options',
×
96
                                        [
×
97
                                                'cart_url'               => __( 'Cart URL. Field name: <strong>cartUrl</strong>', 'wp-graphql-woocommerce' ),
×
98
                                                'checkout_url'           => __( 'Checkout URL. Field name: <strong>checkoutUrl</strong>', 'wp-graphql-woocommerce' ),
×
99
                                                'account_url'            => __( 'Account URL. Field name: <strong>accountUrl</strong>', 'wp-graphql-woocommerce' ),
×
100
                                                'add_payment_method_url' => __( 'Add Payment Method URL. Field name: <strong>addPaymentMethodUrl</strong>', 'wp-graphql-woocommerce' ),
×
101
                                        ]
×
102
                                ),
×
103
                                'value'             => $enable_auth_urls_hardcoded ? $all_urls_checked : woographql_setting( 'enable_authorizing_url_fields', [] ),
×
104
                                'disabled'          => $enable_auth_urls_hardcoded,
×
105
                                'sanitize_callback' => static function( $value ) {
×
106
                                        if ( empty( $value ) ) {
×
107
                                                return [];
×
108
                                        }
109

110
                                        return $value;
×
111
                                },
×
112
                        ],
×
113
                        [
×
114
                                'name'     => 'authorizing_url_endpoint',
×
115
                                'label'    => __( 'Endpoint for Authorizing URLs', 'wp-graphql-woocommerce' ),
×
116
                                'desc'     => sprintf(
×
117
                                        /* translators: %1$s: Site URL, %2$s: WooGraphQL Auth Endpoint */
118
                                        __( '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' ),
×
119
                                        site_url(),
×
120
                                        woographql_setting( 'authorizing_url_endpoint', 'transfer-session' )
×
121
                                ),
×
122
                                'type'     => 'text',
×
123
                                'default'  => ! empty( $custom_endpoint ) ? $custom_endpoint : 'transfer-session',
×
124
                                'disabled' => empty( $enabled_authorizing_url_fields ),
×
125
                        ],
×
126
                        [
×
127
                                'name'              => 'cart_url_nonce_param',
×
128
                                'label'             => __( 'Cart URL nonce name', 'wp-graphql-woocommerce' ),
×
129
                                'desc'              => __( 'Query parameter name of the nonce included in the "cartUrl" field', 'wp-graphql-woocommerce' )
×
130
                                        . ( $cart_url_hardcoded ? __( ' This setting is disabled. The "CART_URL_NONCE_PARAM" flag has been set with code', 'wp-graphql-woocommerce' ) : '' ),
×
131
                                'type'              => 'text',
×
132
                                'value'             => $cart_url_hardcoded ? CART_URL_NONCE_PARAM : woographql_setting( 'cart_url_nonce_param', '_wc_cart' ),
×
133
                                'disabled'          => defined( 'CART_URL_NONCE_PARAM' ) || ! in_array( 'cart_url', $enabled_authorizing_url_fields, true ),
×
134
                                'sanitize_callback' => static function ( $value ) {
×
135
                                        $other_nonces = self::get_other_nonce_values( 'cart_url' );
×
136
                                        if ( in_array( $value, $other_nonces, true ) ) {
×
137
                                                add_settings_error(
×
138
                                                        'cart_url_nonce_param',
×
139
                                                        'unique',
×
140
                                                        __( 'The <strong>Cart URL nonce name</strong> field must be unique', 'wp-graphql-woocommerce' ),
×
141
                                                        'error'
×
142
                                                );
×
143

144
                                                return '_wc_cart';
×
145
                                        }
146

147
                                        return $value;
×
148
                                },
×
149
                        ],
×
150
                        [
×
151
                                'name'              => 'checkout_url_nonce_param',
×
152
                                'label'             => __( 'Checkout URL nonce name', 'wp-graphql-woocommerce' ),
×
153
                                'desc'              => __( 'Query parameter name of the nonce included in the "checkoutUrl" field', 'wp-graphql-woocommerce' )
×
154
                                        . ( $checkout_url_hardcoded ? __( ' This setting is disabled. The "CHECKOUT_URL_NONCE_PARAM" flag has been set with code', 'wp-graphql-woocommerce' ) : '' ),
×
155
                                'type'              => 'text',
×
156
                                'value'             => $checkout_url_hardcoded ? CHECKOUT_URL_NONCE_PARAM : woographql_setting( 'checkout_url_nonce_param', '_wc_checkout' ),
×
157
                                'disabled'          => defined( 'CHECKOUT_URL_NONCE_PARAM' ) || ! in_array( 'checkout_url', $enabled_authorizing_url_fields, true ),
×
158
                                'sanitize_callback' => static function ( $value ) {
×
159
                                        $other_nonces = self::get_other_nonce_values( 'checkout_url' );
×
160
                                        if ( in_array( $value, $other_nonces, true ) ) {
×
161
                                                add_settings_error(
×
162
                                                        'checkout_url_nonce_param',
×
163
                                                        'unique',
×
164
                                                        __( 'The <strong>Checkout URL nonce name</strong> field must be unique', 'wp-graphql-woocommerce' ),
×
165
                                                        'error'
×
166
                                                );
×
167

168
                                                return '_wc_checkout';
×
169
                                        }
170

171
                                        return $value;
×
172
                                },
×
173
                        ],
×
174
                        [
×
175
                                'name'              => 'account_url_nonce_param',
×
176
                                'label'             => __( 'Account URL nonce name', 'wp-graphql-woocommerce' ),
×
177
                                'desc'              => __( 'Query parameter name of the nonce included in the "accountUrl" field', 'wp-graphql-woocommerce' )
×
178
                                        . ( $account_url_hardcoded ? __( ' This setting is disabled. The "ACCOUNT_URL_NONCE_PARAM" flag has been set with code', 'wp-graphql-woocommerce' ) : '' ),
×
179
                                'type'              => 'text',
×
180
                                'value'             => $account_url_hardcoded ? ACCOUNT_URL_NONCE_PARAM : woographql_setting( 'account_url_nonce_param', '_wc_account' ),
×
181
                                'disabled'          => defined( 'ACCOUNT_URL_NONCE_PARAM' ) || ! in_array( 'account_url', $enabled_authorizing_url_fields, true ),
×
182
                                'sanitize_callback' => static function ( $value ) {
×
183
                                        $other_nonces = self::get_other_nonce_values( 'account_url' );
×
184
                                        if ( in_array( $value, $other_nonces, true ) ) {
×
185
                                                add_settings_error(
×
186
                                                        'account_url_nonce_param',
×
187
                                                        'unique',
×
188
                                                        __( 'The <strong>Account URL nonce name</strong> field must be unique', 'wp-graphql-woocommerce' ),
×
189
                                                        'error'
×
190
                                                );
×
191

192
                                                return '_wc_account';
×
193
                                        }
194

195
                                        return $value;
×
196
                                },
×
197
                        ],
×
198
                        [
×
199
                                'name'              => 'add_payment_method_url_nonce_param',
×
200
                                'label'             => __( 'Add Payment Method URL nonce name', 'wp-graphql-woocommerce' ),
×
201
                                'desc'              => __( 'Query parameter name of the nonce included in the "addPaymentMethodUrl" field', 'wp-graphql-woocommerce' )
×
202
                                        . ( $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' ) : '' ),
×
203
                                'type'              => 'text',
×
204
                                'value'             => $add_payment_method_url_hardcoded ? ADD_PAYMENT_METHOD_URL_NONCE_PARAM : woographql_setting( 'add_payment_method_url_nonce_param', '_wc_payment' ),
×
205
                                'disabled'          => defined( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) || ! in_array( 'add_payment_method_url', $enabled_authorizing_url_fields, true ),
×
206
                                'sanitize_callback' => static function ( $value ) {
×
207
                                        $other_nonces = self::get_other_nonce_values( 'add_payment_method_url' );
×
208
                                        if ( in_array( $value, $other_nonces, true ) ) {
×
209
                                                add_settings_error(
×
210
                                                        'add_payment_method_url_nonce_param',
×
211
                                                        'unique',
×
212
                                                        __( 'The <strong>Add Payment Method URL nonce name</strong> field must be unique', 'wp-graphql-woocommerce' ),
×
213
                                                        'error'
×
214
                                                );
×
215

216
                                                return '_wc_payment';
×
217
                                        }
218

219
                                        return $value;
×
220
                                },
×
221
                        ],
×
222
                ];
×
223
        }
224
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc