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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / Api / Settings.php
woocommerce / src / Internal / Api Last commit date
Autogenerated 4 weeks ago GraphQLEndpointRegistrar.php 4 weeks ago OpcacheFileExpiry.php 4 weeks ago QueryCache.php 4 weeks ago QueryComplexityRule.php 4 weeks ago QueryDepthRule.php 4 weeks ago Settings.php 4 weeks ago StatusResolverFailedException.php 4 weeks ago
Settings.php
188 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Automattic\WooCommerce\Internal\Api;
6
7 use Automattic\WooCommerce\Api\Infrastructure\GraphQLControllerBase;
8 use Automattic\WooCommerce\Api\Infrastructure\Main;
9
10 /**
11 * Settings handling for the GraphQL API.
12 *
13 * Registers the "GraphQL" section under WooCommerce - Settings - Advanced.
14 * Only active when Main::is_enabled() returns true (feature flag on and
15 * PHP 8.1+), so the section is hidden when the feature is disabled.
16 */
17 class Settings {
18 /**
19 * Identifier for the GraphQL section under the Advanced settings tab.
20 */
21 public const SECTION_ID = 'graphql';
22
23 /**
24 * Register the filter hooks that expose the GraphQL settings section.
25 */
26 public function register(): void {
27 add_filter( 'woocommerce_get_sections_advanced', array( $this, 'add_section' ) );
28 add_filter( 'woocommerce_get_settings_advanced', array( $this, 'add_settings' ), 10, 2 );
29 add_filter(
30 'woocommerce_admin_settings_sanitize_option_' . Main::OPTION_ENDPOINT_URL,
31 array( $this, 'sanitize_endpoint_url' ),
32 10,
33 3
34 );
35 }
36
37 /**
38 * Append the GraphQL section to the Advanced settings tab.
39 *
40 * @param array $sections Existing sections keyed by id.
41 * @return array
42 */
43 public function add_section( array $sections ): array {
44 if ( Main::is_enabled() ) {
45 $sections[ self::SECTION_ID ] = __( 'GraphQL', 'woocommerce' );
46 }
47 return $sections;
48 }
49
50 /**
51 * Provide the settings fields for the GraphQL section.
52 *
53 * @param array $settings Existing settings for the current section.
54 * @param string $section_id Current section id.
55 * @return array
56 */
57 public function add_settings( array $settings, string $section_id ): array {
58 if ( self::SECTION_ID !== $section_id || ! Main::is_enabled() ) {
59 return $settings;
60 }
61
62 return array(
63 array(
64 'title' => __( 'GraphQL', 'woocommerce' ),
65 'desc' => __( 'Configure the WooCommerce GraphQL API.', 'woocommerce' ),
66 'type' => 'title',
67 'id' => 'woocommerce_graphql_options',
68 ),
69 array(
70 'title' => __( 'Endpoint URL', 'woocommerce' ),
71 'desc' => __( 'Path relative to /wp-json/ where the GraphQL endpoint is exposed. Needs at least two segments (namespace/route), e.g. wc/graphql.', 'woocommerce' ),
72 'desc_tip' => true,
73 'id' => Main::OPTION_ENDPOINT_URL,
74 'default' => GraphQLControllerBase::DEFAULT_ENDPOINT_URL,
75 'type' => 'text',
76 ),
77 array(
78 'title' => __( 'Enable GET endpoint', 'woocommerce' ),
79 'desc' => __( 'Allow GraphQL queries over GET in addition to POST', 'woocommerce' ),
80 'id' => Main::OPTION_GET_ENDPOINT_ENABLED,
81 'default' => 'yes',
82 'type' => 'checkbox',
83 ),
84 array(
85 'title' => __( 'Maximum query depth', 'woocommerce' ),
86 'desc' => __( 'Reject queries whose selection nesting exceeds this depth.', 'woocommerce' ),
87 'id' => Main::OPTION_MAX_QUERY_DEPTH,
88 'default' => (string) GraphQLControllerBase::DEFAULT_MAX_QUERY_DEPTH,
89 'type' => 'number',
90 'custom_attributes' => array( 'min' => '1' ),
91 ),
92 array(
93 'title' => __( 'Maximum query complexity', 'woocommerce' ),
94 'desc' => __( 'Reject queries whose computed complexity score exceeds this value.', 'woocommerce' ),
95 'id' => Main::OPTION_MAX_QUERY_COMPLEXITY,
96 'default' => (string) GraphQLControllerBase::DEFAULT_MAX_QUERY_COMPLEXITY,
97 'type' => 'number',
98 'custom_attributes' => array( 'min' => '1' ),
99 ),
100 array(
101 'title' => __( 'Enable OPcache-based caching', 'woocommerce' ),
102 'desc' => __( 'Cache parsed queries on disk as PHP files so OPcache can serve them from shared memory. Falls back to the object cache when the filesystem is not writable.', 'woocommerce' ),
103 'id' => Main::OPTION_OPCACHE_ENABLED,
104 'default' => 'yes',
105 'type' => 'checkbox',
106 ),
107 array(
108 'title' => __( 'Enable ObjectCache-based caching', 'woocommerce' ),
109 'desc' => __( 'Cache parsed queries in the WP object cache', 'woocommerce' ),
110 'id' => Main::OPTION_OBJECT_CACHE_ENABLED,
111 'default' => 'yes',
112 'type' => 'checkbox',
113 ),
114 array(
115 'title' => __( 'Enable APQ caching', 'woocommerce' ),
116 'desc' => __( 'Cache parsed queries using the Apollo Automatic Persisted Queries protocol', 'woocommerce' ),
117 'id' => Main::OPTION_APQ_ENABLED,
118 'default' => 'yes',
119 'type' => 'checkbox',
120 ),
121 array(
122 'title' => __( 'Parsed query cache TTL', 'woocommerce' ),
123 'desc' => __( 'Time in seconds before cached parsed queries expire.', 'woocommerce' ),
124 'id' => Main::OPTION_QUERY_CACHE_TTL,
125 'default' => (string) QueryCache::DEFAULT_CACHE_TTL,
126 'type' => 'number',
127 'custom_attributes' => array( 'min' => '1' ),
128 ),
129 array(
130 'type' => 'sectionend',
131 'id' => 'woocommerce_graphql_options',
132 ),
133 );
134 }
135
136 /**
137 * Validate and normalize the endpoint URL on save.
138 *
139 * Rejects empty input and inputs without at least two path segments, since
140 * register_rest_route() needs both a namespace and a route. Rejects any
141 * character outside of what WordPress REST routes accept (alphanumerics,
142 * underscores, hyphens). On rejection, adds a settings error message and
143 * returns the previously stored value so the option is not overwritten.
144 *
145 * @param mixed $value The sanitized value passed by earlier filters.
146 * @param array $option The option config from add_settings().
147 * @param mixed $raw_value The raw value submitted by the form. Typed as mixed because POST data can be null or an array (e.g. when the field name is submitted as `name[]`).
148 * @return string
149 */
150 public function sanitize_endpoint_url( $value, array $option, $raw_value ): string {
151 unset( $value, $option );
152
153 $fallback = (string) get_option( Main::OPTION_ENDPOINT_URL, GraphQLControllerBase::DEFAULT_ENDPOINT_URL );
154
155 if ( ! is_string( $raw_value ) ) {
156 return $fallback;
157 }
158
159 $normalized = trim( $raw_value, '/' );
160
161 if ( '' === $normalized ) {
162 \WC_Admin_Settings::add_error( __( 'GraphQL endpoint URL cannot be empty.', 'woocommerce' ) );
163 return $fallback;
164 }
165
166 $parts = explode( '/', $normalized );
167 if ( count( $parts ) < 2 ) {
168 \WC_Admin_Settings::add_error( __( 'GraphQL endpoint URL needs at least two segments, e.g. wc/graphql.', 'woocommerce' ) );
169 return $fallback;
170 }
171
172 foreach ( $parts as $part ) {
173 if ( '' === $part || ! preg_match( GraphQLControllerBase::ENDPOINT_URL_SEGMENT_PATTERN, $part ) ) {
174 \WC_Admin_Settings::add_error(
175 sprintf(
176 /* translators: %s: the invalid path segment */
177 __( 'GraphQL endpoint URL segment "%s" contains invalid characters. Use letters, digits, underscores, and hyphens only.', 'woocommerce' ),
178 $part
179 )
180 );
181 return $fallback;
182 }
183 }
184
185 return $normalized;
186 }
187 }
188