@@ -5190,9 +5190,8 @@ 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 );
51965195
51975196            $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
51985197                $this->_plugin :
@@ -5344,70 +5343,65 @@ private function parse_settings( &$plugin_info ) {
53445343         */
53455344        protected function validate_checkout_config($config)
53465345        {
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)
5346+             $schema = array(
5347+                 // currency
5348+                 'currency'                      => 'string',
5349+                 'default_currency'              => 'string',
5350+                 // cart
5351+                 'always_show_renewals_amount'   => 'bool',
5352+                 'annual_discount'               => 'bool',
5353+                 'billing_cycle'                 => ['string', 'int'],
5354+                 'bundle_discount'               => 'float',
5355+                 'maximize_discounts'            => 'bool',
5356+                 'multisite_discount'            => ['bool', 'string'], // string expected to be "auto"
5357+                 'show_inline_currency_selector' => 'bool',
5358+                 'show_monthly'                  => 'bool',
5359+                 // appearance
5360+                 'form_position'                 => 'string',
5361+                 'is_bundle_collapsed'           => 'bool',
5362+                 'layout'                        => 'string',
5363+                 'refund_policy_position'        => 'string',
5364+                 'show_refund_badge'             => 'bool',
5365+                 'show_reviews'                  => 'bool',
5366+                 'show_upsells'                  => 'bool',
5367+                 'title'                         => 'string',
5368+             );
5369+ 
5370+             $result = array();
5371+ 
5372+             foreach ($schema as $key => $expected_type)
53735373            {
5374-                 if (isset($config[$section]) && is_array( $config[$section] ))
5374+                 if (array_key_exists($key,  $config))
53755375                {
5376-                     foreach ($fields as $key => $expected_type)
5376+                     $value = $config[$key];
5377+                     $types = is_array($expected_type) ? $expected_type : [$expected_type];
5378+                     $valid = false;
5379+ 
5380+                     foreach ($types as $type)
53775381                    {
5378-                         if (array_key_exists($key, $config[$section]) )
5382+                         switch ($type )
53795383                        {
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;
5384+                             case 'bool':
5385+                                 if (is_bool($value))
5386+                                     $valid = true;
5387+                                 break;
5388+                             case 'string':
5389+                                 if (is_string($value))
5390+                                     $valid = true;
5391+                                 break;
5392+                             case 'int':
5393+                                 if (is_int($value))
5394+                                     $valid = true;
5395+                                 break;
5396+                             case 'float':
5397+                                 if (is_float($value) || is_int($value))
5398+                                     $valid = true;
5399+                                 break;
54095400                        }
54105401                    }
5402+ 
5403+                     if ($valid)
5404+                         $result[$key] = $value;
54115405                }
54125406            }
54135407
0 commit comments