Skip to content

Commit a6a073f

Browse files
Kiril KirkovKiril Kirkov
authored andcommitted
hot fixes
1 parent b78732d commit a6a073f

4 files changed

Lines changed: 18 additions & 63 deletions

File tree

Includes/Admin/Classes/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Config
2525
'spotify_search_limit',
2626
'spotify_search_default_styles',
2727
'spotify_search_styles',
28-
'absolute_positioned_results',
28+
'spotify_search_absolute_results',
2929
'spotify_search_show_on_tunedex',
3030
'spotify_search_url_params'
3131
],

Includes/Admin/SettingsForm.php

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -141,35 +141,10 @@
141141

142142
<div class="mb-4">
143143
<label>
144-
<input type="hidden" name="<?php esc_attr_e($Config::INPUTS_PREFIX); ?>absolute_positioned_results" value="0">
145-
<input type="checkbox" class="absolute_positioned_results" name="<?php esc_attr_e($Config::INPUTS_PREFIX); ?>absolute_positioned_results" value="1" <?php
146-
$option_value = get_option($Config::INPUTS_PREFIX.'absolute_positioned_results');
147-
// Backward compatibility: check old option name too
148-
$old_option = get_option($Config::INPUTS_PREFIX.'spotify_search_absolute_results');
149-
150-
// Determine if checkbox should be checked
151-
// Explicitly check the stored value
152-
$is_checked = false;
153-
154-
// Check new option first
155-
if ($option_value !== false) {
156-
// Option exists - check its value
157-
// WordPress may return "0" as string, 0 as int, or false
158-
// We explicitly check for "1" or 1, everything else is unchecked
159-
$is_checked = ($option_value === '1' || $option_value === 1);
160-
}
161-
// If new option doesn't exist, check old option for backward compatibility
162-
elseif ($old_option !== false) {
163-
$is_checked = ($old_option === '1' || $old_option === 1);
164-
}
165-
// Neither option exists - default to checked (new installation)
166-
else {
167-
$is_checked = true;
168-
}
169-
170-
if ($is_checked) {
171-
echo 'checked';
172-
}
144+
<input type="hidden" name="<?php esc_attr_e($Config::INPUTS_PREFIX); ?>spotify_search_absolute_results" value="0">
145+
<input type="checkbox" class="spotify_search_absolute_results" name="<?php esc_attr_e($Config::INPUTS_PREFIX); ?>spotify_search_absolute_results" value="1" <?php
146+
$option_value = get_option($Config::INPUTS_PREFIX.'spotify_search_absolute_results');
147+
echo $option_value === '1' ? 'checked' : '';
173148
?> />
174149
<?php esc_html_e( 'Absolute positioned results', 'kirilkirkov-spotify-search' ); ?>
175150
</label>

Includes/Public/PublicSearchForm.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,8 @@
2020
</div>
2121

2222
<?php
23-
$absolute_results = get_option($Config::INPUTS_PREFIX.'absolute_positioned_results');
24-
// Backward compatibility: check old option name too
25-
if ($absolute_results === false) {
26-
$absolute_results = get_option($Config::INPUTS_PREFIX.'spotify_search_absolute_results');
27-
}
28-
// Default to enabled if option doesn't exist (new installation)
29-
// Only apply absolute positioning if explicitly set to "1" or not set at all (default)
30-
// If explicitly set to "0", do NOT apply absolute positioning
31-
if ($absolute_results === false || $absolute_results === '1') {
23+
$absolute_results = get_option($Config::INPUTS_PREFIX.'spotify_search_absolute_results');
24+
if ($absolute_results === '1') {
3225
?>
3326
<style>
3427
#kirilkirkov-spotify-search-container {

KirilKirkovSpotifySearch.php

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ private function init()
6262
add_action('wp_ajax_get_spotify_search_results', array($this, 'get_spotify_search_results') );
6363
add_action('wp_ajax_nopriv_get_spotify_search_results', array($this, 'get_spotify_search_results') );
6464

65+
register_activation_hook( __FILE__, array($this, 'plugin_activation') );
66+
6567
add_shortcode(Config::SHORTCODE, array($this, 'load_public_form'));
6668
}
6769

@@ -212,22 +214,7 @@ public function admin_init()
212214

213215
foreach(Config::get_groups_input_fieds() as $group => $inputs) {
214216
foreach($inputs as $input) {
215-
// Add sanitize callback for absolute_positioned_results to ensure "0" is saved correctly
216-
if ($input === 'absolute_positioned_results') {
217-
register_setting($group, Config::INPUTS_PREFIX.$input, array(
218-
'sanitize_callback' => function($value) {
219-
// Handle all possible values: "1", 1, "0", 0, false, null, empty string
220-
// Always return "0" or "1" as string
221-
if ($value === '1' || $value === 1 || $value === true) {
222-
return '1';
223-
}
224-
// Everything else (including "0", 0, false, null, empty) should be "0"
225-
return '0';
226-
}
227-
));
228-
} else {
229-
register_setting($group, Config::INPUTS_PREFIX.$input);
230-
}
217+
register_setting($group, Config::INPUTS_PREFIX.$input);
231218
}
232219
}
233220
}
@@ -301,15 +288,15 @@ private function strip_param_from_url($url, $param)
301288
$new_query = http_build_query($parameters); // Rebuilt query string
302289
return $base_url.'?'.$new_query; // Finally url is ready
303290
}
291+
292+
public function plugin_activation()
293+
{
294+
// Only set default if option doesn't exist (new installation)
295+
if (get_option(Config::INPUTS_PREFIX.'spotify_search_absolute_results') === false) {
296+
update_option(Config::INPUTS_PREFIX.'spotify_search_absolute_results', '1');
297+
}
298+
}
304299
}
305300

306301
$spotify_search = KirilKirkovSpotifySearch::getInstance();
307-
308-
// Set default value for absolute_positioned_results on plugin activation
309-
register_activation_hook(__FILE__, function() {
310-
// Only set default if option doesn't exist (new installation)
311-
if (get_option(Config::INPUTS_PREFIX.'absolute_positioned_results') === false) {
312-
update_option(Config::INPUTS_PREFIX.'absolute_positioned_results', '1');
313-
}
314-
});
315302
}

0 commit comments

Comments
 (0)