Skip to content

Commit

Permalink
Pass other rd_ URL parameters into IFRAME
Browse files Browse the repository at this point in the history
  • Loading branch information
edwh committed Mar 1, 2021
1 parent 51f83d8 commit 354e9c1
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions repair-directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<!-- Repair Directory plugin v" . REPAIR_DIRECTORY_PLUGIN_VERSION . ' -->' . "\n";
$html .= '<IFRAME';

Expand Down

0 comments on commit 354e9c1

Please sign in to comment.