Add in-WordPress updater: checks Gitea releases, one-click and auto updates
- Update\ReleaseParser (pure, host-pinned, https only) and Update\Updater (WP hooks, cached, failure-safe) - Settings: optional access token for a private repo, 'Check for updates now' Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
27646c1001
commit
4cec93067c
7 files changed
+453
No files matched your search
@@ -60,11 +60,21 @@ final class SettingsPage {
|
||||
self::ipDiagnostics( (string) $s['visitor_ip_header'] );
|
||||
echo '</td></tr></table></div>';
|
||||
|
||||
$rel = \StreamGoals\Update\Updater::latest();
|
||||
echo '<div class="sg-card"><h2>Plugin updates</h2><table class="form-table" role="presentation">';
|
||||
echo '<tr><th scope="row">Installed version</th><td><code>' . esc_html( STREAMGOALS_VERSION ) . '</code></td></tr>';
|
||||
echo '<tr><th scope="row">Latest release</th><td>' . ( $rel ? '<code>' . esc_html( $rel['version'] ) . '</code>' . ( \StreamGoals\Update\ReleaseParser::isNewer( $rel['version'], STREAMGOALS_VERSION ) ? ' (update available)' : ' (up to date)' ) : 'Not found yet (or the check failed).' ) . ' <button type="submit" form="sg_update_check_form" class="button">Check for updates now</button></td></tr>';
|
||||
echo '<tr><th scope="row"><label for="sg_utoken">Access token (only needed while the update repository is private)</label></th><td><input type="password" id="sg_utoken" name="update_token" class="regular-text code" autocomplete="new-password" spellcheck="false" value="" placeholder="' . esc_attr( '' !== (string) $s['update_token'] ? Input::maskSecret( (string) $s['update_token'] ) : 'Paste a read-only token' ) . '">';
|
||||
echo '<p class="description">' . ( '' !== (string) $s['update_token'] ? 'A token is saved. Leave this empty to keep it, or paste a new one to replace it.' : 'Not needed once the repository is public.' ) . '</p></td></tr></table></div>';
|
||||
|
||||
echo '<div class="sg-card"><h2>PayPal fee estimate</h2>';
|
||||
echo '<p>When a donor chooses "cover the fees", the form adds the estimated PayPal fee so you receive the amount they intended. The defaults (<strong>3.49% + $0.49</strong>) are <strong>US domestic estimates</strong>. Fees for international (cross-border) payments and currency conversion are higher and are <strong>not</strong> included, so you may receive slightly less than expected in those cases. Check PayPal\'s current fee page for your country and adjust.</p>';
|
||||
echo '<table class="form-table" role="presentation"><tr><th scope="row"><label for="sg_pct">Percentage fee</label></th><td><input type="text" id="sg_pct" name="fee_percent" class="small-text" inputmode="decimal" value="' . esc_attr( number_format( (int) $s['fee_percent_bps'] / 100, 2, '.', '' ) ) . '"> %</td></tr>';
|
||||
echo '<tr><th scope="row"><label for="sg_fix">Fixed fee (' . esc_html( $cur ) . ')</label></th><td><input type="text" id="sg_fix" name="fee_fixed" class="small-text" inputmode="decimal" value="' . esc_attr( Format::decimal( (int) $s['fee_fixed_minor'], $cur ) ) . '"></td></tr></table></div>';
|
||||
echo '<p><button class="button button-primary button-hero">Save settings</button></p></form>';
|
||||
echo '<form id="sg_update_check_form" method="post" action="' . esc_url( admin_url( 'admin-post.php' ) ) . '"><input type="hidden" name="action" value="' . esc_attr( \StreamGoals\Update\Updater::ACTION_CHECK ) . '">';
|
||||
wp_nonce_field( \StreamGoals\Update\Updater::ACTION_CHECK );
|
||||
echo '</form>';
|
||||
Admin::close();
|
||||
}
|
||||
|
||||
@@ -129,6 +139,10 @@ final class SettingsPage {
|
||||
} else {
|
||||
$upd['visitor_ip_header'] = $ipMode;
|
||||
}
|
||||
$tok = $post['update_token'] ?? '';
|
||||
if ( ! Input::secretUnchanged( is_string( $tok ) ? $tok : '' ) ) {
|
||||
$upd['update_token'] = Input::text( $tok, 300 );
|
||||
}
|
||||
$upd['funding_card'] = ! empty( $post['funding_card'] );
|
||||
$upd['funding_paylater'] = ! empty( $post['funding_paylater'] );
|
||||
$upd['moderate_messages'] = ! empty( $post['moderate_messages'] );
|
||||
|
||||
Reference in new issue
Block a user