@@ -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