diff --git a/repair-directory.php b/repair-directory.php index a40492a..2467759 100644 --- a/repair-directory.php +++ b/repair-directory.php @@ -37,12 +37,34 @@ function repair_directory_plugin_add_shortcode_cb($atts) } } - // Construct source, which needs to include the region. - $atts['src'] = esc_url($atts['src']) . '?rd_region=' . esc_attr($atts['rd_region']) . '&rd_parenturl=' . esc_attr($atts['rd_parenturl']); + // 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']); - // Construct HTML to return + 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. $html = "\n' . "\n"; $html .= '