Compare commits

..
Author SHA1 Message Date
shadowdaoandClaude Sonnet 5.5 96bae1cbf9 Keep overlays and live responses out of LiteSpeed Cache
Test and Release / test (push) Successful in 3m47s
Test and Release / release (push) Successful in 13s
LiteSpeed Cache held overlay poll responses for 7 days, so OBS kept getting
304s and neither the goal bar nor alerts updated after a donation. The overlay
data, overlay pages and fee preview now opt out, as the progress route did.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-27 21:07:57 -08:00
shadowdaoandClaude Sonnet 5.5 0180aacd72 Progress route: opt out of LiteSpeed cache via its hook
Test and Release / test (push) Successful in 2m26s
Test and Release / release (push) Successful in 15s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXhhC8xipsBR7e3o76i
2026-11-16 08:37:10 -08:00
shadowdaoandClaude Sonnet 5.5 c6520b761a Progress bar: update right after a donation (LiteSpeed no-cache, more refreshes, visible fill for small amounts)
Test and Release / test (push) Successful in 1m19s
Test and Release / release (push) Successful in 8s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXhhC8xipsBR7e3o76i
2026-11-16 08:34:59 -08:00
shadowdaoandClaude Sonnet 5.5 55d1c34b1f Donate form: remove the form after a successful donation until page reload
Test and Release / test (push) Successful in 1m27s
Test and Release / release (push) Successful in 6s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXhhC8xipsBR7e3o76i
2026-11-16 08:25:05 -08:00
shadowdaoandClaude Sonnet 5.5 565ee0a352 Donate form: show a clear thank-you panel after a successful donation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXhhC8xipsBR7e3o76i
2026-11-16 08:21:20 -08:00
shadowdaoandClaude Sonnet 5.5 a41ad107a1 Donate form: fill container width, centre block, left-align text inside theme-centred modules
Test and Release / test (push) Successful in 2m1s
Test and Release / release (push) Successful in 14s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXhhC8xipsBR7e3o76i
2026-11-16 06:48:30 -08:00
shadowdaoandClaude Sonnet 5.5 f19ed5c5f2 Fix moderation redirect after last approval; add going-live and chargeback docs
Test and Release / test (push) Successful in 1m20s
Test and Release / release (push) Successful in 16s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 21:44:47 -08:00
shadowdaoandClaude Sonnet 5.5 9f33ea7975 Progress bar: use accent gradient fill so a full bar is visible
Test and Release / test (push) Successful in 1m18s
Test and Release / release (push) Successful in 4s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 17:53:34 -08:00
11 changed files with 118 additions and 8 deletions

No files matched your search

+20
View File
@@ -30,6 +30,23 @@ You need two values from PayPal: a **Client ID** and a **Secret**.
Start in **Sandbox**, make a test donation using a PayPal sandbox buyer account, then repeat the steps
with the Live credentials and switch the mode to Live in Settings.
### Going live
1. In the PayPal developer dashboard (Apps & Credentials), switch to **Live** and create a Live app (type Merchant).
2. In StreamGoals > Settings, paste the Live **Client ID** and **Secret**.
3. Switch the mode to **Live**, then **Save and test connection**.
4. Webhook: the plugin registers it for you when the test succeeds (changing mode or credentials clears the old one, so
the Live webhook is created fresh). It points to `https://YOUR-SITE/wp-json/streamgoals/v1/webhook` and listens for
`PAYMENT.CAPTURE.COMPLETED`. If the message says it could not register it (needs a public https site, or a webhook
for that address already exists), add it by hand in your Live app in the PayPal dashboard with that URL and that event.
5. Make a small real donation and check it appears under Donations and on your goal, then refund yourself in PayPal if you like.
6. Set the visitor IP header if needed (Settings > Advanced; Cloudflare is detected automatically).
7. Add the overlays in OBS as Browser Sources (StreamGoals > Overlays).
8. Turn on two-factor authentication for both your PayPal and WordPress accounts.
### Chargebacks and refunds
Chargebacks and refunds are handled manually in PayPal. The plugin does not track them, so totals, timers, counters
and tiers are not reduced. If you need to compensate, adjust the goal or its rules yourself by editing them.
### Behind Cloudflare?
Nothing to do: the plugin recognises Cloudflare automatically (by its published addresses) so each visitor is rate
limited separately. For another proxy, choose it in StreamGoals > Settings > Advanced; the panel there shows what your
@@ -105,6 +122,9 @@ plus a counter); when it differs from the one the page was loaded with, the over
plugin does this automatically, and StreamGoals > Overlays > "Refresh all overlays now" does it on demand. Alert media
URLs also carry `?v=<file modified time>`, so replacing a file with the same name is picked up.
Overlay data, overlay pages, the progress bar and the fee preview are never page-cached (the plugin tells LiteSpeed
Cache to skip them). With another caching plugin or CDN, exclude `/wp-json/streamgoals/` and `/streamgoals-overlay/`.
## Updates
New versions appear in WordPress automatically (Dashboard > Updates and the Plugins screen), checked against
this repository's releases. The repository is public, so no token is needed. (If you run a private fork, paste an
+7 -3
View File
@@ -1,4 +1,4 @@
.sg-donate{max-width:min(100%,440px);font:inherit}
.sg-donate{width:100%;max-width:min(100%,440px);margin-left:auto;margin-right:auto;box-sizing:border-box;text-align:left;font:inherit}
.sg-donate .sg-row{margin:0 0 .9rem}
.sg-donate label{display:block;font-weight:600;margin-bottom:.25rem}
.sg-donate label.sg-inline{display:flex;gap:.5rem;align-items:center;font-weight:400}
@@ -45,11 +45,15 @@
/* Progress bar (theme-neutral: inherits text colour; fill uses currentColor so it follows the theme). */
.sg-donate .sg-progress{margin:0 0 .9rem;max-width:100%;box-sizing:border-box}
.sg-donate .sg-progress-bar{position:relative;height:14px;border:1px solid rgba(128,128,128,.6);border-radius:999px;background:rgba(128,128,128,.18);overflow:hidden}
.sg-donate .sg-progress-fill{display:block;height:100%;width:0;background:currentColor;opacity:.75;border-radius:999px;transition:width .6s ease}
.sg-donate .sg-progress-bar{position:relative;height:14px;border:1px solid rgba(128,128,128,.45);border-radius:999px;background:rgba(128,128,128,.22);overflow:hidden;box-shadow:inset 0 1px 2px rgba(0,0,0,.18)}
.sg-donate .sg-progress-fill{display:block;height:100%;width:0;background:linear-gradient(90deg,var(--sg-accent,#7c5cff),var(--sg-accent2,#22d3ee));min-width:0;border-radius:999px;transition:width .6s ease}
.sg-donate .sg-progress-text{display:flex;flex-wrap:wrap;justify-content:space-between;gap:.25rem .75rem;margin-top:.35rem;font-weight:600;line-height:1.4;overflow-wrap:anywhere}
.sg-donate .sg-progress-tier,.sg-donate .sg-progress-done{margin:.25rem 0 0;font-size:.9em;line-height:1.4;overflow-wrap:anywhere}
.sg-donate .sg-progress-done{font-weight:700}
.sg-donate .sg-progress [hidden]{display:none}
.sg-donate.sg-progress-only .sg-progress{margin-bottom:0}
@media (prefers-reduced-motion:reduce){.sg-donate .sg-progress-fill{transition:none}}
.sg-donate .sg-thanks{margin:.5rem 0 0;padding:1.1rem 1rem;border:1px solid rgba(26,127,55,.55);border-left-width:4px;border-radius:.4rem;text-align:center}
.sg-donate .sg-thanks:focus{outline:0}
.sg-donate .sg-thanks-title{margin:0;font-size:1.15em;font-weight:700;line-height:1.4;overflow-wrap:anywhere}
.sg-donate [hidden]{display:none!important}
+16 -3
View File
@@ -79,7 +79,7 @@
bar.setAttribute('aria-valuenow', String(pct));
bar.setAttribute('aria-valuetext', p.reached ? (PT.reached || '') : of + ' (' + pct + '%)');
bar.setAttribute('aria-label', String(PT.label || '%s').replace('%s', function () { return p.title; }));
bar.firstChild.style.width = pct + '%';
bar.firstChild.style.width = ((pct < 2 && (parseInt(p.raised_minor, 10) || 0) > 0) ? 2 : pct) + '%';
box.querySelector('.sg-progress-amounts').textContent = of;
box.querySelector('.sg-progress-pct').textContent = pct + '%';
var tier = box.querySelector('.sg-progress-tier'), done = box.querySelector('.sg-progress-done');
@@ -110,7 +110,7 @@
refreshAll(true); // a cached page may hold old numbers
}
// After a successful donation: refresh now, and again shortly (a pending capture can finalize a moment later).
function afterDonation() { refreshAll(true); setTimeout(function () { refreshAll(true); }, 5000); }
function afterDonation() { refreshAll(true); [1500, 5000, 12000].forEach(function (ms) { setTimeout(function () { refreshAll(true); }, ms); }); }
function init(root) {
var pinned = parseInt(root.getAttribute('data-goal'), 10) || 0;
@@ -262,6 +262,18 @@
};
}
// Replace the form with a confirmation (keeps the progress bar). No way back until the page is reloaded,
// so the donor does not pay twice thinking it failed.
function showThanks(text) {
state.renderToken++;
Array.prototype.forEach.call(root.children, function (n) { if (n !== barBox) { n.hidden = true; } });
var panel = el('div', { 'class': 'sg-thanks', role: 'status', tabindex: '-1' }, [
el('p', { 'class': 'sg-thanks-title', text: text })
]);
root.appendChild(panel);
try { panel.focus(); panel.scrollIntoView({ block: 'nearest', behavior: 'smooth' }); } catch (e) { /* ignore */ }
}
function renderButtons() {
var token = ++state.renderToken;
buttons.textContent = '';
@@ -277,7 +289,8 @@
},
onApprove: function (data) {
return api('/orders/' + encodeURIComponent(data.orderID) + '/capture', { method: 'POST' }).then(function (r) {
say(r.status === 'completed' ? T.thanks : T.processing, 'sg-ok');
say('');
showThanks(r.status === 'completed' ? T.thanks : T.processing);
afterDonation();
});
},
+7 -1
View File
@@ -98,13 +98,19 @@ final class DonationsPage {
Admin::close();
}
/** Moderation submenu exists only when moderation is on or items are pending (see Admin::menu); otherwise land on Donations. */
public static function afterModerationPage( bool $moderationOn, int $pending ): string {
return ( $moderationOn || $pending > 0 ) ? 'streamgoals-moderation' : 'streamgoals-donations';
}
public static function handleModerate(): void {
Admin::guard( 'sg_moderate' );
$post = Admin::post_raw();
$id = isset( $post['donation_id'] ) ? absint( $post['donation_id'] ) : 0;
$to = isset( $post['decision'] ) && is_string( $post['decision'] ) ? $post['decision'] : '';
$ok = $id && Store::setModeration( $id, $to );
Admin::redirect( Admin::url( 'streamgoals-moderation' ), $ok ? 'success' : 'error', $ok ? ( 'approved' === $to ? 'Donation approved.' : 'Donation rejected.' ) : 'That donation could not be updated (it may already be reviewed).' );
$page = self::afterModerationPage( (bool) Settings::get( 'moderate_messages' ), Store::pendingModerationCount() );
Admin::redirect( Admin::url( $page ), $ok ? 'success' : 'error', $ok ? ( 'approved' === $to ? 'Donation approved.' : 'Donation rejected.' ) : 'That donation could not be updated (it may already be reviewed).' );
}
public static function handleExport(): void {
+21
View File
@@ -0,0 +1,21 @@
<?php
declare( strict_types=1 );
namespace StreamGoals\Core;
/**
* Keeps live responses out of page caches. LiteSpeed Cache stores REST responses (and pages sending
* nocache_headers()) for days unless told otherwise, which freezes overlays that poll for changes.
*/
final class PageCache {
public const LITESPEED_HEADER = 'X-LiteSpeed-Cache-Control';
/** Call before any output, early enough that error responses are covered too. */
public static function skip( string $reason ): void {
do_action( 'litespeed_control_set_nocache', 'streamgoals ' . $reason );
if ( ! headers_sent() ) {
header( self::LITESPEED_HEADER . ': no-cache' ); // also covers LiteSpeed server caching without the plugin
}
}
}
+2 -1
View File
@@ -76,13 +76,14 @@ final class Progress {
public static function html( array $p, array $labels ): string {
$e = static fn( string $s ): string => htmlspecialchars( $s, ENT_QUOTES, 'UTF-8' );
$pct = max( 0, min( 100, (int) $p['percent'] ) );
$fill = ( $pct < 2 && (int) ( $p['raised_minor'] ?? 0 ) > 0 ) ? 2 : $pct; // a first small donation still shows
$sub = static fn( string $tpl, array $v ): string => (string) preg_replace_callback( '/%(\d)\$s/', static fn( array $m ): string => $v[ (int) $m[1] - 1 ] ?? '', $tpl );
$of = $sub( $labels['of'] ?? '%1$s / %2$s', array( $p['raised_display'], $p['target_display'] ) );
$out = '<div class="sg-progress' . ( $p['reached'] ? ' sg-progress-reached' : '' ) . '" data-goal="' . (int) $p['goal_id'] . '">';
$out .= '<div class="sg-progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="' . $pct . '"'
. ' aria-valuetext="' . $e( $p['reached'] ? ( $labels['reached'] ?? '' ) : $of . ' (' . $pct . '%)' ) . '"'
. ' aria-label="' . $e( str_replace( '%s', (string) $p['title'], $labels['label'] ?? '%s' ) ) . '">'
. '<span class="sg-progress-fill" style="width:' . $pct . '%"></span></div>';
. '<span class="sg-progress-fill" style="width:' . $fill . '%"></span></div>';
$out .= '<div class="sg-progress-text"><span class="sg-progress-amounts">' . $e( $of ) . '</span> <span class="sg-progress-pct">' . $pct . '%</span></div>';
$out .= '<p class="sg-progress-tier"' . ( $p['tier'] ? '' : ' hidden' ) . '>'
. ( $p['tier'] ? $e( $sub( $labels['tier'] ?? '%1$s (%2$s)', array( $p['tier']['title'], $p['tier']['target_display'] ) ) ) : '' ) . '</p>';
+2
View File
@@ -3,6 +3,7 @@ declare( strict_types=1 );
namespace StreamGoals\Overlay;
use StreamGoals\Core\PageCache;
use StreamGoals\Rest\OverlayController;
/** Serves the transparent OBS browser-source page at /streamgoals-overlay/{token}/{widget}/. */
@@ -46,6 +47,7 @@ final class Router {
if ( '' === $token || '' === $widget ) {
return;
}
PageCache::skip( 'overlay page' ); // nocache_headers() alone does not stop LiteSpeed Cache
if ( ! is_string( $token ) || ! is_string( $widget ) || ! in_array( $widget, OverlayService::WIDGETS, true ) || ! OverlayController::verify_token( $token ) ) {
global $wp_query;
$wp_query->set_404();
+4
View File
@@ -3,6 +3,7 @@ declare( strict_types=1 );
namespace StreamGoals\Rest;
use StreamGoals\Core\PageCache;
use StreamGoals\Core\GoalTargetPolicy;
use StreamGoals\Core\Money;
use StreamGoals\Core\Settings;
@@ -85,6 +86,8 @@ final class DonateController {
$res = rest_ensure_response( self::progress_for( $goal ) );
// Short shared cache lets a CDN collapse bursts; the page JS adds a cache-busting parameter after a donation.
$res->header( 'Cache-Control', 'public, max-age=10, s-maxage=10' );
PageCache::skip( 'progress' ); // LiteSpeed would otherwise hold REST responses for days
$res->header( PageCache::LITESPEED_HEADER, 'no-cache' );
return $res;
}
@@ -168,6 +171,7 @@ final class DonateController {
}
public static function fee_preview( \WP_REST_Request $req ) {
PageCache::skip( 'fee preview' ); // follows the current fee settings and goal status
if ( $limited = self::limit( 'preview', 120, 60 ) ) {
return $limited;
}
+2
View File
@@ -3,6 +3,7 @@ declare( strict_types=1 );
namespace StreamGoals\Rest;
use StreamGoals\Core\PageCache;
use StreamGoals\Core\Settings;
use StreamGoals\Overlay\Build;
use StreamGoals\Overlay\OverlayService;
@@ -54,6 +55,7 @@ final class OverlayController {
}
public static function handle( \WP_REST_Request $req ): \WP_REST_Response|\WP_Error {
PageCache::skip( 'overlay data' ); // a cached poll response would freeze the goal bar and alerts
if ( ! self::verify_token( (string) $req['token'] ) ) {
return new \WP_Error( 'sg_not_found', 'Not found.', array( 'status' => 404 ) );
}
+8
View File
@@ -5,6 +5,7 @@ namespace StreamGoals\Tests\Unit;
use PHPUnit\Framework\TestCase;
use StreamGoals\Admin\Csv;
use StreamGoals\Admin\DonationsPage;
use StreamGoals\Admin\Format;
use StreamGoals\Admin\Input;
use StreamGoals\Admin\RuleConfig;
@@ -133,4 +134,11 @@ final class AdminLogicTest extends TestCase {
$this->assertTrue( Format::isTest( array( 'paypal_order_id' => 'TEST-abc' ) ) );
$this->assertFalse( Format::isTest( array( 'paypal_order_id' => '5O1234' ) ) );
}
public function test_after_moderation_redirect_only_to_registered_page(): void {
$this->assertSame( 'streamgoals-donations', DonationsPage::afterModerationPage( false, 0 ) );
$this->assertSame( 'streamgoals-moderation', DonationsPage::afterModerationPage( false, 2 ) );
$this->assertSame( 'streamgoals-moderation', DonationsPage::afterModerationPage( true, 0 ) );
$this->assertSame( 'streamgoals-moderation', DonationsPage::afterModerationPage( true, 5 ) );
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
declare( strict_types=1 );
namespace StreamGoals\Tests\Unit;
use PHPUnit\Framework\TestCase;
/** Live responses must opt out of page caching, or OBS overlays freeze behind LiteSpeed Cache. */
final class PageCacheOptOutTest extends TestCase {
public function test_every_live_response_opts_out_of_page_caching(): void {
$root = dirname( __DIR__, 2 ) . '/includes/';
$expected = array(
'Rest/OverlayController.php' => "PageCache::skip( 'overlay data' )",
'Overlay/Router.php' => "PageCache::skip( 'overlay page' )",
'Rest/DonateController.php' => "PageCache::skip( 'fee preview' )",
);
foreach ( $expected as $file => $call ) {
$this->assertStringContainsString( $call, (string) file_get_contents( $root . $file ), $file );
}
$helper = (string) file_get_contents( $root . 'Core/PageCache.php' );
$this->assertStringContainsString( 'litespeed_control_set_nocache', $helper );
}
public function test_overlay_opts_out_before_the_token_check_so_404s_are_not_cached(): void {
$src = (string) file_get_contents( dirname( __DIR__, 2 ) . '/includes/Rest/OverlayController.php' );
$this->assertLessThan( strpos( $src, 'self::verify_token( (string)' ), strpos( $src, 'PageCache::skip(' ) );
}
}