/**
  * Validate attributes passed to the [gravityview] shortcode. Supports {get} Merge Tags values.
  *
  * Attributes passed to the shortcode are compared to registered attributes {@see GravityView_View_Data::get_default_args}
  * Only attributes that are defined will be allowed through.
  *
  * Then, {get} merge tags are replaced with their $_GET values, if passed
  *
  * Then, attributes are sanitized based on the type of setting (number, checkbox, select, radio, text)
  *
  * @since 1.15.1
  *
  * @see GravityView_View_Data::get_default_args Only attributes defined in get_default_args() are valid to be passed via the shortcode
  *
  * @param array $passed_atts Attribute pairs defined to render the View
  *
  * @return array Valid and sanitized attribute pairs
  */
 private function parse_and_sanitize_atts($passed_atts)
 {
     $defaults = GravityView_View_Data::get_default_args(true);
     $supported_atts = array_fill_keys(array_keys($defaults), '');
     // Whittle down the attributes to only valid pairs
     $filtered_atts = shortcode_atts($supported_atts, $passed_atts, 'gravityview');
     // Only keep the passed attributes after making sure that they're valid pairs
     $filtered_atts = function_exists('array_intersect_key') ? array_intersect_key($passed_atts, $filtered_atts) : $filtered_atts;
     $atts = array();
     foreach ($filtered_atts as $key => $passed_value) {
         // Allow using {get} merge tags in shortcode attributes
         $passed_value = GravityView_Merge_Tags::replace_get_variables($passed_value);
         switch ($defaults[$key]['type']) {
             /**
              * Make sure number fields are numeric.
              * Also, convert mixed number strings to numbers
              * @see http://php.net/manual/en/function.is-numeric.php#107326
              */
             case 'number':
                 if (is_numeric($passed_value)) {
                     $atts[$key] = $passed_value + 0;
                 }
                 break;
                 // Checkboxes should be 1 or 0
             // Checkboxes should be 1 or 0
             case 'checkbox':
                 $atts[$key] = gv_empty($passed_value) ? 0 : 1;
                 break;
                 /**
                  * Only allow values that are defined in the settings
                  */
             /**
              * Only allow values that are defined in the settings
              */
             case 'select':
             case 'radio':
                 $options = isset($defaults[$key]['choices']) ? $defaults[$key]['choices'] : $defaults[$key]['options'];
                 if (in_array($passed_value, array_keys($options))) {
                     $atts[$key] = $passed_value;
                 }
                 break;
             case 'text':
             default:
                 $atts[$key] = $passed_value;
                 break;
         }
     }
     return $atts;
 }