feat: give releases and tracks their own pages

Albums were three hardcoded cards. An album is a chrnx_release term
now, with cover, status and listening links; its archive is the album
page with an ordered tracklist. A song is a post carrying lyrics and
notes, its track number, and the audio.

The player is a native audio element, no library and no JavaScript.
Platform icons render only when a URL exists, so nothing points at a
service the release is not on yet.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
chrnxandClaude Opus 5 committed 2026-08-13 19:41:36 -05:00
1 parent a142ece51d
commit 20c47c927a
13 files changed
+867 -16

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
( function () {
'use strict';
function initialize( doc, media ) {
const input = doc.querySelector( '[data-chrnx-release-cover]' );
const button = doc.querySelector( '[data-chrnx-release-cover-pick]' );
const preview = doc.querySelector( '[data-chrnx-release-cover-preview]' );
if ( ! input || ! button || ! preview || typeof media !== 'function' ) {
return false;
}
let frame = null;
button.addEventListener( 'click', function () {
if ( ! frame ) {
frame = media( {
title: button.textContent,
library: { type: 'image' },
multiple: false,
} );
frame.on( 'select', function () {
const attachment = frame.state().get( 'selection' ).first().toJSON();
input.value = attachment.id;
const source = attachment.sizes?.medium?.url || attachment.url;
preview.innerHTML = '';
const image = doc.createElement( 'img' );
image.src = source;
image.alt = attachment.alt || '';
image.style.maxWidth = '240px';
image.style.height = 'auto';
preview.append( image );
} );
}
frame.open();
} );
return true;
}
if ( typeof module !== 'undefined' && module.exports ) {
module.exports = { initialize };
} else if ( typeof document !== 'undefined' ) {
const start = function () {
initialize( document, window.wp && window.wp.media );
};
if ( document.readyState === 'loading' ) {
document.addEventListener( 'DOMContentLoaded', start, { once: true } );
} else {
start();
}
}
} )();
+165
View File
@@ -0,0 +1,165 @@
( function ( factory ) {
if ( typeof module === 'object' && module.exports ) {
module.exports = factory();
} else {
factory().initialize( window.wp );
}
} )( function () {
'use strict';
function platformFields( __ ) {
return [
{ key: 'chrnx_track_url_suno', label: __( 'Suno URL', 'chrnx' ) },
{ key: 'chrnx_track_url_spotify', label: __( 'Spotify URL', 'chrnx' ) },
{ key: 'chrnx_track_url_apple', label: __( 'Apple Music URL', 'chrnx' ) },
];
}
function getTranslator( wp ) {
return wp.i18n && typeof wp.i18n.__ === 'function'
? wp.i18n.__
: function ( text ) {
return text;
};
}
function updateMeta( editPost, currentMeta, key, value ) {
if ( typeof editPost !== 'function' ) {
return;
}
editPost( { meta: { ...( currentMeta || {} ), [ key ]: value } } );
}
function hasRequiredGlobals( wp ) {
return Boolean(
wp &&
wp.components &&
wp.components.TextControl &&
wp.components.Button &&
wp.blockEditor &&
wp.blockEditor.MediaUpload &&
wp.data &&
typeof wp.data.useDispatch === 'function' &&
typeof wp.data.useSelect === 'function' &&
wp.editPost &&
wp.editPost.PluginDocumentSettingPanel &&
wp.element &&
typeof wp.element.createElement === 'function' &&
wp.plugins &&
typeof wp.plugins.registerPlugin === 'function',
);
}
function initialize( wp ) {
if ( ! hasRequiredGlobals( wp ) ) {
return false;
}
const __ = getTranslator( wp );
const el = wp.element.createElement;
function TrackPanel() {
const editorState = wp.data.useSelect( function ( select ) {
if ( typeof select !== 'function' ) {
return null;
}
const currentEditor = select( 'core/editor' );
const core = select( 'core' );
if (
! currentEditor ||
typeof currentEditor.getCurrentPostType !== 'function' ||
typeof currentEditor.getEditedPostAttribute !== 'function' ||
! core ||
typeof core.getEntityRecord !== 'function'
) {
return null;
}
const topicIds = currentEditor.getEditedPostAttribute( 'topic' );
return {
meta: currentEditor.getEditedPostAttribute( 'meta' ) || {},
postType: currentEditor.getCurrentPostType(),
topic:
Array.isArray( topicIds ) && topicIds.length === 1
? core.getEntityRecord( 'taxonomy', 'chrnx_topic', topicIds[ 0 ] )
: null,
};
}, [] );
const editorDispatch = wp.data.useDispatch( 'core/editor' );
if ( ! editorState || editorState.postType !== 'post' || ! editorDispatch?.editPost ) {
return null;
}
if ( ! editorState.topic || editorState.topic.slug !== 'music' ) {
return null;
}
const meta = editorState.meta;
const setMeta = function ( key, value ) {
updateMeta( editorDispatch.editPost, meta, key, value );
};
return el(
wp.editPost.PluginDocumentSettingPanel,
{ name: 'chrnx-track', title: __( 'Track', 'chrnx' ) },
el( wp.components.TextControl, {
label: __( 'Track number', 'chrnx' ),
type: 'number',
min: 0,
value: meta.chrnx_track_number ?? '',
onChange( value ) {
const number = Number.parseInt( value, 10 );
setMeta( 'chrnx_track_number', Number.isInteger( number ) ? Math.max( 0, number ) : 0 );
},
} ),
el( wp.blockEditor.MediaUpload, {
allowedTypes: [ 'audio' ],
value: meta.chrnx_track_audio || 0,
onSelect( attachment ) {
setMeta( 'chrnx_track_audio', attachment?.id ? Number( attachment.id ) : 0 );
},
render( { open } ) {
return el(
wp.components.Button,
{ variant: 'secondary', onClick: open },
meta.chrnx_track_audio
? __( 'Replace audio file', 'chrnx' )
: __( 'Select audio file', 'chrnx' ),
);
},
} ),
meta.chrnx_track_audio
? el(
wp.components.Button,
{
variant: 'link',
isDestructive: true,
onClick() {
setMeta( 'chrnx_track_audio', 0 );
},
},
__( 'Remove audio file', 'chrnx' ),
)
: null,
...platformFields( __ ).map( function ( platform ) {
return el( wp.components.TextControl, {
key: platform.key,
label: platform.label,
type: 'url',
value: meta[ platform.key ] || '',
onChange( value ) {
setMeta( platform.key, value );
},
} );
} ),
);
}
wp.plugins.registerPlugin( 'chrnx-track-meta', { render: TrackPanel } );
return true;
}
return { initialize, updateMeta, platformFields };
} );
+15
View File
@@ -0,0 +1,15 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "chrnx/release-detail",
"version": "0.2.0",
"title": "Release Detail",
"category": "theme",
"description": "Album cover, listening links, and the ordered tracklist.",
"textdomain": "chrnx",
"attributes": {
"headingLevel": { "type": "integer", "default": 2, "enum": [2, 3, 4, 5, 6] }
},
"supports": { "html": false },
"render": "file:./render.php"
}
+67
View File
@@ -0,0 +1,67 @@
<?php
/**
* Release Detail block render.
*
* @package CHRNX
*/
$chrnx_term = get_queried_object();
if ( ! $chrnx_term instanceof WP_Term || 'chrnx_release' !== $chrnx_term->taxonomy ) {
return;
}
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_release_status', true );
$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_release_cover', true ) );
$chrnx_links = chrnx_get_release_links( $chrnx_term->term_id );
$chrnx_tracks = chrnx_get_release_track_ids( $chrnx_term->slug );
$chrnx_track_h = min( 6, $chrnx_heading + 1 );
// Without status, description or links there is no second column to fill.
$chrnx_has_intro = '' !== $chrnx_status || '' !== $chrnx_term->description || ! empty( $chrnx_links );
$chrnx_head_class = 'chrnx-release-detail__head' . ( $chrnx_has_intro ? '' : ' is-bare' );
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-release-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<div class="<?php echo esc_attr( $chrnx_head_class ); ?>">
<div class="chrnx-release-detail__art">
<?php if ( $chrnx_cover > 0 ) : ?>
<?php echo wp_get_attachment_image( $chrnx_cover, 'large', false, array( 'class' => 'chrnx-release-detail__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php else : ?>
<?php echo chrnx_get_topic_portrait_markup( 'placeholder-release', '', 'chrnx-release-detail__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?>
<?php endif; ?>
</div>
<div class="chrnx-release-detail__intro">
<?php if ( '' !== $chrnx_status ) : ?>
<p class="chrnx-release-detail__status"><?php echo esc_html( $chrnx_status ); ?></p>
<?php endif; ?>
<?php if ( '' !== $chrnx_term->description ) : ?>
<p class="chrnx-release-detail__description"><?php echo esc_html( $chrnx_term->description ); ?></p>
<?php endif; ?>
<?php echo chrnx_get_platform_links_markup( $chrnx_links, 'chrnx-platform-links' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
</div>
<?php if ( empty( $chrnx_tracks ) ) : ?>
<p class="chrnx-release-detail__empty"><?php echo esc_html__( 'No published tracks yet.', 'chrnx' ); ?></p>
<?php else : ?>
<ol class="chrnx-tracklist">
<?php
foreach ( $chrnx_tracks as $chrnx_index => $chrnx_track_id ) :
$chrnx_number = absint( get_post_meta( $chrnx_track_id, 'chrnx_track_number', true ) );
$chrnx_player = chrnx_get_track_player_markup( $chrnx_track_id );
?>
<li class="chrnx-tracklist__item">
<span class="chrnx-tracklist__number" aria-hidden="true"><?php echo esc_html( str_pad( (string) ( $chrnx_number > 0 ? $chrnx_number : $chrnx_index + 1 ), 2, '0', STR_PAD_LEFT ) ); ?></span>
<?php if ( '' !== $chrnx_player ) : ?>
<div class="chrnx-tracklist__player"><?php echo $chrnx_player; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
<?php endif; ?>
<div class="chrnx-tracklist__body">
<h<?php echo esc_attr( $chrnx_track_h ); ?> class="chrnx-tracklist__title">
<a href="<?php echo esc_url( get_permalink( $chrnx_track_id ) ); ?>"><?php echo esc_html( get_the_title( $chrnx_track_id ) ); ?></a>
</h<?php echo esc_attr( $chrnx_track_h ); ?>>
<?php echo chrnx_get_platform_links_markup( chrnx_get_track_links( $chrnx_track_id ), 'chrnx-platform-links' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
</section>
+15
View File
@@ -0,0 +1,15 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "chrnx/release-list",
"version": "0.2.0",
"title": "Release List",
"category": "theme",
"description": "The No Names releases, each linking to its album page.",
"textdomain": "chrnx",
"attributes": {
"headingLevel": { "type": "integer", "default": 4, "enum": [2, 3, 4, 5, 6] }
},
"supports": { "html": false },
"render": "file:./render.php"
}
+48
View File
@@ -0,0 +1,48 @@
<?php
/**
* Release List block render.
*
* @package CHRNX
*/
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 4, 4 );
$chrnx_terms = get_terms(
array(
'taxonomy' => 'chrnx_release',
'hide_empty' => false,
)
);
if ( is_wp_error( $chrnx_terms ) || empty( $chrnx_terms ) ) {
return;
}
?>
<div <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-release-list' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<?php
foreach ( $chrnx_terms as $chrnx_term ) :
$chrnx_link = get_term_link( $chrnx_term );
$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_release_status', true );
$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_release_cover', true ) );
$chrnx_links = chrnx_get_release_links( $chrnx_term->term_id );
?>
<article class="chrnx-release-card">
<?php if ( ! is_wp_error( $chrnx_link ) ) : ?>
<a class="chrnx-release-card__link" href="<?php echo esc_url( $chrnx_link ); ?>">
<?php endif; ?>
<span class="chrnx-release-card__art">
<?php if ( $chrnx_cover > 0 ) : ?>
<?php echo wp_get_attachment_image( $chrnx_cover, 'chrnx-card', false, array( 'class' => 'chrnx-release-card__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php else : ?>
<?php echo chrnx_get_topic_portrait_markup( 'placeholder-release', '', 'chrnx-release-card__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?>
<?php endif; ?>
</span>
<h<?php echo esc_attr( $chrnx_heading ); ?> class="chrnx-release-card__title"><?php echo esc_html( $chrnx_term->name ); ?></h<?php echo esc_attr( $chrnx_heading ); ?>>
<?php if ( '' !== $chrnx_status ) : ?>
<p class="chrnx-release-card__status"><?php echo esc_html( $chrnx_status ); ?></p>
<?php endif; ?>
<?php if ( ! is_wp_error( $chrnx_link ) ) : ?>
</a>
<?php endif; ?>
<?php echo chrnx_get_platform_links_markup( $chrnx_links, 'chrnx-platform-links' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</article>
<?php endforeach; ?>
</div>
+12
View File
@@ -0,0 +1,12 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "chrnx/track-meta",
"version": "0.2.0",
"title": "Track Meta",
"category": "theme",
"description": "Player, listening links, and album for one song.",
"textdomain": "chrnx",
"supports": { "html": false },
"render": "file:./render.php"
}
+46
View File
@@ -0,0 +1,46 @@
<?php
/**
* Track Meta block render.
*
* @package CHRNX
*/
$chrnx_post_id = isset( $block->context['postId'] ) ? absint( $block->context['postId'] ) : get_the_ID();
if ( ! chrnx_is_eligible_editorial_post( $chrnx_post_id ) ) {
return;
}
$chrnx_release = chrnx_get_track_release( $chrnx_post_id );
$chrnx_player = chrnx_get_track_player_markup( $chrnx_post_id );
$chrnx_links = chrnx_get_track_links( $chrnx_post_id );
$chrnx_number = absint( get_post_meta( $chrnx_post_id, 'chrnx_track_number', true ) );
// Nothing invented: without any track data this block stays silent.
if ( null === $chrnx_release && '' === $chrnx_player && empty( $chrnx_links ) ) {
return;
}
$chrnx_release_link = null !== $chrnx_release ? get_term_link( $chrnx_release ) : null;
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-track-meta' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> aria-label="<?php echo esc_attr__( 'Track details', 'chrnx' ); ?>">
<?php if ( '' !== $chrnx_player ) : ?>
<div class="chrnx-track-meta__player"><?php echo $chrnx_player; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
<?php endif; ?>
<div class="chrnx-track-meta__facts">
<?php if ( null !== $chrnx_release && ! is_wp_error( $chrnx_release_link ) ) : ?>
<p class="chrnx-track-meta__release">
<span class="chrnx-track-meta__label"><?php echo esc_html__( 'From', 'chrnx' ); ?></span>
<a href="<?php echo esc_url( $chrnx_release_link ); ?>"><?php echo esc_html( $chrnx_release->name ); ?></a>
<?php if ( $chrnx_number > 0 ) : ?>
<span class="chrnx-track-meta__number">
<?php
/* translators: %d: track number within the album. */
echo esc_html( sprintf( __( 'Track %d', 'chrnx' ), $chrnx_number ) );
?>
</span>
<?php endif; ?>
</p>
<?php endif; ?>
<?php echo chrnx_get_platform_links_markup( $chrnx_links, 'chrnx-platform-links' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
</section>
+258
View File
@@ -0,0 +1,258 @@
<?php
/**
* Release (album) term metadata and shared platform links.
*
* @package CHRNX
*/
/**
* Return the supported streaming platforms in display order.
*
* @return array<string,array<string,string>> Platform key to label and icon path data.
*/
function chrnx_get_release_platforms() {
return array(
'suno' => array(
'label' => __( 'Suno', 'chrnx' ),
'icon' => '<path d="M12 3a9 9 0 1 0 9 9"/><path d="M8 12a4 4 0 1 0 4-4"/>',
),
'spotify' => array(
'label' => __( 'Spotify', 'chrnx' ),
'icon' => '<circle cx="12" cy="12" r="9"/><path d="M7.5 9.5c3-.8 6.2-.5 8.8 1M8 12.6c2.4-.6 5-.4 7.2.9M8.6 15.6c1.9-.5 4-.3 5.7.7"/>',
),
'apple' => array(
'label' => __( 'Apple Music', 'chrnx' ),
'icon' => '<path d="M9 18V6.5l9-1.5V16"/><circle cx="7" cy="18" r="2"/><circle cx="16" cy="16" r="2"/>',
),
);
}
/**
* Sanitize an external listening URL and require HTTPS.
*
* @param mixed $value Submitted value.
* @return string Valid HTTPS URL or an empty string.
*/
function chrnx_sanitize_https_url( $value ) {
if ( ! is_string( $value ) ) {
return '';
}
$url = esc_url_raw( trim( $value ) );
$scheme = wp_parse_url( $url, PHP_URL_SCHEME );
$host = wp_parse_url( $url, PHP_URL_HOST );
return '' !== $url && 'https' === $scheme && ! empty( $host ) ? $url : '';
}
/**
* Return the release term meta keys and their sanitizers.
*
* @return array<string,callable-string> Meta key to sanitize callback.
*/
function chrnx_get_release_meta_definitions() {
$definitions = array(
'chrnx_release_cover' => 'absint',
'chrnx_release_status' => 'sanitize_text_field',
);
foreach ( array_keys( chrnx_get_release_platforms() ) as $platform ) {
$definitions[ 'chrnx_release_url_' . $platform ] = 'chrnx_sanitize_https_url';
}
return $definitions;
}
/**
* Require permission to manage release term metadata.
*
* @return bool Whether the current user can manage categories.
*/
function chrnx_auth_release_meta() {
return current_user_can( 'manage_categories' );
}
/**
* Register release term metadata.
*/
function chrnx_register_release_meta() {
foreach ( chrnx_get_release_meta_definitions() as $meta_key => $sanitize ) {
register_term_meta(
'chrnx_release',
$meta_key,
array(
'type' => 'chrnx_release_cover' === $meta_key ? 'integer' : 'string',
'single' => true,
'show_in_rest' => true,
'sanitize_callback' => $sanitize,
'auth_callback' => 'chrnx_auth_release_meta',
)
);
}
}
add_action( 'init', 'chrnx_register_release_meta' );
/**
* Return the stored external links for one release term.
*
* @param int $term_id Release term ID.
* @return array<string,string> Platform key to URL, omitting empty ones.
*/
function chrnx_get_release_links( $term_id ) {
$links = array();
foreach ( array_keys( chrnx_get_release_platforms() ) as $platform ) {
$url = chrnx_sanitize_https_url( get_term_meta( $term_id, 'chrnx_release_url_' . $platform, true ) );
if ( '' !== $url ) {
$links[ $platform ] = $url;
}
}
return $links;
}
/**
* 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.
* @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();
$items = '';
foreach ( $links as $platform => $url ) {
if ( ! isset( $platforms[ $platform ] ) ) {
continue;
}
$items .= sprintf(
// The icon path data is a fixed literal, never user input.
'<li><a class="%1$s__link" href="%2$s" target="_blank" rel="noopener noreferrer external"><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">%3$s</svg><span class="chrnx-screen-reader-text">%4$s</span></a></li>',
esc_attr( $class_name ),
esc_url( $url ),
$platforms[ $platform ]['icon'], // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
esc_html( $platforms[ $platform ]['label'] )
);
}
if ( '' === $items ) {
return '';
}
return '<ul class="' . esc_attr( $class_name ) . '">' . $items . '</ul>';
}
/**
* Print one release meta field row for the term edit screen.
*
* @param string $meta_key Meta key.
* @param string $label Field label.
* @param string $value Current value.
* @param string $type Input type.
* @param string $help Optional description.
*/
function chrnx_print_release_field( $meta_key, $label, $value, $type = 'url', $help = '' ) {
printf(
'<tr class="form-field"><th scope="row"><label for="%1$s">%2$s</label></th><td><input name="%1$s" id="%1$s" type="%3$s" value="%4$s" class="regular-text"%5$s>%6$s</td></tr>',
esc_attr( $meta_key ),
esc_html( $label ),
esc_attr( $type ),
esc_attr( $value ),
'chrnx_release_cover' === $meta_key ? ' data-chrnx-release-cover' : '',
'' !== $help ? '<p class="description">' . esc_html( $help ) . '</p>' : ''
);
}
/**
* Render the release metadata fields on the term edit screen.
*
* @param WP_Term $term Release term.
*/
function chrnx_render_release_edit_fields( $term ) {
$cover_id = absint( get_term_meta( $term->term_id, 'chrnx_release_cover', true ) );
chrnx_print_release_field(
'chrnx_release_cover',
__( 'Cover image ID', 'chrnx' ),
(string) ( $cover_id > 0 ? $cover_id : '' ),
'number',
__( 'Media library attachment ID for the album artwork.', 'chrnx' )
);
echo '<tr class="form-field"><th scope="row"></th><td>';
echo '<button type="button" class="button" data-chrnx-release-cover-pick>' . esc_html__( 'Select cover', 'chrnx' ) . '</button>';
echo '<div data-chrnx-release-cover-preview>';
if ( $cover_id > 0 ) {
echo wp_get_attachment_image( $cover_id, 'medium' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Core returns escaped markup.
}
echo '</div></td></tr>';
chrnx_print_release_field(
'chrnx_release_status',
__( 'Status', 'chrnx' ),
(string) get_term_meta( $term->term_id, 'chrnx_release_status', true ),
'text',
__( 'Shown under the title, for example: 13-track debut album — in production.', 'chrnx' )
);
foreach ( chrnx_get_release_platforms() as $platform => $definition ) {
chrnx_print_release_field(
'chrnx_release_url_' . $platform,
/* translators: %s: streaming platform name. */
sprintf( __( '%s URL', 'chrnx' ), $definition['label'] ),
(string) get_term_meta( $term->term_id, 'chrnx_release_url_' . $platform, true ),
'url',
__( 'HTTPS only. Leave empty to hide this icon.', 'chrnx' )
);
}
}
add_action( 'chrnx_release_edit_form_fields', 'chrnx_render_release_edit_fields' );
/**
* Persist release term metadata from the term edit screen.
*
* @param int $term_id Release term ID.
*/
function chrnx_save_release_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_release_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 || 0 === $value ) {
delete_term_meta( $term_id, $meta_key );
continue;
}
update_term_meta( $term_id, $meta_key, $value );
}
}
add_action( 'edited_chrnx_release', 'chrnx_save_release_meta' );
add_action( 'created_chrnx_release', 'chrnx_save_release_meta' );
/**
* Enqueue the media picker only on the release term screen.
*
* @param string $hook_suffix Current admin page.
*/
function chrnx_enqueue_release_admin_assets( $hook_suffix ) {
$taxonomy = isset( $_GET['taxonomy'] ) ? sanitize_key( wp_unslash( $_GET['taxonomy'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only screen routing.
if ( ! in_array( $hook_suffix, array( 'term.php', 'edit-tags.php' ), true ) || 'chrnx_release' !== $taxonomy ) {
return;
}
wp_enqueue_media();
wp_enqueue_script(
'chrnx-admin-release',
get_theme_file_uri( 'assets/js/admin-release.js' ),
array( 'media-editor' ),
CHRNX_VERSION,
true
);
}
add_action( 'admin_enqueue_scripts', 'chrnx_enqueue_release_admin_assets' );
+177
View File
@@ -0,0 +1,177 @@
<?php
/**
* Track (song) post metadata.
*
* @package CHRNX
*/
/**
* Require permission to edit the post owning track metadata.
*
* @param bool $allowed Previously calculated permission.
* @param string $meta_key Metadata key.
* @param int $post_id Post ID.
* @return bool Whether the current user can edit the post.
*/
function chrnx_auth_track_meta( $allowed, $meta_key, $post_id ) {
return current_user_can( 'edit_post', $post_id );
}
/**
* Return the track meta keys and their sanitizers.
*
* @return array<string,callable-string> Meta key to sanitize callback.
*/
function chrnx_get_track_meta_definitions() {
$definitions = array(
'chrnx_track_number' => 'absint',
'chrnx_track_audio' => 'absint',
);
foreach ( array_keys( chrnx_get_release_platforms() ) as $platform ) {
$definitions[ 'chrnx_track_url_' . $platform ] = 'chrnx_sanitize_https_url';
}
return $definitions;
}
/**
* Register track metadata for posts.
*/
function chrnx_register_track_meta() {
foreach ( chrnx_get_track_meta_definitions() as $meta_key => $sanitize ) {
$is_number = in_array( $meta_key, array( 'chrnx_track_number', 'chrnx_track_audio' ), true );
register_post_meta(
'post',
$meta_key,
array(
'type' => $is_number ? 'integer' : 'string',
'single' => true,
'show_in_rest' => array(
'schema' => $is_number
? array(
'type' => 'integer',
'minimum' => 0,
)
: array( 'type' => 'string' ),
),
'sanitize_callback' => $sanitize,
'auth_callback' => 'chrnx_auth_track_meta',
)
);
}
}
add_action( 'init', 'chrnx_register_track_meta' );
/**
* Return the stored external links for one track.
*
* @param int $post_id Track post ID.
* @return array<string,string> Platform key to URL, omitting empty ones.
*/
function chrnx_get_track_links( $post_id ) {
$links = array();
foreach ( array_keys( chrnx_get_release_platforms() ) as $platform ) {
$url = chrnx_sanitize_https_url( get_post_meta( $post_id, 'chrnx_track_url_' . $platform, true ) );
if ( '' !== $url ) {
$links[ $platform ] = $url;
}
}
return $links;
}
/**
* Return the playable audio source for one track.
*
* @param int $post_id Track post ID.
* @return string Audio URL, or an empty string when nothing is attached.
*/
function chrnx_get_track_audio_url( $post_id ) {
$attachment_id = absint( get_post_meta( $post_id, 'chrnx_track_audio', true ) );
if ( 0 === $attachment_id || 'attachment' !== get_post_type( $attachment_id ) ) {
return '';
}
if ( 0 !== strpos( (string) get_post_mime_type( $attachment_id ), 'audio/' ) ) {
return '';
}
$url = wp_get_attachment_url( $attachment_id );
return is_string( $url ) ? $url : '';
}
/**
* Render the native mini player for one track, or nothing without audio.
*
* @param int $post_id Track post ID.
* @return string Escaped markup or an empty string.
*/
function chrnx_get_track_player_markup( $post_id ) {
$src = chrnx_get_track_audio_url( $post_id );
if ( '' === $src ) {
return '';
}
// ponytail: native <audio>, no player library. Controls are styled with CSS.
return sprintf(
'<audio class="chrnx-track-player" controls preload="none" src="%1$s" aria-label="%2$s"></audio>',
esc_url( $src ),
/* translators: %s: track title. */
esc_attr( sprintf( __( 'Play %s', 'chrnx' ), get_the_title( $post_id ) ) )
);
}
/**
* Return the release term assigned to one track.
*
* @param int $post_id Track post ID.
* @return WP_Term|null Release term or null.
*/
function chrnx_get_track_release( $post_id ) {
$terms = get_the_terms( $post_id, 'chrnx_release' );
if ( is_wp_error( $terms ) || empty( $terms ) ) {
return null;
}
$term = reset( $terms );
return $term instanceof WP_Term ? $term : null;
}
/**
* Return the ordered track IDs for one release.
*
* @param string $release_slug Release term slug.
* @param int $limit Maximum tracks, bounded to 60.
* @return int[] Track post IDs ordered by stored track number.
*/
function chrnx_get_release_track_ids( string $release_slug, int $limit = 30 ): array {
$slug = chrnx_validate_editorial_term_slug( $release_slug, 'chrnx_release' );
if ( '' === $slug ) {
return array();
}
$query = chrnx_run_eligible_query(
array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => min( 60, max( 1, $limit ) ),
'orderby' => array(
'meta_value_num' => 'ASC',
'date' => 'ASC',
),
'meta_key' => 'chrnx_track_number', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Tracklist order is the feature.
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'fields' => 'ids',
'suppress_filters' => false,
'chrnx_require_nonempty_title' => true,
'tax_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Scoped to one release.
array(
'taxonomy' => 'chrnx_release',
'field' => 'slug',
'terms' => $slug,
),
),
)
);
return array_values( array_map( 'absint', $query->posts ) );
}
+2 -8
View File
@@ -13,17 +13,11 @@
<section class="wp-block-group chrnx-home-projects">
<!-- wp:group {"className":"chrnx-character-stage","layout":{"type":"constrained"}} -->
<div class="wp-block-group chrnx-character-stage">
<!-- wp:html --><div class="chrnx-character-stage__atmosphere" aria-hidden="true"><?php echo chrnx_get_topic_portrait_markup( 'research', '', 'chrnx-character-stage__secondary-art' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?></div><!-- /wp:html -->
<!-- wp:html --><div class="chrnx-character-stage__atmosphere" aria-hidden="true"><?php echo chrnx_get_atmosphere_markup( 'projects-grunge', 'chrnx-character-stage__backdrop' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?><?php echo chrnx_get_topic_portrait_markup( 'research', '', 'chrnx-character-stage__secondary-art' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?></div><!-- /wp:html -->
<!-- wp:group {"className":"chrnx-character-stage__content","layout":{"type":"constrained"}} -->
<div class="wp-block-group chrnx-character-stage__content">
<!-- wp:heading --><h2 class="wp-block-heading"><?php echo esc_html__( 'Selected work', 'chrnx' ); ?></h2><!-- /wp:heading -->
<!-- wp:columns -->
<div class="wp-block-columns">
<!-- wp:column --><div class="wp-block-column"><!-- wp:heading {"level":3} --><h3 class="wp-block-heading"><?php echo esc_html__( 'Expressive Tea', 'chrnx' ); ?></h3><!-- /wp:heading --></div><!-- /wp:column -->
<!-- wp:column --><div class="wp-block-column"><!-- wp:heading {"level":3} --><h3 class="wp-block-heading"><?php echo esc_html__( 'Ailed', 'chrnx' ); ?></h3><!-- /wp:heading --></div><!-- /wp:column -->
<!-- wp:column --><div class="wp-block-column"><!-- wp:heading {"level":3} --><h3 class="wp-block-heading"><?php echo esc_html__( 'Published research', 'chrnx' ); ?></h3><!-- /wp:heading --></div><!-- /wp:column -->
</div>
<!-- /wp:columns -->
<!-- wp:chrnx/selected-work /-->
</div>
<!-- /wp:group -->
<!-- wp:html --><div class="chrnx-character-stage__art"><?php echo chrnx_get_topic_portrait_markup( 'code', '', 'chrnx-section-portrait' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?></div><!-- /wp:html -->
+2 -8
View File
@@ -24,14 +24,8 @@
<!-- wp:html --><div class="chrnx-character-stage__art"><?php echo chrnx_get_topic_portrait_markup( 'music', __( 'The No Names musician portrait', 'chrnx' ), 'chrnx-music-landing__portrait' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?></div><!-- /wp:html -->
</div>
<!-- /wp:group -->
<!-- wp:paragraph --><p><?php echo esc_html__( 'El proceso usa generative AI anclada en la voz humana real de Chrnx. Es una herramienta de producción, no una mitología ficticia ni una promesa sobre lo que la tecnología puede hacer.', 'chrnx' ); ?></p><!-- /wp:paragraph -->
<!-- wp:paragraph {"className":"chrnx-music-note"} --><p class="chrnx-music-note"><?php echo esc_html__( 'El proceso usa generative AI anclada en la voz humana real de Chrnx. Es una herramienta de producción, no una mitología ficticia ni una promesa sobre lo que la tecnología puede hacer.', 'chrnx' ); ?></p><!-- /wp:paragraph -->
<!-- wp:heading {"level":3} --><h3 class="wp-block-heading"><?php echo esc_html__( 'Releases in progress', 'chrnx' ); ?></h3><!-- /wp:heading -->
<!-- wp:group {"className":"chrnx-release-list","layout":{"type":"grid","minimumColumnWidth":"18rem"}} -->
<div class="wp-block-group chrnx-release-list">
<!-- wp:group {"tagName":"article","className":"chrnx-release-card"} --><article class="wp-block-group chrnx-release-card"><!-- wp:heading {"level":4} --><h4 class="wp-block-heading"><?php echo esc_html__( 'El Hermoso Caos que habita en mi cabeza', 'chrnx' ); ?></h4><!-- /wp:heading --><!-- wp:paragraph --><p><?php echo esc_html__( '13-track debut album — draft/in production', 'chrnx' ); ?></p><!-- /wp:paragraph --></article><!-- /wp:group -->
<!-- wp:group {"tagName":"article","className":"chrnx-release-card"} --><article class="wp-block-group chrnx-release-card"><!-- wp:heading {"level":4} --><h4 class="wp-block-heading"><?php echo esc_html__( 'Ando Bien Arriba', 'chrnx' ); ?></h4><!-- /wp:heading --><!-- wp:paragraph --><p><?php echo esc_html__( 'six-track bright mirrored EP — draft/in production', 'chrnx' ); ?></p><!-- /wp:paragraph --></article><!-- /wp:group -->
<!-- wp:group {"tagName":"article","className":"chrnx-release-card"} --><article class="wp-block-group chrnx-release-card"><!-- wp:heading {"level":4} --><h4 class="wp-block-heading"><?php echo esc_html__( 'Aquí se Rompió una Jerga', 'chrnx' ); ?></h4><!-- /wp:heading --><!-- wp:paragraph --><p><?php echo esc_html__( 'six-track dark mirrored EP — draft/in production', 'chrnx' ); ?></p><!-- /wp:paragraph --></article><!-- /wp:group -->
</div>
<!-- /wp:group -->
<!-- wp:chrnx/release-list /-->
</section>
<!-- /wp:group -->
+10
View File
@@ -0,0 +1,10 @@
<!-- wp:template-part {"slug":"header","tagName":"header"} /-->
<!-- wp:group {"tagName":"main","anchor":"chrnx-main","className":"chrnx-archive chrnx-release-archive","layout":{"type":"constrained"}} -->
<main id="chrnx-main" class="wp-block-group chrnx-archive chrnx-release-archive" tabindex="-1">
<!-- wp:query-title {"type":"archive","level":1,"showPrefix":false} /-->
<!-- wp:chrnx/release-detail /-->
</main>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->