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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 / api / class-wc-rest-setting-options-controller.php
woocommerce / includes / api Last commit date
legacy 7 years ago v1 7 years ago v2 6 years ago wc-blocks 7 years ago class-wc-rest-authentication.php 7 years ago class-wc-rest-coupons-controller.php 7 years ago class-wc-rest-customer-downloads-controller.php 7 years ago class-wc-rest-customers-controller.php 7 years ago class-wc-rest-data-continents-controller.php 7 years ago class-wc-rest-data-controller.php 7 years ago class-wc-rest-data-countries-controller.php 7 years ago class-wc-rest-data-currencies-controller.php 7 years ago class-wc-rest-exception.php 8 years ago class-wc-rest-network-orders-controller.php 7 years ago class-wc-rest-order-notes-controller.php 7 years ago class-wc-rest-order-refunds-controller.php 7 years ago class-wc-rest-orders-controller.php 7 years ago class-wc-rest-payment-gateways-controller.php 7 years ago class-wc-rest-product-attribute-terms-controller.php 7 years ago class-wc-rest-product-attributes-controller.php 7 years ago class-wc-rest-product-categories-controller.php 7 years ago class-wc-rest-product-reviews-controller.php 7 years ago class-wc-rest-product-shipping-classes-controller.php 7 years ago class-wc-rest-product-tags-controller.php 7 years ago class-wc-rest-product-variations-controller.php 7 years ago class-wc-rest-products-controller.php 7 years ago class-wc-rest-report-coupons-totals-controller.php 7 years ago class-wc-rest-report-customers-totals-controller.php 7 years ago class-wc-rest-report-orders-totals-controller.php 7 years ago class-wc-rest-report-products-totals-controller.php 7 years ago class-wc-rest-report-reviews-totals-controller.php 7 years ago class-wc-rest-report-sales-controller.php 7 years ago class-wc-rest-report-top-sellers-controller.php 7 years ago class-wc-rest-reports-controller.php 7 years ago class-wc-rest-setting-options-controller.php 7 years ago class-wc-rest-settings-controller.php 7 years ago class-wc-rest-shipping-methods-controller.php 7 years ago class-wc-rest-shipping-zone-locations-controller.php 7 years ago class-wc-rest-shipping-zone-methods-controller.php 7 years ago class-wc-rest-shipping-zones-controller.php 7 years ago class-wc-rest-system-status-controller.php 7 years ago class-wc-rest-system-status-tools-controller.php 7 years ago class-wc-rest-tax-classes-controller.php 7 years ago class-wc-rest-taxes-controller.php 7 years ago class-wc-rest-webhooks-controller.php 7 years ago
class-wc-rest-setting-options-controller.php
251 lines
1 <?php
2 /**
3 * REST API Setting Options controller
4 *
5 * Handles requests to the /settings/$group/$setting endpoints.
6 *
7 * @package WooCommerce/API
8 * @since 3.0.0
9 */
10
11 defined( 'ABSPATH' ) || exit;
12
13 /**
14 * REST API Setting Options controller class.
15 *
16 * @package WooCommerce/API
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 $filtered_settings = array();
86 foreach ( $settings as $setting ) {
87 $option_key = $setting['option_key'];
88 $setting = $this->filter_setting( $setting );
89 $default = isset( $setting['default'] ) ? $setting['default'] : '';
90 // Get the option value.
91 if ( is_array( $option_key ) ) {
92 $option = get_option( $option_key[0] );
93 $setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default;
94 } else {
95 $admin_setting_value = WC_Admin_Settings::get_option( $option_key, $default );
96 $setting['value'] = $admin_setting_value;
97 }
98
99 if ( 'multi_select_countries' === $setting['type'] ) {
100 $setting['options'] = WC()->countries->get_countries();
101 $setting['type'] = 'multiselect';
102 } elseif ( 'single_select_country' === $setting['type'] ) {
103 $setting['type'] = 'select';
104 $setting['options'] = $this->get_countries_and_states();
105 } elseif ( 'single_select_page' === $setting['type'] ) {
106 $pages = get_pages(
107 array(
108 'sort_column' => 'menu_order',
109 'sort_order' => 'ASC',
110 'hierarchical' => 0,
111 )
112 );
113 $options = array();
114 foreach ( $pages as $page ) {
115 $options[ $page->ID ] = ! empty( $page->post_title ) ? $page->post_title : '#' . $page->ID;
116 }
117 $setting['type'] = 'select';
118 $setting['options'] = $options;
119 }
120
121 $filtered_settings[] = $setting;
122 }
123
124 return $filtered_settings;
125 }
126
127 /**
128 * Returns a list of countries and states for use in the base location setting.
129 *
130 * @since 3.0.7
131 * @return array Array of states and countries.
132 */
133 private function get_countries_and_states() {
134 $countries = WC()->countries->get_countries();
135 if ( ! $countries ) {
136 return array();
137 }
138 $output = array();
139 foreach ( $countries as $key => $value ) {
140 $states = WC()->countries->get_states( $key );
141
142 if ( $states ) {
143 foreach ( $states as $state_key => $state_value ) {
144 $output[ $key . ':' . $state_key ] = $value . ' - ' . $state_value;
145 }
146 } else {
147 $output[ $key ] = $value;
148 }
149 }
150 return $output;
151 }
152
153 /**
154 * Get the settings schema, conforming to JSON Schema.
155 *
156 * @return array
157 */
158 public function get_item_schema() {
159 $schema = array(
160 '$schema' => 'http://json-schema.org/draft-04/schema#',
161 'title' => 'setting',
162 'type' => 'object',
163 'properties' => array(
164 'id' => array(
165 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ),
166 'type' => 'string',
167 'arg_options' => array(
168 'sanitize_callback' => 'sanitize_title',
169 ),
170 'context' => array( 'view', 'edit' ),
171 'readonly' => true,
172 ),
173 'group_id' => array(
174 'description' => __( 'An identifier for the group this setting belongs to.', 'woocommerce' ),
175 'type' => 'string',
176 'arg_options' => array(
177 'sanitize_callback' => 'sanitize_title',
178 ),
179 'context' => array( 'view', 'edit' ),
180 'readonly' => true,
181 ),
182 'label' => array(
183 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
184 'type' => 'string',
185 'arg_options' => array(
186 'sanitize_callback' => 'sanitize_text_field',
187 ),
188 'context' => array( 'view', 'edit' ),
189 'readonly' => true,
190 ),
191 'description' => array(
192 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ),
193 'type' => 'string',
194 'arg_options' => array(
195 'sanitize_callback' => 'sanitize_text_field',
196 ),
197 'context' => array( 'view', 'edit' ),
198 'readonly' => true,
199 ),
200 'value' => array(
201 'description' => __( 'Setting value.', 'woocommerce' ),
202 'type' => 'mixed',
203 'context' => array( 'view', 'edit' ),
204 ),
205 'default' => array(
206 'description' => __( 'Default value for the setting.', 'woocommerce' ),
207 'type' => 'mixed',
208 'context' => array( 'view', 'edit' ),
209 'readonly' => true,
210 ),
211 'tip' => array(
212 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ),
213 'type' => 'string',
214 'arg_options' => array(
215 'sanitize_callback' => 'sanitize_text_field',
216 ),
217 'context' => array( 'view', 'edit' ),
218 'readonly' => true,
219 ),
220 'placeholder' => array(
221 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ),
222 'type' => 'string',
223 'arg_options' => array(
224 'sanitize_callback' => 'sanitize_text_field',
225 ),
226 'context' => array( 'view', 'edit' ),
227 'readonly' => true,
228 ),
229 'type' => array(
230 'description' => __( 'Type of setting.', 'woocommerce' ),
231 'type' => 'string',
232 'arg_options' => array(
233 'sanitize_callback' => 'sanitize_text_field',
234 ),
235 'context' => array( 'view', 'edit' ),
236 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ),
237 'readonly' => true,
238 ),
239 'options' => array(
240 'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ),
241 'type' => 'object',
242 'context' => array( 'view', 'edit' ),
243 'readonly' => true,
244 ),
245 ),
246 );
247
248 return $this->add_additional_fields_schema( $schema );
249 }
250 }
251