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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 / includes / rest-api / Controllers / Version3 / class-wc-rest-setting-options-controller.php
woocommerce / includes / rest-api / Controllers / Version3 Last commit date
class-wc-rest-controller.php 1 year ago class-wc-rest-coupons-controller.php 4 years ago class-wc-rest-crud-controller.php 7 months ago class-wc-rest-customer-downloads-controller.php 5 years ago class-wc-rest-customers-controller.php 3 years ago class-wc-rest-data-continents-controller.php 4 months ago class-wc-rest-data-controller.php 5 years ago class-wc-rest-data-countries-controller.php 4 months ago class-wc-rest-data-currencies-controller.php 4 months ago class-wc-rest-layout-templates-controller.php 2 years ago class-wc-rest-network-orders-controller.php 5 years ago class-wc-rest-order-notes-controller.php 5 years ago class-wc-rest-order-refunds-controller.php 2 months ago class-wc-rest-orders-controller.php 2 months ago class-wc-rest-payment-gateways-controller.php 1 year ago class-wc-rest-paypal-buttons-controller.php 5 months ago class-wc-rest-paypal-standard-controller.php 3 months ago class-wc-rest-paypal-webhooks-controller.php 3 months ago class-wc-rest-posts-controller.php 2 years ago class-wc-rest-product-attribute-terms-controller.php 5 years ago class-wc-rest-product-attributes-controller.php 2 years ago class-wc-rest-product-brands-controller.php 1 year ago class-wc-rest-product-categories-controller.php 3 months ago class-wc-rest-product-custom-fields-controller.php 1 year ago class-wc-rest-product-reviews-controller.php 1 year ago class-wc-rest-product-shipping-classes-controller.php 1 year ago class-wc-rest-product-tags-controller.php 5 years ago class-wc-rest-product-variations-controller.php 1 month ago class-wc-rest-products-catalog-controller.php 7 months ago class-wc-rest-products-controller.php 2 months ago class-wc-rest-refunds-controller.php 2 years ago class-wc-rest-report-coupons-totals-controller.php 5 years ago class-wc-rest-report-customers-totals-controller.php 5 years ago class-wc-rest-report-orders-totals-controller.php 2 years ago class-wc-rest-report-products-totals-controller.php 5 years ago class-wc-rest-report-reviews-totals-controller.php 5 years ago class-wc-rest-report-sales-controller.php 5 years ago class-wc-rest-report-top-sellers-controller.php 5 years ago class-wc-rest-reports-controller.php 5 years ago class-wc-rest-setting-options-controller.php 4 months ago class-wc-rest-settings-controller.php 5 years ago class-wc-rest-shipping-methods-controller.php 5 years ago class-wc-rest-shipping-zone-locations-controller.php 5 years ago class-wc-rest-shipping-zone-methods-controller.php 5 years ago class-wc-rest-shipping-zones-controller-base.php 5 years ago class-wc-rest-shipping-zones-controller.php 5 years ago class-wc-rest-system-status-controller.php 5 years ago class-wc-rest-system-status-tools-controller.php 5 years ago class-wc-rest-tax-classes-controller.php 5 years ago class-wc-rest-taxes-controller.php 5 years ago class-wc-rest-terms-controller.php 1 month ago class-wc-rest-variations-controller.php 9 months ago class-wc-rest-webhooks-controller.php 5 years ago
class-wc-rest-setting-options-controller.php
259 lines
1 <?php
2 /**
3 * REST API Setting Options controller
4 *
5 * Handles requests to the /settings/$group/$setting endpoints.
6 *
7 * @package WooCommerce\RestApi
8 * @since 3.0.0
9 */
10
11 defined( 'ABSPATH' ) || exit;
12
13 /**
14 * REST API Setting Options controller class.
15 *
16 * @package WooCommerce\RestApi
17 * @extends WC_REST_Setting_Options_V2_Controller
18 */
19 class WC_REST_Setting_Options_Controller extends WC_REST_Setting_Options_V2_Controller {
20
21 /**
22 * Endpoint namespace.
23 *
24 * @var string
25 */
26 protected $namespace = 'wc/v3';
27
28 /**
29 * Get setting data.
30 *
31 * @param string $group_id Group ID.
32 * @param string $setting_id Setting ID.
33 * @return stdClass|WP_Error
34 */
35 public function get_setting( $group_id, $setting_id ) {
36 $setting = parent::get_setting( $group_id, $setting_id );
37 if ( is_wp_error( $setting ) ) {
38 return $setting;
39 }
40 $setting['group_id'] = $group_id;
41 return $setting;
42 }
43
44 /**
45 * Callback for allowed keys for each setting response.
46 *
47 * @param string $key Key to check.
48 * @return boolean
49 */
50 public function allowed_setting_keys( $key ) {
51 return in_array(
52 $key, array(
53 'id',
54 'group_id',
55 'label',
56 'description',
57 'default',
58 'tip',
59 'placeholder',
60 'type',
61 'options',
62 'value',
63 'option_key',
64 ), true
65 );
66 }
67
68 /**
69 * Get all settings in a group.
70 *
71 * @param string $group_id Group ID.
72 * @return array|WP_Error
73 */
74 public function get_group_settings( $group_id ) {
75 if ( empty( $group_id ) ) {
76 return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
77 }
78
79 $settings = apply_filters( 'woocommerce_settings-' . $group_id, array() ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
80
81 if ( empty( $settings ) ) {
82 return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
83 }
84
85 $this->prime_options_cache_for_settings( $settings );
86
87 $filtered_settings = array();
88 foreach ( $settings as $setting ) {
89 $option_key = $setting['option_key'];
90 $setting = $this->filter_setting( $setting );
91 $default = isset( $setting['default'] ) ? $setting['default'] : '';
92
93 if ( in_array( $setting['type'] ?? '', array( 'title', 'sectionend' ), true ) ) {
94 $filtered_settings[] = $setting;
95 continue;
96 }
97
98 // Get the option value.
99 if ( is_array( $option_key ) ) {
100 $option = get_option( $option_key[0] );
101 $setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default;
102 } else {
103 $admin_setting_value = WC_Admin_Settings::get_option( $option_key, $default );
104 $setting['value'] = $admin_setting_value;
105 }
106
107 if ( 'multi_select_countries' === $setting['type'] ) {
108 $setting['options'] = WC()->countries->get_countries();
109 $setting['type'] = 'multiselect';
110 } elseif ( 'single_select_country' === $setting['type'] ) {
111 $setting['type'] = 'select';
112 $setting['options'] = $this->get_countries_and_states();
113 } elseif ( $setting['type'] === 'single_select_page' || $setting['type'] === 'single_select_page_with_search' ) {
114 $pages = get_pages(
115 array(
116 'sort_column' => 'menu_order',
117 'sort_order' => 'ASC',
118 'hierarchical' => 0,
119 )
120 );
121 $options = array();
122 foreach ( $pages as $page ) {
123 $options[ $page->ID ] = ! empty( $page->post_title ) ? $page->post_title : '#' . $page->ID;
124 }
125 $setting['type'] = 'select';
126 $setting['options'] = $options;
127 }
128
129 $filtered_settings[] = $setting;
130 }
131
132 return $filtered_settings;
133 }
134
135 /**
136 * Returns a list of countries and states for use in the base location setting.
137 *
138 * @since 3.0.7
139 * @return array Array of states and countries.
140 */
141 private function get_countries_and_states() {
142 $countries = WC()->countries->get_countries();
143 if ( ! $countries ) {
144 return array();
145 }
146 $output = array();
147 foreach ( $countries as $key => $value ) {
148 $states = WC()->countries->get_states( $key );
149
150 if ( $states ) {
151 foreach ( $states as $state_key => $state_value ) {
152 $output[ $key . ':' . $state_key ] = $value . ' - ' . $state_value;
153 }
154 } else {
155 $output[ $key ] = $value;
156 }
157 }
158 return $output;
159 }
160
161 /**
162 * Get the settings schema, conforming to JSON Schema.
163 *
164 * @return array
165 */
166 public function get_item_schema() {
167 $schema = array(
168 '$schema' => 'http://json-schema.org/draft-04/schema#',
169 'title' => 'setting',
170 'type' => 'object',
171 'properties' => array(
172 'id' => array(
173 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ),
174 'type' => 'string',
175 'arg_options' => array(
176 'sanitize_callback' => 'sanitize_title',
177 ),
178 'context' => array( 'view', 'edit' ),
179 'readonly' => true,
180 ),
181 'group_id' => array(
182 'description' => __( 'An identifier for the group this setting belongs to.', 'woocommerce' ),
183 'type' => 'string',
184 'arg_options' => array(
185 'sanitize_callback' => 'sanitize_title',
186 ),
187 'context' => array( 'view', 'edit' ),
188 'readonly' => true,
189 ),
190 'label' => array(
191 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
192 'type' => 'string',
193 'arg_options' => array(
194 'sanitize_callback' => 'sanitize_text_field',
195 ),
196 'context' => array( 'view', 'edit' ),
197 'readonly' => true,
198 ),
199 'description' => array(
200 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ),
201 'type' => 'string',
202 'arg_options' => array(
203 'sanitize_callback' => 'sanitize_text_field',
204 ),
205 'context' => array( 'view', 'edit' ),
206 'readonly' => true,
207 ),
208 'value' => array(
209 'description' => __( 'Setting value.', 'woocommerce' ),
210 'type' => 'mixed',
211 'context' => array( 'view', 'edit' ),
212 ),
213 'default' => array(
214 'description' => __( 'Default value for the setting.', 'woocommerce' ),
215 'type' => 'mixed',
216 'context' => array( 'view', 'edit' ),
217 'readonly' => true,
218 ),
219 'tip' => array(
220 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ),
221 'type' => 'string',
222 'arg_options' => array(
223 'sanitize_callback' => 'sanitize_text_field',
224 ),
225 'context' => array( 'view', 'edit' ),
226 'readonly' => true,
227 ),
228 'placeholder' => array(
229 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ),
230 'type' => 'string',
231 'arg_options' => array(
232 'sanitize_callback' => 'sanitize_text_field',
233 ),
234 'context' => array( 'view', 'edit' ),
235 'readonly' => true,
236 ),
237 'type' => array(
238 'description' => __( 'Type of setting.', 'woocommerce' ),
239 'type' => 'string',
240 'arg_options' => array(
241 'sanitize_callback' => 'sanitize_text_field',
242 ),
243 'context' => array( 'view', 'edit' ),
244 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ),
245 'readonly' => true,
246 ),
247 'options' => array(
248 'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ),
249 'type' => 'object',
250 'context' => array( 'view', 'edit' ),
251 'readonly' => true,
252 ),
253 ),
254 );
255
256 return $this->add_additional_fields_schema( $schema );
257 }
258 }
259