Skip to content
Draft
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
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion spinupwp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/MagicLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
1 change: 1 addition & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand Down
93 changes: 93 additions & 0 deletions src/SubdomainUrlRewriter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace SpinupWp;

class SubdomainUrlRewriter {

/**
* @var string
*/
private $subdomain;

/**
* @var string
*/
private $site_url;

/**
* Init
*
* @return void
*/
public function init() {
$this->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;
}
}