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

Commit c8c3fa9

Browse files
committed
feat: add floating button configuration
1 parent c2d4fd3 commit c8c3fa9

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

frak-integration.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ function frak_register_settings() {
3434
}
3535
));
3636
register_setting('frak_settings', 'frak_enable_purchase_tracking');
37+
register_setting('frak_settings', 'frak_enable_floating_button');
38+
register_setting('frak_settings', 'frak_show_reward');
39+
register_setting('frak_settings', 'frak_button_classname');
3740
}
3841
add_action('admin_init', 'frak_register_settings');
3942

@@ -75,18 +78,27 @@ function frak_settings_page() {
7578
$logo_url = esc_url_raw($_POST['frak_logo_url']);
7679
$custom_config = stripslashes($_POST['frak_custom_config']);
7780
$enable_tracking = isset($_POST['frak_enable_purchase_tracking']) ? 1 : 0;
81+
$enable_button = isset($_POST['frak_enable_floating_button']) ? 1 : 0;
82+
$show_reward = isset($_POST['frak_show_reward']) ? 1 : 0;
83+
$button_classname = sanitize_text_field($_POST['frak_button_classname']);
7884

7985
// Save everything
8086
update_option('frak_app_name', $app_name);
8187
update_option('frak_logo_url', $logo_url);
8288
update_option('frak_custom_config', $custom_config);
8389
update_option('frak_enable_purchase_tracking', $enable_tracking);
90+
update_option('frak_enable_floating_button', $enable_button);
91+
update_option('frak_show_reward', $show_reward);
92+
update_option('frak_button_classname', $button_classname);
8493
}
8594

8695
$app_name = get_option('frak_app_name', 'Your App Name');
8796
$logo_url = get_option('frak_logo_url', '');
8897
$custom_config = get_option('frak_custom_config', '');
8998
$enable_tracking = get_option('frak_enable_purchase_tracking', 0);
99+
$enable_button = get_option('frak_enable_floating_button', 0);
100+
$show_reward = get_option('frak_show_reward', 0);
101+
$button_classname = get_option('frak_button_classname', '');
90102

91103
if (empty($custom_config)) {
92104
$custom_config = <<<JS
@@ -182,6 +194,56 @@ function frak_settings_page() {
182194
</tr>
183195
</table>
184196

197+
<h2>Floating Button Configuration</h2>
198+
<table class="form-table">
199+
<tr>
200+
<th scope="row">
201+
<label for="frak_enable_floating_button">Enable Floating Button</label>
202+
</th>
203+
<td>
204+
<label>
205+
<input type="checkbox" id="frak_enable_floating_button"
206+
name="frak_enable_floating_button" value="1"
207+
<?php checked($enable_button, 1); ?>>
208+
Show floating button on all pages
209+
</label>
210+
</td>
211+
</tr>
212+
<tr>
213+
<th scope="row">
214+
<label for="frak_show_reward">Show Potential Reward</label>
215+
</th>
216+
<td>
217+
<label>
218+
<input type="checkbox" id="frak_show_reward"
219+
name="frak_show_reward" value="1"
220+
<?php checked($show_reward, 1); ?>
221+
<?php echo $enable_button ? '' : 'disabled'; ?>>
222+
Display potential reward on the button
223+
</label>
224+
</td>
225+
</tr>
226+
<tr>
227+
<th scope="row">
228+
<label for="frak_button_classname">Custom Class Name</label>
229+
</th>
230+
<td>
231+
<input type="text" id="frak_button_classname"
232+
name="frak_button_classname"
233+
value="<?php echo esc_attr($button_classname); ?>"
234+
class="regular-text"
235+
<?php echo $enable_button ? '' : 'disabled'; ?>>
236+
<p class="description">Add custom CSS classes to the button</p>
237+
</td>
238+
</tr>
239+
<tr>
240+
<th scope="row">Button Position</th>
241+
<td>
242+
<p class="description">The button position is controlled by the <code>modalWalletConfig.metadata.position</code> setting in the advanced configuration above. It can be set to either "left" or "right".</p>
243+
</td>
244+
</tr>
245+
</table>
246+
185247
<h2>Advanced Configuration</h2>
186248
<p>Customize your Frak configuration below:</p>
187249
<textarea id="frak_custom_config" name="frak_custom_config"
@@ -225,7 +287,15 @@ function updateConfig() {
225287
editor.codemirror.setValue(currentConfig);
226288
}
227289

290+
// Handle floating button settings
291+
function toggleFloatingButtonSettings() {
292+
var enabled = $('#frak_enable_floating_button').is(':checked');
293+
$('#frak_show_reward, #frak_button_classname').prop('disabled', !enabled);
294+
}
295+
228296
$('#frak_app_name, #frak_logo_url').on('input', updateConfig);
297+
$('#frak_enable_floating_button').on('change', toggleFloatingButtonSettings);
298+
toggleFloatingButtonSettings(); // Initial state
229299
});
230300
</script>
231301
<?php
@@ -254,6 +324,31 @@ function frak_add_to_frontend() {
254324
}
255325
add_action('wp_head', 'frak_add_to_frontend');
256326

327+
// Add floating button to the body
328+
function frak_add_floating_button() {
329+
if (is_admin()) {
330+
return;
331+
}
332+
333+
if (!get_option('frak_enable_floating_button', 0)) {
334+
return;
335+
}
336+
337+
$show_reward = get_option('frak_show_reward', 0);
338+
$classname = get_option('frak_button_classname', '');
339+
340+
$attributes = array();
341+
if ($show_reward) {
342+
$attributes[] = 'use-reward';
343+
}
344+
if (!empty($classname)) {
345+
$attributes[] = 'classname="' . esc_attr($classname) . '"';
346+
}
347+
348+
echo '<frak-button-wallet ' . implode(' ', $attributes) . '></frak-button-wallet>';
349+
}
350+
add_action('wp_footer', 'frak_add_floating_button');
351+
257352
// Add WooCommerce purchase tracking
258353
function frak_add_purchase_tracking($order_id) {
259354
// Early exit if tracking is disabled

0 commit comments

Comments
 (0)