chore: initial commit — Radio v0.1.0 (Phase A complete)

First release of a-radio — a free, focused SomaFM player for the
WordPress admin. Extracted-and-rebuilt from RangerPlex's RadioPlayer
component, simplified along the way (no Node CORS proxy needed; the
browser plays SomaFM streams directly).

Phase A deliverables — all in this commit:

PLAYER SURFACES
- Dashboard widget on WP Admin → Dashboard (compact: play/pause +
  station select + volume).
- Dedicated admin page at WP Admin → Radio → My Radio (larger
  layout, station genre badge, volume %% display).
- Both surfaces share the same JS — picking a station on one mirrors
  to the other within the same admin session.

STATIONS
- 44 SomaFM stations grouped by 10 genres (Ambient / Electronic /
  Lounge / Rock / Metal / Jazz / World / Reggae / Holiday / Specials).
- Ported verbatim from RangerPlex's RadioPlayer.tsx.
- Default station: Groove Salad (most popular SomaFM channel, safe
  ambient/coding pick).

STATE
- Per-user state stored in user_meta under key `radio_state`:
  { station_id, volume, theme, last_played_at }.
- Settings page lets the user pick default station, default volume,
  theme (auto/light/dark), and hide the dashboard widget.
- AJAX endpoint `radio_save_state` persists changes without a page
  reload. Nonce-protected, capability-checked, only known keys
  accepted, station validated against the list, volume clamped to
  [0,1].

UPDATES
- Self-hosted updater wired to Gitea (ranger/a-radio) from commit 1.
- Direct port of Buddy's inc/updater.php with BUDDY_* → RADIO_* and
  buddy_* → radio_* renames. Same 12h-success / 1h-error caching.

ARCHITECTURE
- No `wp` prefix (trademark policy).
- GPL v2+ public Gitea repo from day one.
- Vanilla JS only — no React, no webpack, no minified-only files.
- CSS-only animations, all assets local.
- Single H1 per admin page.
- Direct HTML5 <audio> playback (SomaFM has CORS headers; no PHP
  audio proxy needed). This is the key simplification vs RangerPlex.

COMPLIANCE
- "Powered by SomaFM" credit displayed on both player surfaces with
  link to somafm.com. About page invites users to donate to SomaFM
  directly.

PHASE PROGRESSION (not in this commit)
- Phase B — Settings polish + retry on transient stream errors +
  README.md formatted for WP.org submission.
- Phase C — Now-playing metadata via SomaFM's per-station song
  history endpoint (this is where the RangerPlex proxy logic ports
  to — server-side, for metadata not audio).
- Phase D — [ranger_radio] shortcode for frontend embedding.
- Phase E — Favorites system.
- Phase F — Multi-provider (Radio Paradise / NTS / KEXP / BBC).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-26 09:40:23 +01:00
commit a22ddfb6d3
13 changed files with 1543 additions and 0 deletions
+88
View File
@@ -0,0 +1,88 @@
<?php
/**
* Radio — dashboard widget.
*
* The compact mini-player on WP Admin → Dashboard. Same HTML structure
* as the main admin page but smaller, so the assets/js/radio.js can
* bind to whichever surface the user opens first.
*/
if ( ! defined( 'ABSPATH' ) ) { exit; }
add_action( 'wp_dashboard_setup', 'radio_register_dashboard_widget' );
function radio_register_dashboard_widget() {
if ( ! current_user_can( 'read' ) ) { return; }
// Honour the per-user opt-out from Settings.
$state = radio_get_state();
if ( isset( $state['hide_dashboard_widget'] ) && $state['hide_dashboard_widget'] ) {
return;
}
wp_add_dashboard_widget(
'radio_dashboard_widget',
__( 'Radio', 'radio' ),
'radio_render_dashboard_widget'
);
}
function radio_render_dashboard_widget() {
$state = radio_get_state();
$station = radio_find_station( $state['station_id'] );
$stations = radio_get_stations_grouped();
?>
<div class="radio-player radio-player--widget" data-radio-surface="widget">
<div class="radio-player__now">
<div class="radio-player__label"><?php esc_html_e( 'Now Playing', 'radio' ); ?></div>
<div class="radio-player__station-name" data-radio-name><?php echo esc_html( $station['name'] ); ?></div>
<div class="radio-player__station-desc" data-radio-desc><?php echo esc_html( $station['description'] ); ?></div>
</div>
<div class="radio-player__controls">
<button type="button" class="radio-player__play button button-primary" data-radio-play title="<?php esc_attr_e( 'Play', 'radio' ); ?>">
<span class="dashicons dashicons-controls-play"></span>
</button>
<div class="radio-player__volume">
<span class="dashicons dashicons-controls-volumeon"></span>
<input type="range" min="0" max="100" value="<?php echo esc_attr( (int) round( $state['volume'] * 100 ) ); ?>" data-radio-volume aria-label="<?php esc_attr_e( 'Volume', 'radio' ); ?>">
</div>
</div>
<div class="radio-player__station-select">
<label for="radio-station-widget"><?php esc_html_e( 'Station', 'radio' ); ?></label>
<select id="radio-station-widget" data-radio-station>
<?php foreach ( $stations as $genre => $entries ) :
if ( empty( $entries ) ) { continue; }
?>
<optgroup label="<?php echo esc_attr( $genre ); ?>">
<?php foreach ( $entries as $entry ) : ?>
<option value="<?php echo esc_attr( $entry['id'] ); ?>" data-url="<?php echo esc_attr( $entry['url'] ); ?>" data-desc="<?php echo esc_attr( $entry['description'] ); ?>" <?php selected( $entry['id'], $state['station_id'] ); ?>>
<?php echo esc_html( $entry['name'] ); ?>
</option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
</select>
</div>
<div class="radio-player__error" data-radio-error hidden></div>
<audio data-radio-audio preload="none"></audio>
<p class="radio-player__credit">
<?php
/* translators: %s = SomaFM link */
printf(
wp_kses(
/* translators: %s = link to somafm.com */
__( 'Powered by %s', 'radio' ),
array( 'a' => array( 'href' => true, 'target' => true, 'rel' => true ) )
),
'<a href="https://somafm.com/" target="_blank" rel="noopener">SomaFM</a>'
);
?>
</p>
</div>
<?php
}