@@ -5190,9 +5190,9 @@ private function parse_settings( &$plugin_info ) {
51905190 ) );
51915191 }
51925192
5193- if ( isset( $plugin_info['checkout'] ) && is_array( $plugin_info[' checkout'] ) ) {
5194- $this->_checkout_config = $this->validate_checkout_config( $plugin_info['checkout'] );
5195- }
5193+ // Extracts, validate and save checkout-specific settings.
5194+ $this->_checkout_config = $this->validate_checkout_config( $plugin_info );
5195+ wp_die(serialize($this->_checkout_config));
51965196
51975197 $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
51985198 $this->_plugin :
@@ -5344,70 +5344,65 @@ private function parse_settings( &$plugin_info ) {
53445344 */
53455345 protected function validate_checkout_config($config)
53465346 {
5347- $schema = [
5348- 'cart' => [
5349- 'always_show_renewals_amount' => 'bool',
5350- 'annual_discount' => 'bool',
5351- 'billing_cycle' => ['string', 'int'],
5352- 'bundle_discount' => 'float',
5353- 'maximize_discounts' => 'bool',
5354- 'multisite_discount' => ['bool', 'string'], // string expected to be "auto"
5355- 'show_inline_currency_selector' => 'bool',
5356- 'show_monthly' => 'bool',
5357- ],
5358- 'appearance' => [
5359- 'form_position' => 'string',
5360- 'is_bundle_collapsed' => 'bool',
5361- 'layout' => 'string',
5362- 'refund_policy_position' => 'string',
5363- 'show_refund_badge' => 'bool',
5364- 'show_reviews' => 'bool',
5365- 'show_upsells' => 'bool',
5366- 'title' => 'string',
5367- ],
5368- ];
5369-
5370- $result = [];
5371-
5372- foreach ($schema as $section => $fields)
5347+ $schema = array(
5348+ // currency
5349+ 'currency' => 'string',
5350+ 'default_currency' => 'string',
5351+ // cart
5352+ 'always_show_renewals_amount' => 'bool',
5353+ 'annual_discount' => 'bool',
5354+ 'billing_cycle' => ['string', 'int'],
5355+ 'bundle_discount' => 'float',
5356+ 'maximize_discounts' => 'bool',
5357+ 'multisite_discount' => ['bool', 'string'], // string expected to be "auto"
5358+ 'show_inline_currency_selector' => 'bool',
5359+ 'show_monthly' => 'bool',
5360+ // appearance
5361+ 'form_position' => 'string',
5362+ 'is_bundle_collapsed' => 'bool',
5363+ 'layout' => 'string',
5364+ 'refund_policy_position' => 'string',
5365+ 'show_refund_badge' => 'bool',
5366+ 'show_reviews' => 'bool',
5367+ 'show_upsells' => 'bool',
5368+ 'title' => 'string',
5369+ );
5370+
5371+ $result = array();
5372+
5373+ foreach ($schema as $key => $expected_type)
53735374 {
5374- if (isset($config[$section]) && is_array( $config[$section] ))
5375+ if (array_key_exists($key, $config))
53755376 {
5376- foreach ($fields as $key => $expected_type)
5377+ $value = $config[$key];
5378+ $types = is_array($expected_type) ? $expected_type : [$expected_type];
5379+ $valid = false;
5380+
5381+ foreach ($types as $type)
53775382 {
5378- if (array_key_exists($key, $config[$section]) )
5383+ switch ($type )
53795384 {
5380- $value = $config[$section][$key];
5381- $types = is_array($expected_type) ? $expected_type : [$expected_type];
5382- $valid = false;
5383-
5384- foreach ($types as $type)
5385- {
5386- switch ($type)
5387- {
5388- case 'bool':
5389- if (is_bool($value))
5390- $valid = true;
5391- break;
5392- case 'string':
5393- if (is_string($value))
5394- $valid = true;
5395- break;
5396- case 'int':
5397- if (is_int($value))
5398- $valid = true;
5399- break;
5400- case 'float':
5401- if (is_float($value) || is_int($value))
5402- $valid = true;
5403- break;
5404- }
5405- }
5406-
5407- if ($valid)
5408- $result[$key] = $value;
5385+ case 'bool':
5386+ if (is_bool($value))
5387+ $valid = true;
5388+ break;
5389+ case 'string':
5390+ if (is_string($value))
5391+ $valid = true;
5392+ break;
5393+ case 'int':
5394+ if (is_int($value))
5395+ $valid = true;
5396+ break;
5397+ case 'float':
5398+ if (is_float($value) || is_int($value))
5399+ $valid = true;
5400+ break;
54095401 }
54105402 }
5403+
5404+ if ($valid)
5405+ $result[$key] = $value;
54115406 }
54125407 }
54135408
0 commit comments