Skip to content

Commit

Permalink
change deprecated way of string interpolation (#1609)
Browse files Browse the repository at this point in the history
"${var}" is deprecated with php 8.2. Future options are "{$var}" or the good old "$var". With simple variables, the good old variant is easier to read IMHO.
  • Loading branch information
nelarsen authored Jul 2, 2024
1 parent dc1514d commit 551c0f5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Map/SearchShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ protected function create_container( $cb_map_id, $attrs, $options, $content ) {
$data_loader = trim("
const config = CommonsSearch.parseLegacyConfig(" . wp_json_encode($settings) . ");
const api = CommonsSearch.createAdminAjaxAPI({
url: ${admin_ajax_url},
nonce: ${nonce},
mapId: ${cb_map_id},
url: $admin_ajax_url,
nonce: $nonce,
mapId: $cb_map_id,
}, config);
if (!window.__CB_SEARCH_DATA) window.__CB_SEARCH_DATA = {};
window.__CB_SEARCH_DATA[${cb_map_id}] = { config, api };
window.__CB_SEARCH_DATA[$cb_map_id] = { config, api };
");
$this->processed_map_ids[] = $cb_map_id;
} else {
$data_loader = "const { config, api } = window.__CB_SEARCH_DATA[${cb_map_id}];";
$data_loader = "const { config, api } = window.__CB_SEARCH_DATA[$cb_map_id];";
}

$content = trim(strip_tags($content));
$content_is_config = $content && is_object(json_decode($content)) && json_last_error() == JSON_ERROR_NONE;
if ($content_is_config) {
$user_config = "const userConfig = ${content};";
$user_config = "const userConfig = $content;";
} else {
$user_config = "const userConfig = {};";
}
Expand All @@ -52,9 +52,9 @@ protected function create_container( $cb_map_id, $attrs, $options, $content ) {

$init_script = "(function (el) {
document.addEventListener('DOMContentLoaded', function() {
${data_loader}
${user_config}
CommonsSearch.init(el, api, CommonsSearch.mergeConfigs(config, { layout: ${layout_config}, ...userConfig }));
$data_loader
$user_config
CommonsSearch.init(el, api, CommonsSearch.mergeConfigs(config, { layout: $layout_config, ...userConfig }));
});
})(document.currentScript.parentElement)";

Expand Down

0 comments on commit 551c0f5

Please sign in to comment.