Skip to content
This repository was archived by the owner on Oct 4, 2019. It is now read-only.

Commit 5ed0c56

Browse files
author
Justin Shreve
authored
Apply the patch from woocommerce/woocommerce#15817 (#22)
1 parent 0e70f3b commit 5ed0c56

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

api/class-wc-rest-dev-setting-options-controller.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,51 @@ public function allowed_setting_keys( $key ) {
115115
) );
116116
}
117117

118+
/**
119+
* Get all settings in a group.
120+
*
121+
* @param string $group_id Group ID.
122+
* @return array|WP_Error
123+
*/
124+
public function get_group_settings( $group_id ) {
125+
if ( empty( $group_id ) ) {
126+
return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
127+
}
128+
129+
$settings = apply_filters( 'woocommerce_settings-' . $group_id, array() );
130+
131+
if ( empty( $settings ) ) {
132+
return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
133+
}
134+
135+
$filtered_settings = array();
136+
foreach ( $settings as $setting ) {
137+
$option_key = $setting['option_key'];
138+
$setting = $this->filter_setting( $setting );
139+
$default = isset( $setting['default'] ) ? $setting['default'] : '';
140+
// Get the option value
141+
if ( is_array( $option_key ) ) {
142+
$option = get_option( $option_key[0] );
143+
$setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default;
144+
} else {
145+
$admin_setting_value = WC_Admin_Settings::get_option( $option_key, $default );
146+
$setting['value'] = $admin_setting_value;
147+
}
148+
149+
if ( 'multi_select_countries' === $setting['type'] ) {
150+
$setting['options'] = WC()->countries->get_countries();
151+
$setting['type'] = 'multiselect';
152+
} elseif ( 'single_select_country' === $setting['type'] ) {
153+
$setting['type'] = 'select';
154+
$setting['options'] = $this->get_countries_and_states();
155+
}
156+
157+
$filtered_settings[] = $setting;
158+
}
159+
160+
return $filtered_settings;
161+
}
162+
118163
/**
119164
* Get the settings schema, conforming to JSON Schema.
120165
*

0 commit comments

Comments
 (0)