feat: link a podcast show to where it is heard
Releases already had platform links; shows had none, so the Podcasts page could not point at Spotify or Apple. chrnx_show terms take a Spotify, Apple Podcasts and RSS URL now, rendered above the latest episode and only when a URL exists. The platform helper takes its definitions as an argument rather than always reading the release set: a podcast lives on Apple Podcasts, not Apple Music, and labelling it wrong would send people to the wrong service. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
8 files changed
+197
-6
No files matched your search
@@ -1856,3 +1856,25 @@ html[data-theme="light"] .chrnx-music-landing .chrnx-character-stage {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Where a show can be heard, above its latest episode. */
|
||||
.chrnx-show-links {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem 1rem;
|
||||
align-items: center;
|
||||
margin-block: 1.5rem;
|
||||
}
|
||||
|
||||
.chrnx-show-links__label {
|
||||
margin: 0;
|
||||
color: var(--chrnx-muted);
|
||||
font-family: var(--wp--preset--font-family--metadata);
|
||||
font-size: var(--wp--preset--font-size--small);
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.chrnx-show-links .chrnx-platform-links {
|
||||
margin: 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/show-links",
|
||||
"version": "0.2.0",
|
||||
"title": "Show Links",
|
||||
"category": "theme",
|
||||
"description": "Where a podcast show can be listened to, rendered only when a URL exists.",
|
||||
"textdomain": "chrnx",
|
||||
"attributes": {
|
||||
"show": { "type": "string", "default": "" }
|
||||
},
|
||||
"supports": { "html": false },
|
||||
"render": "file:./render.php"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Show Links block render.
|
||||
*
|
||||
* @package CHRNX
|
||||
*/
|
||||
|
||||
// A named show wins; otherwise fall back to the show archive being viewed.
|
||||
$chrnx_slug = chrnx_validate_editorial_term_slug( $attributes['show'] ?? '', 'chrnx_show' );
|
||||
$chrnx_term = '' !== $chrnx_slug ? get_term_by( 'slug', $chrnx_slug, 'chrnx_show' ) : get_queried_object();
|
||||
if ( ! $chrnx_term instanceof WP_Term || 'chrnx_show' !== $chrnx_term->taxonomy ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$chrnx_links = chrnx_get_show_links( $chrnx_term->term_id );
|
||||
if ( empty( $chrnx_links ) ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<div <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-show-links' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
||||
<p class="chrnx-show-links__label"><?php echo esc_html__( 'Listen on', 'chrnx' ); ?></p>
|
||||
<?php echo chrnx_get_platform_links_markup( $chrnx_links, 'chrnx-platform-links', chrnx_get_show_platforms() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
define( 'CHRNX_VERSION', '0.2.0' );
|
||||
|
||||
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||
foreach ( array( 'setup', 'assets', 'taxonomies', 'editor', 'podcast-meta', 'project-meta', 'release-meta', 'track-meta', 'settings', 'queries', 'media', 'blocks', 'theme-preference' ) as $module ) {
|
||||
foreach ( array( 'setup', 'assets', 'taxonomies', 'editor', 'podcast-meta', 'project-meta', 'release-meta', 'show-meta', 'track-meta', 'settings', 'queries', 'media', 'blocks', 'theme-preference' ) as $module ) {
|
||||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
$path = get_theme_file_path( "inc/{$module}.php" );
|
||||
if ( file_exists( $path ) ) {
|
||||
|
||||
+1
-1
@@ -232,7 +232,7 @@ function chrnx_get_editorial_card_markup( $post_id, $heading_level = 3, $class_n
|
||||
|
||||
/** Register all block metadata directories that exist. */
|
||||
function chrnx_register_editorial_blocks() {
|
||||
$blocks = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools', 'reading-time', 'journal-link', 'selected-work', 'release-list', 'release-detail', 'track-meta', 'subscribe-form' );
|
||||
$blocks = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools', 'reading-time', 'journal-link', 'selected-work', 'release-list', 'release-detail', 'track-meta', 'subscribe-form', 'show-links' );
|
||||
foreach ( $blocks as $block ) {
|
||||
$name = 'chrnx/' . $block;
|
||||
if ( WP_Block_Type_Registry::get_instance()->is_registered( $name ) ) {
|
||||
|
||||
@@ -112,12 +112,13 @@ function chrnx_get_release_links( $term_id ) {
|
||||
/**
|
||||
* Render a row of platform links, or nothing when none are stored.
|
||||
*
|
||||
* @param array<string,string> $links Platform key to URL.
|
||||
* @param string $class_name Wrapper class.
|
||||
* @param array<string,string> $links Platform key to URL.
|
||||
* @param string $class_name Wrapper class.
|
||||
* @param array<string,array>|null $platforms Platform definitions, defaulting to releases.
|
||||
* @return string Escaped markup or an empty string.
|
||||
*/
|
||||
function chrnx_get_platform_links_markup( array $links, $class_name = 'chrnx-platform-links' ) {
|
||||
$platforms = chrnx_get_release_platforms();
|
||||
function chrnx_get_platform_links_markup( array $links, $class_name = 'chrnx-platform-links', $platforms = null ) {
|
||||
$platforms = is_array( $platforms ) ? $platforms : chrnx_get_release_platforms();
|
||||
$items = '';
|
||||
|
||||
foreach ( $links as $platform => $url ) {
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* Show (podcast programme) term metadata.
|
||||
*
|
||||
* @package CHRNX
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return the platforms a show can be listened on.
|
||||
*
|
||||
* Shares the release icons but not their labels: a podcast lives on Apple
|
||||
* Podcasts, not Apple Music.
|
||||
*
|
||||
* @return array<string,array<string,string>> Platform key to label and icon.
|
||||
*/
|
||||
function chrnx_get_show_platforms() {
|
||||
$release = chrnx_get_release_platforms();
|
||||
|
||||
return array(
|
||||
'spotify' => $release['spotify'],
|
||||
'apple' => array(
|
||||
'label' => __( 'Apple Podcasts', 'chrnx' ),
|
||||
'icon' => $release['apple']['icon'],
|
||||
),
|
||||
'rss' => array(
|
||||
'label' => __( 'RSS feed', 'chrnx' ),
|
||||
'icon' => '<path d="M5 19a1 1 0 1 0 0-2 1 1 0 0 0 0 2"/><path d="M5 12a7 7 0 0 1 7 7"/><path d="M5 5a14 14 0 0 1 14 14"/>',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the show term meta keys and their sanitizers.
|
||||
*
|
||||
* @return array<string,string> Meta key to sanitize callback.
|
||||
*/
|
||||
function chrnx_get_show_meta_definitions() {
|
||||
$definitions = array();
|
||||
foreach ( array_keys( chrnx_get_show_platforms() ) as $platform ) {
|
||||
$definitions[ 'chrnx_show_url_' . $platform ] = 'chrnx_sanitize_https_url';
|
||||
}
|
||||
return $definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register show term metadata.
|
||||
*/
|
||||
function chrnx_register_show_meta() {
|
||||
foreach ( chrnx_get_show_meta_definitions() as $meta_key => $sanitize ) {
|
||||
register_term_meta(
|
||||
'chrnx_show',
|
||||
$meta_key,
|
||||
array(
|
||||
'type' => 'string',
|
||||
'single' => true,
|
||||
'show_in_rest' => true,
|
||||
'sanitize_callback' => $sanitize,
|
||||
'auth_callback' => 'chrnx_auth_release_meta',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'init', 'chrnx_register_show_meta' );
|
||||
|
||||
/**
|
||||
* Return the stored listening links for one show.
|
||||
*
|
||||
* @param int $term_id Show term ID.
|
||||
* @return array<string,string> Platform key to URL, omitting empty ones.
|
||||
*/
|
||||
function chrnx_get_show_links( $term_id ) {
|
||||
$links = array();
|
||||
foreach ( array_keys( chrnx_get_show_platforms() ) as $platform ) {
|
||||
$url = chrnx_sanitize_https_url( get_term_meta( $term_id, 'chrnx_show_url_' . $platform, true ) );
|
||||
if ( '' !== $url ) {
|
||||
$links[ $platform ] = $url;
|
||||
}
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the show metadata fields on the term edit screen.
|
||||
*
|
||||
* @param WP_Term $term Show term.
|
||||
*/
|
||||
function chrnx_render_show_edit_fields( $term ) {
|
||||
foreach ( chrnx_get_show_platforms() as $platform => $definition ) {
|
||||
chrnx_print_release_field(
|
||||
'chrnx_show_url_' . $platform,
|
||||
/* translators: %s: listening platform name. */
|
||||
sprintf( __( '%s URL', 'chrnx' ), $definition['label'] ),
|
||||
(string) get_term_meta( $term->term_id, 'chrnx_show_url_' . $platform, true ),
|
||||
'url',
|
||||
__( 'HTTPS only. Leave empty to hide this icon.', 'chrnx' )
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'chrnx_show_edit_form_fields', 'chrnx_render_show_edit_fields' );
|
||||
|
||||
/**
|
||||
* Persist show term metadata from the term edit screen.
|
||||
*
|
||||
* @param int $term_id Show term ID.
|
||||
*/
|
||||
function chrnx_save_show_meta( $term_id ) {
|
||||
if ( ! chrnx_auth_release_meta() ) {
|
||||
return;
|
||||
}
|
||||
// Core supplies and verifies the add/update term nonce on these screens.
|
||||
$nonce = isset( $_POST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ) : '';
|
||||
if ( ! wp_verify_nonce( $nonce, 'update-tag_' . $term_id ) && ! wp_verify_nonce( $nonce, 'add-tag' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( chrnx_get_show_meta_definitions() as $meta_key => $sanitize ) {
|
||||
if ( ! isset( $_POST[ $meta_key ] ) ) {
|
||||
continue;
|
||||
}
|
||||
$value = call_user_func( $sanitize, wp_unslash( $_POST[ $meta_key ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized by the mapped callback.
|
||||
if ( '' === $value ) {
|
||||
delete_term_meta( $term_id, $meta_key );
|
||||
continue;
|
||||
}
|
||||
update_term_meta( $term_id, $meta_key, $value );
|
||||
}
|
||||
}
|
||||
add_action( 'edited_chrnx_show', 'chrnx_save_show_meta' );
|
||||
add_action( 'created_chrnx_show', 'chrnx_save_show_meta' );
|
||||
@@ -23,6 +23,7 @@
|
||||
<!-- wp:html --><div class="chrnx-character-stage__art"><?php echo chrnx_get_topic_portrait_markup( 'podcasts', '', 'chrnx-podcast-landing__art chrnx-section-portrait' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?></div><!-- /wp:html -->
|
||||
</div>
|
||||
<!-- /wp:group -->
|
||||
<!-- wp:chrnx/show-links {"show":"silicon-ranch"} /-->
|
||||
<!-- wp:chrnx/latest-podcast /-->
|
||||
<!-- wp:group {"metadata":{"name":"chrnx/podcast-show-discovery"},"layout":{"type":"constrained"}} --><div class="wp-block-group"></div><!-- /wp:group -->
|
||||
<!-- wp:group {"metadata":{"name":"chrnx/podcast-archive"},"layout":{"type":"constrained"}} --><div class="wp-block-group"></div><!-- /wp:group -->
|
||||
|
||||
Reference in new issue
Block a user