Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit bea29d8

Browse files
KONFeatureclaude
andcommitted
Remove live preview and generate JS configuration on backend
- Remove Advanced Configuration section from admin UI - Remove all live preview functionality from admin.js - Update config endpoint to generate complete HTML script tags - Include SDK loading and configuration in generated script - Remove duplicate order tracking (already handled by Frak_WooCommerce) - Clean up unused custom_config option handling - Update frontend to load complete script from endpoint The JS is now generated entirely on the backend, similar to the PrestaShop plugin implementation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 44709df commit bea29d8

6 files changed

Lines changed: 67 additions & 271 deletions

File tree

admin/class-frak-admin.php

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -196,7 +190,6 @@ private function save_settings() {
196190

197191
update_option('frak_app_name', $app_name);
198192
update_option('frak_logo_url', $logo_url);
199-
update_option('frak_custom_config', $custom_config);
200193
update_option('frak_enable_purchase_tracking', $enable_tracking);
201194
update_option('frak_enable_floating_button', $enable_button);
202195
update_option('frak_show_reward', $show_reward);
@@ -219,7 +212,6 @@ private function render_settings_page() {
219212

220213
$app_name = get_option('frak_app_name', $default_app_name);
221214
$logo_url = get_option('frak_logo_url', $default_logo_url);
222-
$custom_config = get_option('frak_custom_config', '');
223215
// Auto-enable WooCommerce tracking if WooCommerce is active and setting hasn't been configured yet
224216
$enable_tracking_option = get_option('frak_enable_purchase_tracking', null);
225217
if ($enable_tracking_option === null && class_exists('WooCommerce')) {
@@ -235,10 +227,6 @@ private function render_settings_page() {
235227
$modal_language = get_option('frak_modal_language', 'default');
236228
$modal_i18n = json_decode(get_option('frak_modal_i18n', '{}'), true);
237229

238-
if (empty($custom_config)) {
239-
$custom_config = $this->get_default_config($app_name, $logo_url);
240-
}
241-
242230
include FRAK_PLUGIN_DIR . 'admin/views/settings-page.php';
243231
}
244232

@@ -263,66 +251,6 @@ private function get_site_icon_url() {
263251
return '';
264252
}
265253

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-
/&amp;|&lt;|&gt;|&#39;|&quot;/g,
282-
tag =>
283-
({
284-
'&amp;': '&',
285-
'&lt;': '<',
286-
'&gt;': '>',
287-
'&#39;': "'",
288-
'&quot;': '"'
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-
}
326254

327255
private function handle_logo_upload($file) {
328256
// Check file type

admin/css/admin.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@
131131
color: #dc3232;
132132
}
133133

134-
/* Advanced configuration textarea */
135-
#frak_custom_config {
136-
background: #f0f0f1;
137-
border: 1px solid #8c8f94;
138-
}
139134

140135
/* Button spacing */
141136
.button + .button {

admin/js/admin.js

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,4 @@
11
jQuery(document).ready(function($) {
2-
var editor;
3-
4-
// Initialize code editor if available
5-
if (typeof wp.codeEditor !== 'undefined' && $('#frak_custom_config').length) {
6-
var editorSettings = wp.codeEditor.defaultSettings ? _.clone(wp.codeEditor.defaultSettings) : {};
7-
editorSettings.codemirror = _.extend({}, editorSettings.codemirror, {
8-
indentUnit: 4,
9-
tabSize: 4,
10-
mode: 'javascript',
11-
lineNumbers: true,
12-
matchBrackets: true,
13-
autoCloseBrackets: true,
14-
extraKeys: {"Ctrl-Space": "autocomplete"},
15-
theme: 'default'
16-
});
17-
editor = wp.codeEditor.initialize($('#frak_custom_config'), editorSettings);
18-
}
19-
20-
// Update config function
21-
function updateConfig() {
22-
if (!editor) return;
23-
24-
var appName = $('#frak_app_name').val();
25-
var logoUrl = $('#frak_logo_url').val();
26-
var position = $('#frak_floating_button_position').val();
27-
var modalLang = $('#frak_modal_language').val();
28-
var currentConfig = editor.codemirror.getValue();
29-
30-
// Collect i18n values
31-
var i18nValues = {};
32-
$('.frak-i18n-table input').each(function() {
33-
var $input = $(this);
34-
var key = $input.attr('name').replace('frak_modal_i18n[', '').replace(']', '');
35-
var value = $input.val();
36-
if (value) {
37-
i18nValues[key] = value;
38-
}
39-
});
40-
41-
// Update app name
42-
currentConfig = currentConfig.replace(
43-
/(metadata:\s*{\s*name:\s*")[^"]*(")/,
44-
'$1' + appName + '$2'
45-
);
46-
47-
// Update logo URL - both in let declaration and in objects
48-
currentConfig = currentConfig.replace(
49-
/(let logoUrl = ')[^']*(')/,
50-
'$1' + logoUrl + '$2'
51-
);
52-
53-
// Update language - handle both string and variable format
54-
if (modalLang === 'default') {
55-
// Replace with undefined (variable)
56-
currentConfig = currentConfig.replace(
57-
/(const lang = )[^;]+/,
58-
'$1undefined'
59-
);
60-
} else {
61-
// Replace with quoted string
62-
currentConfig = currentConfig.replace(
63-
/(const lang = )[^;]+/,
64-
"$1'" + modalLang + "'"
65-
);
66-
}
67-
68-
// Update i18n object
69-
var i18nJson = JSON.stringify(i18nValues, null, 0);
70-
// Find the i18n parsing section and update it
71-
var i18nMatch = currentConfig.match(/let i18n = {};\s*try {[\s\S]*?} catch/);
72-
if (i18nMatch) {
73-
// Replace the entire i18n section
74-
var newI18nSection = "let i18n = {};\ntry {\n i18n = JSON.parse('" +
75-
i18nJson.replace(/'/g, "\\'") +
76-
"'.replace(\n /&amp;|&lt;|&gt;|&#39;|&quot;/g,\n tag =>\n ({\n '&amp;': '&',\n '&lt;': '<',\n '&gt;': '>',\n '&#39;': \"'\",\n '&quot;': '"'\n }[tag] || tag)\n )) || {};\n} catch";
77-
currentConfig = currentConfig.replace(/let i18n = {};\s*try {[\s\S]*?} catch/, newI18nSection);
78-
}
79-
80-
// Update floating button position
81-
currentConfig = currentConfig.replace(
82-
/(modalWalletConfig:\s*{[\s\S]*?metadata:\s*{[\s\S]*?position:\s*")[^"]*(")/,
83-
'$1' + position + '$2'
84-
);
85-
86-
editor.codemirror.setValue(currentConfig);
87-
}
88-
892
// Toggle floating button settings
903
function toggleFloatingButtonSettings() {
914
var enabled = $('#frak_enable_floating_button').is(':checked');
@@ -140,14 +53,10 @@ jQuery(document).ready(function($) {
14053
});
14154

14255
// Bind events
143-
$('#frak_app_name, #frak_logo_url, #frak_floating_button_position, #frak_modal_language').on('input change', updateConfig);
14456
$('#frak_enable_floating_button').on('change', toggleFloatingButtonSettings);
14557
$('#frak_logo_file').on('change', handleLogoFileSelect);
14658
$('#frak_logo_url').on('input', handleLogoUrlChange);
14759

148-
// Bind i18n input events
149-
$('.frak-i18n-table input').on('input', updateConfig);
150-
15160
// Initialize toggles
15261
toggleFloatingButtonSettings();
15362

admin/views/settings-page.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,6 @@ class="regular-text"></td>
186186
</table>
187187
</div>
188188
</div>
189-
190-
<!-- Advanced Configuration Section -->
191-
<div class="frak-section">
192-
<h2>Advanced Configuration</h2>
193-
<p>Customize your Frak configuration below:</p>
194-
<textarea id="frak_custom_config" name="frak_custom_config"
195-
style="width: 100%; height: 400px; font-family: monospace;"
196-
><?php echo $custom_config; ?></textarea>
197-
</div>
198-
199189
<!-- Purchase Tracking Section -->
200190
<div class="frak-section">
201191
<h2>Purchase Tracking</h2>

0 commit comments

Comments
 (0)