Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions assets/js/sophia-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
return;
}

var fallbackUrl = button.getAttribute('data-fallback-url') || chatUrl;

function openChat() {
var popup = window.open(
chatUrl,
'SophiaChat',
'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',scrollbars=yes,resizable=yes'
);

// Fallback: if popup blocked, navigate directly
// Fallback: if popup blocked, navigate to fallback URL (or chat URL if not set)
if (!popup || popup.closed) {
window.location.href = chatUrl;
window.location.href = fallbackUrl;
}
}

Expand Down
19 changes: 19 additions & 0 deletions sophia-chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ function sophia_chat_add_widget() {

$chat_url = sophia_chat_get_chat_url();
$icon_url = sophia_chat_get_icon_url();
$fallback_url = get_option('sophia_chat_fallback_url', '');
?>
<!-- Sophia Chat Widget -->
<button id="sophia-chat-bubble"
data-chat-url="<?php echo esc_url($chat_url); ?>"
<?php if ($fallback_url) : ?>data-fallback-url="<?php echo esc_url($fallback_url); ?>"<?php endif; ?>
aria-label="<?php esc_attr_e('Chat with Sophia', 'sophia-chat'); ?>"
title="<?php esc_attr_e('Chat with Sophia', 'sophia-chat'); ?>">
</button>
Expand Down Expand Up @@ -286,6 +288,7 @@ function sophia_chat_register_settings() {
register_setting('sophia_chat_options', 'sophia_chat_visibility', 'sanitize_text_field');
register_setting('sophia_chat_options', 'sophia_chat_page_ids', 'sanitize_text_field');
register_setting('sophia_chat_options', 'sophia_chat_exclude_ids', 'sanitize_text_field');
register_setting('sophia_chat_options', 'sophia_chat_fallback_url', 'esc_url_raw');
}
add_action('admin_init', 'sophia_chat_register_settings');

Expand Down Expand Up @@ -400,6 +403,22 @@ class="regular-text"
</div>
</td>
</tr>

<!-- Fallback URL -->
<tr>
<th scope="row">
<label for="sophia_chat_fallback_url"><?php _e('Fallback Resources URL', 'sophia-chat'); ?></label>
</th>
<td>
<input type="url"
id="sophia_chat_fallback_url"
name="sophia_chat_fallback_url"
value="<?php echo esc_url(get_option('sophia_chat_fallback_url')); ?>"
class="regular-text"
placeholder="https://example.com/support-resources" />
<p class="description"><?php _e('Optional: URL to alternative support resources if the chat popup is blocked. Leave empty to redirect to the chat URL directly.', 'sophia-chat'); ?></p>
</td>
</tr>
</table>

<?php submit_button(); ?>
Expand Down
Loading