@@ -36,11 +36,6 @@ public function add_admin_menu() {
3636 public function register_settings () {
3737 register_setting ('frak_settings ' , 'frak_app_name ' );
3838 register_setting ('frak_settings ' , 'frak_logo_url ' );
39- register_setting ('frak_settings ' , 'frak_custom_config ' , array (
40- 'sanitize_callback ' => function ($ input ) {
41- return stripslashes ($ input );
42- }
43- ));
4439 register_setting ('frak_settings ' , 'frak_enable_purchase_tracking ' );
4540 register_setting ('frak_settings ' , 'frak_enable_floating_button ' );
4641 register_setting ('frak_settings ' , 'frak_show_reward ' );
@@ -178,7 +173,6 @@ private function save_settings() {
178173 }
179174 }
180175
181- $ custom_config = stripslashes ($ _POST ['frak_custom_config ' ]);
182176 $ enable_tracking = isset ($ _POST ['frak_enable_purchase_tracking ' ]) ? 1 : 0 ;
183177 $ enable_button = isset ($ _POST ['frak_enable_floating_button ' ]) ? 1 : 0 ;
184178 $ show_reward = isset ($ _POST ['frak_show_reward ' ]) ? 1 : 0 ;
@@ -189,14 +183,29 @@ private function save_settings() {
189183 // Handle modal i18n
190184 $ modal_i18n = isset ($ _POST ['frak_modal_i18n ' ]) ? $ _POST ['frak_modal_i18n ' ] : array ();
191185 if (is_array ($ modal_i18n )) {
186+ // Sanitize each value
187+ foreach ($ modal_i18n as $ key => $ value ) {
188+ // For text areas, preserve line breaks but sanitize content
189+ if (in_array ($ key , ['sharing.text ' , 'sdk.wallet.login.text_sharing ' , 'sdk.wallet.login.text_referred ' ])) {
190+ $ modal_i18n [$ key ] = sanitize_textarea_field ($ value );
191+ } else {
192+ $ modal_i18n [$ key ] = sanitize_text_field ($ value );
193+ }
194+ }
195+
196+ // Remove empty values
192197 $ modal_i18n = array_filter ($ modal_i18n , function ($ value ) {
193198 return $ value !== '' ;
194199 });
200+
201+ // Handle special case: if text_referred is set, also set it as text
202+ if (isset ($ modal_i18n ['sdk.wallet.login.text_referred ' ])) {
203+ $ modal_i18n ['sdk.wallet.login.text ' ] = $ modal_i18n ['sdk.wallet.login.text_referred ' ];
204+ }
195205 }
196206
197207 update_option ('frak_app_name ' , $ app_name );
198208 update_option ('frak_logo_url ' , $ logo_url );
199- update_option ('frak_custom_config ' , $ custom_config );
200209 update_option ('frak_enable_purchase_tracking ' , $ enable_tracking );
201210 update_option ('frak_enable_floating_button ' , $ enable_button );
202211 update_option ('frak_show_reward ' , $ show_reward );
@@ -205,21 +214,57 @@ private function save_settings() {
205214 update_option ('frak_modal_language ' , $ modal_language );
206215 update_option ('frak_modal_i18n ' , json_encode ($ modal_i18n ));
207216
208- // Update config last modified timestamp for cache busting
209- if (class_exists ('Frak_Config_Endpoint ' )) {
210- Frak_Config_Endpoint::update_last_modified ();
211- }
217+ // Clear any caches to ensure the new configuration is loaded
218+ $ this ->clear_caches ();
212219
213220 }
214221
222+ /**
223+ * Clear caches from popular caching plugins
224+ */
225+ private function clear_caches () {
226+ // WP Rocket
227+ if (function_exists ('rocket_clean_domain ' )) {
228+ rocket_clean_domain ();
229+ }
230+
231+ // W3 Total Cache
232+ if (function_exists ('w3tc_flush_all ' )) {
233+ w3tc_flush_all ();
234+ }
235+
236+ // WP Super Cache
237+ if (function_exists ('wp_cache_clear_cache ' )) {
238+ wp_cache_clear_cache ();
239+ }
240+
241+ // WP Fastest Cache
242+ if (class_exists ('WpFastestCache ' ) && method_exists ('WpFastestCache ' , 'deleteCache ' )) {
243+ $ wpfc = new WpFastestCache ();
244+ $ wpfc ->deleteCache (true );
245+ }
246+
247+ // LiteSpeed Cache
248+ if (class_exists ('LiteSpeed\Purge ' )) {
249+ LiteSpeed \Purge::purge_all ();
250+ }
251+
252+ // Autoptimize
253+ if (class_exists ('autoptimizeCache ' ) && method_exists ('autoptimizeCache ' , 'clearall ' )) {
254+ autoptimizeCache::clearall ();
255+ }
256+
257+ // Clear WordPress object cache
258+ wp_cache_flush ();
259+ }
260+
215261 private function render_settings_page () {
216262 // Get default values from WordPress site info
217263 $ default_app_name = get_bloginfo ('name ' );
218264 $ default_logo_url = $ this ->get_site_icon_url ();
219265
220266 $ app_name = get_option ('frak_app_name ' , $ default_app_name );
221267 $ logo_url = get_option ('frak_logo_url ' , $ default_logo_url );
222- $ custom_config = get_option ('frak_custom_config ' , '' );
223268 // Auto-enable WooCommerce tracking if WooCommerce is active and setting hasn't been configured yet
224269 $ enable_tracking_option = get_option ('frak_enable_purchase_tracking ' , null );
225270 if ($ enable_tracking_option === null && class_exists ('WooCommerce ' )) {
@@ -235,10 +280,6 @@ private function render_settings_page() {
235280 $ modal_language = get_option ('frak_modal_language ' , 'default ' );
236281 $ modal_i18n = json_decode (get_option ('frak_modal_i18n ' , '{} ' ), true );
237282
238- if (empty ($ custom_config )) {
239- $ custom_config = $ this ->get_default_config ($ app_name , $ logo_url );
240- }
241-
242283 include FRAK_PLUGIN_DIR . 'admin/views/settings-page.php ' ;
243284 }
244285
@@ -263,66 +304,6 @@ private function get_site_icon_url() {
263304 return '' ;
264305 }
265306
266- private function get_default_config ($ app_name , $ logo_url ) {
267- $ modal_language = get_option ('frak_modal_language ' , 'default ' );
268- $ floating_button_position = get_option ('frak_floating_button_position ' , 'right ' );
269- $ modal_i18n = get_option ('frak_modal_i18n ' , '{} ' );
270-
271- // Handle language setting
272- $ lang_code = $ modal_language === 'default ' ? 'undefined ' : "' {$ modal_language }' " ;
273-
274- return <<<JS
275- let logoUrl = ' {$ logo_url }';
276- const lang = {$ lang_code };
277-
278- let i18n = {};
279- try {
280- i18n = JSON.parse(' {$ modal_i18n }'.replace(
281- /&|<|>|'|"/g,
282- tag =>
283- ({
284- '&': '&',
285- '<': '<',
286- '>': '>',
287- ''': "'",
288- '"': '"'
289- }[tag] || tag)
290- )) || {};
291- } catch (error) {
292- console.error('Error parsing i18n customizations:', error);
293- }
294-
295- window.FrakSetup = {
296- config: {
297- walletUrl: 'https://wallet.frak.id',
298- metadata: {
299- name: ' {$ app_name }',
300- lang,
301- logoUrl
302- },
303- customizations: { i18n },
304- domain: window.location.host
305- },
306- modalConfig: {
307- login: {
308- allowSso: true,
309- ssoMetadata: {
310- logoUrl,
311- homepageLink: window.location.host
312- }
313- }
314- },
315- modalShareConfig: {
316- link: window.location.href
317- },
318- modalWalletConfig: {
319- metadata: {
320- position: ' {$ floating_button_position }'
321- }
322- },
323- };
324- JS ;
325- }
326307
327308 private function handle_logo_upload ($ file ) {
328309 // Check file type
0 commit comments