diff --git a/readme.txt b/readme.txt index 6c3762e..96d4b3f 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: cache, caching, performance Requires at least: 4.7 Tested up to: 6.9 Requires PHP: 7.1 -Stable tag: 1.9.0 +Stable tag: 1.9.1 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -85,6 +85,9 @@ Create a new team account, invite a member of your team, and allow them to spin * Ensures debug.log files aren’t saved in a publicly-accessible location == Changelog == += 1.9.1 (2026-01-07) = +* Improvement: Add support for SpinupWP subdomains + = 1.9.0 (2025-10-01) = * Change: Use SPINUPWP_REDIS_* variables instead of SPINUPWP_CACHE_* * Change: No longer enabling WP_REDIS_SELECTIVE_FLUSH by default as it can result in timeouts when flushing the cache. Flushing the object cache will now flush it for all sites on a server. diff --git a/spinupwp.php b/spinupwp.php index 5802ecc..4b3193f 100644 --- a/spinupwp.php +++ b/spinupwp.php @@ -4,7 +4,7 @@ Plugin URI: https://spinupwp.com Description: SpinupWP helper plugin. Author: SpinupWP -Version: 1.9.0 +Version: 1.9.1 Network: True Text Domain: spinupwp Requires PHP: 7.1 diff --git a/src/MagicLogin.php b/src/MagicLogin.php index f9a8fe8..fe9b53e 100644 --- a/src/MagicLogin.php +++ b/src/MagicLogin.php @@ -111,6 +111,15 @@ protected function has_valid_signature( string $secret ) { $url = home_url() . "?{$query}"; $signature = hash_hmac( 'sha256', $url, $secret ); + $subdomain = getenv( 'SPINUPWP_SUBDOMAIN' ); + if ( $subdomain ) { + $subdomain_url = "https://{$subdomain}" . "?{$query}"; + $subdomain_signature = hash_hmac( 'sha256', $subdomain_url, $secret ); + if ( hash_equals( $subdomain_signature, $query_signature ) ) { + return true; + } + } + return hash_equals( $signature, $query_signature ); } diff --git a/src/Plugin.php b/src/Plugin.php index 8cadcf3..581d0fa 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -51,6 +51,7 @@ public function run() { ( new MagicLogin() )->init(); ( new SiteHealth() )->init(); + ( new SubdomainUrlRewriter() )->init(); } add_filter( 'spinupwp_should_use_object_cache_dropin', array( $this, 'should_use_object_cache_dropin' ) ); diff --git a/src/SubdomainUrlRewriter.php b/src/SubdomainUrlRewriter.php new file mode 100644 index 0000000..9567c30 --- /dev/null +++ b/src/SubdomainUrlRewriter.php @@ -0,0 +1,93 @@ +subdomain = getenv( 'SPINUPWP_SUBDOMAIN' ); + + if ( ! $this->subdomain || ! $this->is_subdomain_request() ) { + return; + } + + $this->site_url = home_url(); + $this->register_hooks(); + } + + /** + * Determine if the current request is via the subdomain. + * + * @return bool + */ + private function is_subdomain_request() { + return isset( $_SERVER['HTTP_HOST'] ) + && $_SERVER['HTTP_HOST'] === $this->subdomain; + } + + /** + * Register hooks to rewrite URLs before saving to the database. + * + * @return void + */ + private function register_hooks() { + add_filter( 'content_save_pre', array( $this, 'rewrite_urls' ) ); + add_filter( 'excerpt_save_pre', array( $this, 'rewrite_urls' ) ); + add_filter( 'pre_update_option', array( $this, 'rewrite_urls_recursive' ), 10, 1 ); + } + + /** + * Rewrite subdomain URLs to the configured site URL. + * + * @param string $content + * + * @return string + */ + public function rewrite_urls( $content ) { + if ( ! is_string( $content ) || empty( $content ) ) { + return $content; + } + + return str_replace( + array( 'https://' . $this->subdomain, 'http://' . $this->subdomain ), + $this->site_url, + $content + ); + } + + /** + * Recursively rewrite URLs in arrays and strings. + * + * @param mixed $data + * + * @return mixed + */ + public function rewrite_urls_recursive( $data ) { + if ( is_string( $data ) ) { + return $this->rewrite_urls( $data ); + } + + if ( is_array( $data ) ) { + foreach ( $data as $key => $value ) { + $data[ $key ] = $this->rewrite_urls_recursive( $value ); + } + } + + return $data; + } +}