3e6994461e
v0.1.0 worked but felt like a third-party React widget bolted on
top of WordPress. v0.2.0 makes the player visually native to the
WP admin: postbox container, standard Play/Pause button with text
label, admin-colour-scheme aware accents, dashboard widget no
longer renders a card inside a card.
CHANGES
- inc/admin-page.php: main page now wraps the player in a
.postbox > .postbox-header (with h2.hndle) > .inside structure.
Custom rounded card / shadow stripped.
- inc/dashboard-widget.php: bare .radio-player content; WP already
wraps dashboard widgets in a postbox, was double-card before.
- inc/about.php: version-history card promotes v0.2.0 to latest,
demotes v0.1.0.
- assets/css/radio.css: rewrite. Strip custom shadows + oversized
typography. Adopt WP body-text defaults. Use
var(--wp-admin-theme-color, #2271b1) for volume-slider accent +
link colours so the plugin picks up whichever admin colour
scheme the user has chosen. About-page cards now use the
postbox-style gray header + 1px border pattern.
- assets/js/radio.js: setPlayIcon() also flips the visible text
label ("Play" ↔ "Pause"), not just the icon class. mirrorSelection()
also updates the [data-radio-genre] element so the genre label
stays in sync across surfaces.
- radio.php: Version: 0.1.0 -> 0.2.0; BUDDY_VERSION constant
bumped likewise.
- CHANGELOG.md: new [0.2.0] entry explaining the visual overhaul.
NET EFFECT
- Same 44 stations, same audio path, same persistence, same
updater, same AJAX endpoint. Pure visual change.
- The plugin now looks like part of WordPress admin instead of a
guest widget.
- Closer to WP.org submission criteria — plugin reviewers look
for native-styled plugins.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
173 lines
6.0 KiB
PHP
173 lines
6.0 KiB
PHP
<?php
|
|
/**
|
|
* Radio — a free SomaFM player for your WordPress dashboard
|
|
*
|
|
* Plugin Name: Radio
|
|
* Plugin URI: https://icanhelp.ie/radio
|
|
* Description: A small, focused, free radio player for your WordPress admin. 44 SomaFM stations grouped by 10 genres — ambient, electronic, lounge, rock, metal, jazz, world, reggae, holiday, specials. Plays via HTML5 audio; volume + station choice persist per-user.
|
|
* Version: 0.2.0
|
|
* Requires at least: 5.0
|
|
* Requires PHP: 7.4
|
|
* Author: David Keane
|
|
* Author URI: https://rangersmyth.xyz/
|
|
* License: GPL v2 or later
|
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
* Text Domain: radio
|
|
*
|
|
* @package Radio
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; }
|
|
|
|
// Plugin coordinates.
|
|
if ( ! defined( 'RADIO_VERSION' ) ) { define( 'RADIO_VERSION', '0.2.0' ); }
|
|
if ( ! defined( 'RADIO_FILE' ) ) { define( 'RADIO_FILE', __FILE__ ); }
|
|
if ( ! defined( 'RADIO_PATH' ) ) { define( 'RADIO_PATH', plugin_dir_path( __FILE__ ) ); }
|
|
if ( ! defined( 'RADIO_URL' ) ) { define( 'RADIO_URL', plugin_dir_url( __FILE__ ) ); }
|
|
if ( ! defined( 'RADIO_BASENAME' ) ) { define( 'RADIO_BASENAME', plugin_basename( __FILE__ ) ); }
|
|
|
|
// Includes — each file owns one concern.
|
|
require_once RADIO_PATH . 'inc/stations.php'; // the 44-station array + genre helpers
|
|
require_once RADIO_PATH . 'inc/state.php'; // user_meta storage for station/volume choice
|
|
require_once RADIO_PATH . 'inc/dashboard-widget.php'; // the compact mini-player on WP Dashboard
|
|
require_once RADIO_PATH . 'inc/admin-page.php'; // dedicated Radio admin page (larger player)
|
|
require_once RADIO_PATH . 'inc/about.php'; // About page
|
|
require_once RADIO_PATH . 'inc/settings.php'; // Settings page
|
|
require_once RADIO_PATH . 'inc/updater.php'; // self-hosted update checker against Gitea
|
|
|
|
/**
|
|
* Admin menu registration. Radio gets its own top-level menu — having
|
|
* the player one click away matters more than tucking it into Tools or
|
|
* Settings. Icon is dashicons-format-audio for direct visual match.
|
|
*/
|
|
add_action( 'admin_menu', 'radio_register_admin_menu' );
|
|
function radio_register_admin_menu() {
|
|
add_menu_page(
|
|
__( 'Radio', 'radio' ),
|
|
__( 'Radio', 'radio' ),
|
|
'read', // any logged-in user with read access has their own radio
|
|
'radio',
|
|
'radio_render_main_page',
|
|
'dashicons-format-audio',
|
|
72 // sits below Comments, above plugin entries
|
|
);
|
|
|
|
// "My Radio" — main landing submenu. Same slug as parent so clicking
|
|
// either entry lands on the same page. Empty callback so only the
|
|
// parent renderer fires (lesson learned from Buddy / Logbook duplicate-
|
|
// form gotcha).
|
|
add_submenu_page(
|
|
'radio',
|
|
__( 'My Radio', 'radio' ),
|
|
__( 'My Radio', 'radio' ),
|
|
'read',
|
|
'radio',
|
|
''
|
|
);
|
|
|
|
add_submenu_page(
|
|
'radio',
|
|
__( 'Settings', 'radio' ),
|
|
__( 'Settings', 'radio' ),
|
|
'manage_options',
|
|
'radio-settings',
|
|
'radio_render_settings_page'
|
|
);
|
|
|
|
add_submenu_page(
|
|
'radio',
|
|
__( 'About', 'radio' ),
|
|
__( 'About', 'radio' ),
|
|
'read',
|
|
'radio-about',
|
|
'radio_render_about_page'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Enqueue Radio's CSS + JS on its own admin pages and on the main
|
|
* dashboard (where the mini-player widget lives).
|
|
*/
|
|
add_action( 'admin_enqueue_scripts', 'radio_enqueue_admin_assets' );
|
|
function radio_enqueue_admin_assets( $hook ) {
|
|
$radio_hooks = array(
|
|
'index.php', // WP Dashboard (the widget lives here)
|
|
'toplevel_page_radio', // Radio main page
|
|
'radio_page_radio-settings', // Settings
|
|
'radio_page_radio-about', // About
|
|
);
|
|
if ( ! in_array( $hook, $radio_hooks, true ) ) { return; }
|
|
|
|
wp_enqueue_style(
|
|
'radio-admin',
|
|
RADIO_URL . 'assets/css/radio.css',
|
|
array(),
|
|
RADIO_VERSION
|
|
);
|
|
|
|
wp_enqueue_script(
|
|
'radio-admin',
|
|
RADIO_URL . 'assets/js/radio.js',
|
|
array(),
|
|
RADIO_VERSION,
|
|
true
|
|
);
|
|
|
|
// Pass per-user state + station list + AJAX URL to JS.
|
|
wp_localize_script( 'radio-admin', 'RadioPlugin', array(
|
|
'state' => radio_get_state(),
|
|
'stations' => radio_get_stations_flat(),
|
|
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
|
'nonce' => wp_create_nonce( 'radio_save_state' ),
|
|
'strings' => array(
|
|
'play' => __( 'Play', 'radio' ),
|
|
'pause' => __( 'Pause', 'radio' ),
|
|
'loading' => __( 'Loading…', 'radio' ),
|
|
'error' => __( 'Stream error — try another station.', 'radio' ),
|
|
'nowPlaying' => __( 'Now Playing', 'radio' ),
|
|
'volume' => __( 'Volume', 'radio' ),
|
|
'station' => __( 'Station', 'radio' ),
|
|
),
|
|
) );
|
|
}
|
|
|
|
/**
|
|
* AJAX endpoint for saving per-user state (station / volume changes).
|
|
* Avoids a full page reload on every interaction.
|
|
*/
|
|
add_action( 'wp_ajax_radio_save_state', 'radio_ajax_save_state' );
|
|
function radio_ajax_save_state() {
|
|
if ( ! is_user_logged_in() ) {
|
|
wp_send_json_error( 'Not logged in.', 401 );
|
|
}
|
|
check_ajax_referer( 'radio_save_state', 'nonce' );
|
|
|
|
$patch = array();
|
|
if ( isset( $_POST['station_id'] ) ) {
|
|
$patch['station_id'] = sanitize_key( wp_unslash( $_POST['station_id'] ) );
|
|
}
|
|
if ( isset( $_POST['volume'] ) ) {
|
|
$patch['volume'] = max( 0.0, min( 1.0, (float) $_POST['volume'] ) );
|
|
}
|
|
|
|
if ( empty( $patch ) ) {
|
|
wp_send_json_error( 'Nothing to save.', 400 );
|
|
}
|
|
|
|
radio_update_state( $patch );
|
|
wp_send_json_success( radio_get_state() );
|
|
}
|
|
|
|
/**
|
|
* Activation hook: ensure the version option is set so the updater can
|
|
* track it.
|
|
*/
|
|
register_activation_hook( __FILE__, 'radio_on_activate' );
|
|
function radio_on_activate() {
|
|
if ( false === get_option( 'radio_version' ) ) {
|
|
add_option( 'radio_version', RADIO_VERSION );
|
|
} else {
|
|
update_option( 'radio_version', RADIO_VERSION );
|
|
}
|
|
}
|