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>
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>
@@ -114,6 +135,25 @@ class="regular-text"
114135 }
115136 });
116137
138+ // WordPress site information for autofill
139+ var wpSiteInfo = {
140+ name: <?php echo json_encode (get_bloginfo ('name ' )); ?> ,
141+ logoUrl: <?php
142+ $ site_icon_id = get_option ('site_icon ' );
143+ $ logo_url = '' ;
144+ if ($ site_icon_id ) {
145+ $ logo_url = wp_get_attachment_image_url ($ site_icon_id , 'full ' );
146+ }
147+ if (!$ logo_url ) {
148+ $ custom_logo_id = get_theme_mod ('custom_logo ' );
149+ if ($ custom_logo_id ) {
150+ $ logo_url = wp_get_attachment_image_url ($ custom_logo_id , 'full ' );
151+ }
152+ }
153+ echo json_encode ($ logo_url ?: '' );
154+ ?>
155+ };
156+
117157 function updateConfig() {
118158 var appName = $('#frak_app_name').val();
119159 var logoUrl = $('#frak_logo_url').val();
@@ -137,6 +177,19 @@ function toggleFloatingButtonSettings() {
137177 $('#frak_show_reward, #frak_button_classname').prop('disabled', !enabled);
138178 }
139179
180+ // Autofill functionality
181+ $('#autofill_app_name').on('click', function() {
182+ if (wpSiteInfo.name) {
183+ $('#frak_app_name').val(wpSiteInfo.name).trigger('input');
184+ }
185+ });
186+
187+ $('#autofill_logo_url').on('click', function() {
188+ if (wpSiteInfo.logoUrl) {
189+ $('#frak_logo_url').val(wpSiteInfo.logoUrl).trigger('input');
190+ }
191+ });
192+
140193 $('#frak_app_name, #frak_logo_url').on('input', updateConfig);
141194 $('#frak_enable_floating_button').on('change', toggleFloatingButtonSettings);
142195 toggleFloatingButtonSettings();
0 commit comments