diff --git a/repair-directory.php b/repair-directory.php index d24901f..2467759 100644 --- a/repair-directory.php +++ b/repair-directory.php @@ -21,7 +21,8 @@ function repair_directory_plugin_add_shortcode_cb($atts) // Set defaults. $defaults = [ 'src' => 'https://map.restarters.net/', - 'region' => 'London', + 'rd_parenturl' => 'https://map.restarters.net', + 'rd_region' => 'London', 'width' => '100%', 'height' => '600', 'scrolling' => 'no', @@ -36,11 +37,34 @@ function repair_directory_plugin_add_shortcode_cb($atts) } } - // Construct source, which needs to include the region. - $atts['src'] = esc_url($atts['src']) . '?region=' . esc_attr($atts['region']); - unset($atts['region']); + // Construct source URL, which needs to include the region and parent from the attributes on this shortcode. + // It also needs to include any URL parameters starting with rd_ - this allows sharing of results. + // + // The standard WordPress way to do this is using get_query_var, but that requires us to know in advance which query + // variables the Repair Directory will use, and we don't want to introduce that dependency. + $params = [ + 'rd_region' => esc_attr($atts['rd_region']), + 'rd_parenturl' => esc_attr($atts['rd_parenturl']) + ]; + + unset($atts['rd_region']); + unset($atts['rd_parenturl']); + + foreach ($_GET as $var => $value) { + if (strpos($var, 'rd_') === 0) { + $params[esc_attr($var)] = esc_attr($value); + } + } + + $url = esc_url($atts['src']) . '?'; + + foreach ($params as $var => $value) { + $url .= "&$var=$value"; + } + + $atts['src'] = $url; - // Construct HTML to return + // Construct HTML to return. $html = "\n' . "\n"; $html .= '