Skip to content

Conversation

@celticr
Copy link
Contributor

@celticr celticr commented Jan 12, 2026

Summary

  • Adds sophia_chat_get_chat_url() function to allow custom chat URLs
  • Configure via SOPHIA_CHAT_CUSTOM_URL constant in wp-config.php
  • Enforces HTTPS-only URLs for security
  • Falls back to default sophia.chat URL if not configured

Usage

Add to wp-config.php for self-hosted deployments:

define('SOPHIA_CHAT_CUSTOM_URL', 'https://your-instance.example.com/chat');

Test plan

  • Without constant defined - uses default sophia.chat URL
  • With valid HTTPS URL - uses custom URL
  • With HTTP URL - falls back to default (security)
  • With invalid URL - falls back to default
  • Run ./vendor/bin/phpunit - all tests pass (20 tests)

Closes #13

Adds support for custom chat service URL via wp-config.php constant.
Set SOPHIA_CHAT_CUSTOM_URL to override the default sophia.chat URL.

- Only accepts valid HTTPS URLs for security
- Falls back to default if constant not defined or invalid
- No UI exposure (wp-config.php only for advanced users)

Closes #13
Copy link
Contributor Author

@celticr celticr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: PR #35 - Make chat URL configurable for self-hosted deployments

Summary

Allows self-hosted deployments to configure custom chat URL via wp-config.php constant.

Issues Found

1. Removes SOPHIA_CHAT_URL constant - breaking change - High

The PR removes the SOPHIA_CHAT_URL constant (line 23) and replaces with a function. Any code relying on this constant will break.

Current code using constant:

  • sophia_chat.php:59: $chat_url = SOPHIA_CHAT_URL;

The PR updates line 59 but doesn't check for third-party code that might use the constant.

Suggested fix: Keep the constant for backwards compatibility:

// Add after sophia_chat_get_chat_url() definition
if (!defined('SOPHIA_CHAT_URL')) {
    define('SOPHIA_CHAT_URL', sophia_chat_get_chat_url());
}

2. Test only covers default case - Low

The added test only verifies the default URL. Should also test:

  • Custom URL with HTTPS (should work)
  • Custom URL with HTTP (should fallback)
  • Invalid URL (should fallback)

Analysis

Aspect Assessment
Correctness ✅ URL validation logic is correct
Security ✅ HTTPS enforcement is good
Backwards compat ⚠️ Removes constant without shim
Test coverage ⚠️ Minimal coverage

What's Good

  • HTTPS-only enforcement is a smart security measure
  • Clean function implementation
  • Good docblock

Tests

  • Added test passes but only covers default case
  • Would benefit from tests for custom URL scenarios

Recommendation: REQUEST CHANGES - Add backwards-compat constant

- Add backwards-compat SOPHIA_CHAT_URL constant
- Add tests for backwards compatibility
@celticr
Copy link
Contributor Author

celticr commented Jan 12, 2026

Addressed PR Feedback

What changed:

  • Added backwards-compat SOPHIA_CHAT_URL constant after function definition
  • Added test for backwards compatibility constant

Why:
Addresses high-severity feedback about breaking change for third-party code relying on SOPHIA_CHAT_URL constant.

How to test:

./vendor/bin/phpunit

Test results:

  • PHPUnit: 22 tests, 26 assertions - all passing

@celticr celticr merged commit 26f1a11 into main Jan 12, 2026
2 checks passed
@celticr celticr deleted the feature/configurable-url branch January 12, 2026 17:31
@celticr celticr mentioned this pull request Jan 12, 2026
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make chat URL configurable for self-hosted deployments

2 participants