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

Commit b99d7f2

Browse files
committed
Merge branch 'main' into feat/webhook-setup-configuration
Resolved conflicts in settings-page.php by keeping JavaScript in separate admin.js file Integrated autofill functionality from main branch into admin.js
2 parents 0cfaa02 + d24d1ba commit b99d7f2

3 files changed

Lines changed: 80 additions & 4 deletions

File tree

admin/class-frak-admin.php

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,27 @@ public function enqueue_scripts($hook) {
5555

5656
wp_enqueue_code_editor(array('type' => 'text/javascript'));
5757
wp_enqueue_script('frak-admin', plugin_dir_url(dirname(__FILE__)) . 'admin/js/admin.js', array('jquery'), '1.0', true);
58+
59+
// Get logo URL for autofill
60+
$logo_url = '';
61+
$site_icon_id = get_option('site_icon');
62+
if ($site_icon_id) {
63+
$logo_url = wp_get_attachment_image_url($site_icon_id, 'full');
64+
}
65+
if (!$logo_url) {
66+
$custom_logo_id = get_theme_mod('custom_logo');
67+
if ($custom_logo_id) {
68+
$logo_url = wp_get_attachment_image_url($custom_logo_id, 'full');
69+
}
70+
}
71+
5872
wp_localize_script('frak-admin', 'frak_ajax', array(
5973
'ajax_url' => admin_url('admin-ajax.php'),
60-
'nonce' => wp_create_nonce('frak_ajax_nonce')
74+
'nonce' => wp_create_nonce('frak_ajax_nonce'),
75+
'site_info' => array(
76+
'name' => get_bloginfo('name'),
77+
'logo_url' => $logo_url
78+
)
6179
));
6280

6381
wp_add_inline_style('wp-admin', '
@@ -155,8 +173,12 @@ private function save_settings() {
155173
}
156174

157175
private function render_settings_page() {
158-
$app_name = get_option('frak_app_name', 'Your App Name');
159-
$logo_url = get_option('frak_logo_url', '');
176+
// Get default values from WordPress site info
177+
$default_app_name = get_bloginfo('name');
178+
$default_logo_url = $this->get_site_icon_url();
179+
180+
$app_name = get_option('frak_app_name', $default_app_name);
181+
$logo_url = get_option('frak_logo_url', $default_logo_url);
160182
$custom_config = get_option('frak_custom_config', '');
161183
$enable_tracking = get_option('frak_enable_purchase_tracking', 0);
162184
$enable_button = get_option('frak_enable_floating_button', 0);
@@ -170,6 +192,27 @@ private function render_settings_page() {
170192
include FRAK_PLUGIN_DIR . 'admin/views/settings-page.php';
171193
}
172194

195+
private function get_site_icon_url() {
196+
$site_icon_id = get_option('site_icon');
197+
if ($site_icon_id) {
198+
$site_icon_url = wp_get_attachment_image_url($site_icon_id, 'full');
199+
if ($site_icon_url) {
200+
return $site_icon_url;
201+
}
202+
}
203+
204+
// Fallback: try to get logo from theme customizer
205+
$custom_logo_id = get_theme_mod('custom_logo');
206+
if ($custom_logo_id) {
207+
$custom_logo_url = wp_get_attachment_image_url($custom_logo_id, 'full');
208+
if ($custom_logo_url) {
209+
return $custom_logo_url;
210+
}
211+
}
212+
213+
return '';
214+
}
215+
173216
private function get_default_config($app_name, $logo_url) {
174217
return <<<JS
175218
window.FrakSetup = {

admin/js/admin.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ jQuery(document).ready(function($) {
4444
$('#frak_show_reward, #frak_button_classname').prop('disabled', !enabled);
4545
}
4646

47+
// Autofill functionality
48+
$('#autofill_app_name').on('click', function() {
49+
if (frak_ajax.site_info.name) {
50+
$('#frak_app_name').val(frak_ajax.site_info.name).trigger('input');
51+
}
52+
});
53+
54+
$('#autofill_logo_url').on('click', function() {
55+
if (frak_ajax.site_info.logo_url) {
56+
$('#frak_logo_url').val(frak_ajax.site_info.logo_url).trigger('input');
57+
}
58+
});
59+
4760
// Bind events
4861
$('#frak_app_name, #frak_logo_url').on('input', updateConfig);
4962
$('#frak_enable_floating_button').on('change', toggleFloatingButtonSettings);

admin/views/settings-page.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
<td>
1616
<input type="text" id="frak_app_name" name="frak_app_name"
1717
value="<?php echo esc_attr($app_name); ?>" class="regular-text">
18+
<button type="button" id="autofill_app_name" class="button button-secondary" style="margin-left: 10px;">
19+
Use Site Name
20+
</button>
21+
<p class="description">Current site name: <strong><?php echo esc_html(get_bloginfo('name')); ?></strong></p>
1822
</td>
1923
</tr>
2024
<tr>
@@ -24,6 +28,23 @@
2428
<td>
2529
<input type="url" id="frak_logo_url" name="frak_logo_url"
2630
value="<?php echo esc_url($logo_url); ?>" class="regular-text">
31+
<button type="button" id="autofill_logo_url" class="button button-secondary" style="margin-left: 10px;">
32+
Use Site Icon
33+
</button>
34+
<?php
35+
$site_icon_id = get_option('site_icon');
36+
$custom_logo_id = get_theme_mod('custom_logo');
37+
if ($site_icon_id || $custom_logo_id): ?>
38+
<p class="description">
39+
<?php if ($site_icon_id): ?>
40+
Site icon available
41+
<?php elseif ($custom_logo_id): ?>
42+
Custom logo available
43+
<?php endif; ?>
44+
</p>
45+
<?php else: ?>
46+
<p class="description">No site icon or custom logo found. <a href="<?php echo admin_url('customize.php'); ?>" target="_blank">Set one in Customizer</a></p>
47+
<?php endif; ?>
2748
</td>
2849
</tr>
2950
<tr>
@@ -243,4 +264,3 @@ class="regular-text"
243264
<?php submit_button('Save Settings'); ?>
244265
</form>
245266
</div>
246-

0 commit comments

Comments
 (0)