Skip to content

Commit 030ce40

Browse files
committed
Added toggle button for "Insights Only" SD-30643
1 parent 47c2987 commit 030ce40

5 files changed

Lines changed: 141 additions & 3 deletions

File tree

admin/common/settings-common.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,24 @@ function setupSearch(searchInputId, listSelector) {
170170

171171
<div class="pp-home-section pp-margin-bottom">
172172
<h3 class="pp-section-heading"><i class="emoji-star icon-pilot-icon"></i> Interface Settings</h3>
173+
174+
<div class="pp-home-stat pp-stat-card" style="margin-bottom: 20px;">
175+
<div class="pp-home-stat-label">Insights Only</div>
176+
<div style="margin:20px 0;">
177+
<label class="pp-toggle-switch" style="display:flex;align-items:center;gap:15px;cursor:pointer;">
178+
<input type="hidden" name="path_pilot_insights_only" value="0" />
179+
<input type="checkbox" name="path_pilot_insights_only" id="path_pilot_insights_only" value="1" <?php checked(get_option('path_pilot_insights_only', false)); ?> style="display:none;" />
180+
<div class="pp-toggle-track" style="position:relative;width:50px;height:24px;background:#e0e0e0;border-radius:12px;transition:background-color 0.3s ease;">
181+
<div class="pp-toggle-handle" style="position:absolute;top:2px;left:2px;width:20px;height:20px;background:#fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,0.2);transition:transform 0.3s ease;"></div>
182+
</div>
183+
<span style="font-weight:500;">Hide drawer and collect data only</span>
184+
</label>
185+
</div>
186+
<div class="pp-stat-description">
187+
When enabled, Path Pilot collects visitor data and analytics in the background without showing any UI to visitors. When disabled, visitors will see the recommendations drawer.
188+
</div>
189+
</div>
190+
173191
<div class="pp-home-stat pp-stat-card">
174192
<div class="pp-home-stat-label">Minimum Path Hops</div>
175193
<div style="margin:20px 0;">
@@ -181,3 +199,41 @@ function setupSearch(searchInputId, listSelector) {
181199
</div>
182200
</div>
183201
</div>
202+
203+
<script>
204+
document.addEventListener('DOMContentLoaded', function() {
205+
// Toggle switch functionality
206+
function setupToggleSwitch() {
207+
var toggle = document.getElementById('path_pilot_insights_only');
208+
var track = document.querySelector('.pp-toggle-track');
209+
var handle = document.querySelector('.pp-toggle-handle');
210+
211+
if (!toggle || !track || !handle) return;
212+
213+
function updateToggleState() {
214+
if (toggle.checked) {
215+
track.style.backgroundColor = '#1976d2';
216+
handle.style.transform = 'translateX(26px)';
217+
} else {
218+
track.style.backgroundColor = '#e0e0e0';
219+
handle.style.transform = 'translateX(0)';
220+
}
221+
}
222+
223+
// Initialize state
224+
updateToggleState();
225+
226+
// Add click handler
227+
track.addEventListener('click', function(e) {
228+
e.preventDefault();
229+
toggle.checked = !toggle.checked;
230+
updateToggleState();
231+
});
232+
233+
// Add change handler for form submission
234+
toggle.addEventListener('change', updateToggleState);
235+
}
236+
237+
setupToggleSwitch();
238+
});
239+
</script>

admin/free/settings-free.php

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,75 @@
44
// Free settings page
55
?>
66
<div class="pp-content">
7+
<?php if (isset($_GET['updated']) && $_GET['updated'] === 'true'): ?>
8+
<div class="notice notice-success is-dismissible" style="margin: 20px 0; padding: 12px 20px; background: #d4edda; border: 1px solid #c3e6cb; border-radius: 4px; color: #155724;">
9+
<strong>Settings saved successfully!</strong> Your Path Pilot configuration has been updated.
10+
</div>
11+
<?php endif; ?>
12+
713
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" id="path-pilot-settings-form">
814
<input type="hidden" name="action" value="path_pilot_save_settings">
915
<?php wp_nonce_field('path_pilot_save_settings'); ?>
1016
<?php include plugin_dir_path(__DIR__) . 'common/settings-common.php'; ?>
1117
<?php
1218
do_action('path_pilot_additional_settings');
1319
?>
14-
<button type="submit" class="btn btn-primary" style="padding:12px 24px;font-weight:600;font-size:1rem;">Save Settings</button>
20+
<button type="submit" class="btn btn-primary" id="save-settings-btn" style="padding:12px 24px;font-weight:600;font-size:1rem;">Save Settings</button>
1521
</form>
22+
23+
<!-- Loading overlay -->
24+
<div id="pp-loading-overlay" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:9999;justify-content:center;align-items:center;">
25+
<div style="background:#fff;padding:30px;border-radius:8px;text-align:center;box-shadow:0 4px 20px rgba(0,0,0,0.3);">
26+
<div style="width:40px;height:40px;border:4px solid #f3f3f3;border-top:4px solid #1976d2;border-radius:50%;animation:spin 1s linear infinite;margin:0 auto 15px;"></div>
27+
<div style="font-size:16px;font-weight:600;color:#333;">Saving Settings...</div>
28+
</div>
29+
</div>
30+
31+
<style>
32+
@keyframes spin {
33+
0% { transform: rotate(0deg); }
34+
100% { transform: rotate(360deg); }
35+
}
36+
</style>
37+
38+
<script>
39+
document.addEventListener('DOMContentLoaded', function() {
40+
var form = document.getElementById('path-pilot-settings-form');
41+
var saveBtn = document.getElementById('save-settings-btn');
42+
var overlay = document.getElementById('pp-loading-overlay');
43+
44+
if (form && saveBtn && overlay) {
45+
form.addEventListener('submit', function(e) {
46+
// Show loading overlay
47+
overlay.style.display = 'flex';
48+
49+
// Disable save button to prevent double submission
50+
saveBtn.disabled = true;
51+
saveBtn.textContent = 'Saving...';
52+
53+
// Hide overlay after 30 seconds as fallback (in case redirect doesn't work)
54+
setTimeout(function() {
55+
overlay.style.display = 'none';
56+
saveBtn.disabled = false;
57+
saveBtn.textContent = 'Save Settings';
58+
59+
// Show error message
60+
var errorDiv = document.createElement('div');
61+
errorDiv.style.cssText = 'margin: 20px 0; padding: 12px 20px; background: #f8d7da; border: 1px solid #f5c6cb; border-radius: 4px; color: #721c24;';
62+
errorDiv.innerHTML = '<strong>Request timed out.</strong> The settings may not have been saved. Please try again.';
63+
64+
// Insert error message before the form
65+
form.parentNode.insertBefore(errorDiv, form);
66+
67+
// Remove error message after 10 seconds
68+
setTimeout(function() {
69+
if (errorDiv.parentNode) {
70+
errorDiv.parentNode.removeChild(errorDiv);
71+
}
72+
}, 10000);
73+
}, 30000);
74+
});
75+
}
76+
});
77+
</script>
1678
</div>

includes/common/class-path-pilot-admin.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,12 @@ public function save_settings() {
590590
$min_hops = isset($_POST['path_pilot_min_hops']) ? max(1, min(10, intval($_POST['path_pilot_min_hops']))) : 3;
591591
update_option('path_pilot_min_hops', $min_hops);
592592

593+
// Handle the toggle switch - we get "1" when checked, nothing when unchecked
594+
$insights_only = isset($_POST['path_pilot_insights_only']) && $_POST['path_pilot_insights_only'] === '1';
595+
596+
// Save insights_only directly (true = hide drawer, false = show drawer)
597+
update_option('path_pilot_insights_only', $insights_only);
598+
593599
// Save allowed content types with validation
594600
$submitted_content_types = isset($_POST['path_pilot_allowed_content_types']) && is_array($_POST['path_pilot_allowed_content_types'])
595601
? array_map('sanitize_text_field', $_POST['path_pilot_allowed_content_types'])

includes/common/class-path-pilot-shared.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ public static function enqueue_scripts() {
451451
$chat_enabled = apply_filters('path_pilot_chat_enabled', false);
452452
$dev_mode = (bool) get_option('path_pilot_dev_mode', false);
453453
$ready = $dev_mode ? true : (bool) get_option('path_pilot_ready', false);
454+
$insights_only = (bool) get_option('path_pilot_insights_only', false); // Default to false (show drawer)
455+
$show_drawer = !$insights_only; // Show drawer when NOT insights only
454456
$cta_text = get_option('path_pilot_cta_text', 'Need a hand?');
455457
$recommend_label = get_option('path_pilot_recommend_label', 'Recommended for you:');
456458
$chat_label = get_option('path_pilot_chat_label', 'Path Pilot');
@@ -507,8 +509,9 @@ public static function enqueue_scripts() {
507509
);
508510
Log::info('Path Pilot: wp_localize_script result = ' . ($localize_result ? 'success' : 'failed'));
509511

510-
// Always enqueue UI/interactivity - widget should always be available
511-
// Only the chat feature is gated behind Pro license, not the widget itself
512+
// Conditionally enqueue UI/interactivity based on show_drawer setting
513+
// If drawer is disabled, we skip the UI but keep tracking active
514+
if ($show_drawer) {
512515
Log::info('Path Pilot: Enqueuing index.js script...');
513516
$script_url = plugins_url('scripts/index.js', $main_plugin_file);
514517
Log::info('Path Pilot: Script URL = ' . $script_url);
@@ -527,6 +530,8 @@ public static function enqueue_scripts() {
527530
[
528531
'ready' => $ready,
529532
'dev_mode' => $dev_mode,
533+
'insights_only' => $insights_only,
534+
'show_drawer' => $show_drawer,
530535
'cta_text' => $cta_text,
531536
'recommend_label' => $recommend_label,
532537
'chat_label' => $chat_label,
@@ -536,6 +541,9 @@ public static function enqueue_scripts() {
536541
'icon_css_url' => plugins_url('assets/css/path-pilot-icons.css', $main_plugin_file),
537542
]
538543
);
544+
} else {
545+
Log::info('Path Pilot: Drawer disabled - skipping UI scripts but keeping tracking active');
546+
}
539547
}
540548

541549
// Get most common page 2 hops before goal page (for basic recommendations)

scripts/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
function initPathPilot() {
1010

11+
// --- Check if drawer should be shown ---
12+
if (window.PathPilotStatus && window.PathPilotStatus.insights_only === true) {
13+
console.log('Path Pilot: Insights only mode enabled - skipping drawer initialization');
14+
return; // Exit early if insights only mode is enabled
15+
}
16+
1117
// --- Inject icon font CSS if not present ---
1218
if (!document.querySelector('link[href*="path-pilot-icons.css"]')) {
1319
var iconFontLink = document.createElement('link');

0 commit comments

Comments
 (0)