feat: Replace Twig with native PHP templates
All checks were successful
Create Release Package / build-release (push) Successful in 55s

- Remove twig/twig dependency from composer.json
- Convert all 25 Twig templates to native PHP templates
- New render() method in Plugin.php using PHP include with output buffering
- New render_partial() helper method for including partials
- Templates support theme overrides via fedistream/ directory
- Reduced plugin size by eliminating Twig and its dependencies

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-02 22:48:10 +01:00
parent 6e45b0b6f1
commit 379fd23be0
57 changed files with 1928 additions and 1559 deletions

View File

@@ -0,0 +1,50 @@
<?php
/**
* Album card partial template.
*
* @package WP_FediStream
*
* @var array $post Album data array.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<article class="fedistream-card fedistream-card--album">
<a href="<?php echo esc_url( $post['permalink'] ?? '' ); ?>" class="fedistream-card__link">
<div class="fedistream-card__image fedistream-card__image--square">
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="<?php echo esc_attr( $post['title'] ?? '' ); ?>" loading="lazy">
<?php else : ?>
<div class="fedistream-card__placeholder fedistream-card__placeholder--album">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 14.5c-2.49 0-4.5-2.01-4.5-4.5S9.51 7.5 12 7.5s4.5 2.01 4.5 4.5-2.01 4.5-4.5 4.5zm0-5.5c-.55 0-1 .45-1 1s.45 1 1 1 1-.45 1-1-.45-1-1-1z"/></svg>
</div>
<?php endif; ?>
</div>
<div class="fedistream-card__content">
<h3 class="fedistream-card__title"><?php echo esc_html( $post['title'] ?? '' ); ?></h3>
<?php if ( ! empty( $post['artist_name'] ) ) : ?>
<p class="fedistream-card__artist"><?php echo esc_html( $post['artist_name'] ); ?></p>
<?php endif; ?>
<p class="fedistream-card__meta">
<span class="fedistream-card__type"><?php echo esc_html( $post['album_type_label'] ?? '' ); ?></span>
<?php if ( ! empty( $post['release_year'] ) ) : ?>
<span class="fedistream-card__year"><?php echo esc_html( $post['release_year'] ); ?></span>
<?php endif; ?>
</p>
<?php if ( ! empty( $post['total_tracks'] ) && $post['total_tracks'] > 0 ) : ?>
<p class="fedistream-card__stats">
<?php
printf(
/* translators: %d: number of tracks */
esc_html( _n( '%d track', '%d tracks', $post['total_tracks'], 'wp-fedistream' ) ),
(int) $post['total_tracks']
);
?>
</p>
<?php endif; ?>
</div>
</a>
</article>

View File

@@ -1,31 +0,0 @@
{# Album card partial #}
<article class="fedistream-card fedistream-card--album">
<a href="{{ post.permalink }}" class="fedistream-card__link">
<div class="fedistream-card__image fedistream-card__image--square">
{% if post.thumbnail %}
<img src="{{ post.thumbnail }}" alt="{{ post.title|e('html_attr') }}" loading="lazy">
{% else %}
<div class="fedistream-card__placeholder fedistream-card__placeholder--album">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 14.5c-2.49 0-4.5-2.01-4.5-4.5S9.51 7.5 12 7.5s4.5 2.01 4.5 4.5-2.01 4.5-4.5 4.5zm0-5.5c-.55 0-1 .45-1 1s.45 1 1 1 1-.45 1-1-.45-1-1-1z"/></svg>
</div>
{% endif %}
</div>
<div class="fedistream-card__content">
<h3 class="fedistream-card__title">{{ post.title }}</h3>
{% if post.artist_name %}
<p class="fedistream-card__artist">{{ post.artist_name }}</p>
{% endif %}
<p class="fedistream-card__meta">
<span class="fedistream-card__type">{{ post.album_type_label }}</span>
{% if post.release_year %}
<span class="fedistream-card__year">{{ post.release_year }}</span>
{% endif %}
</p>
{% if post.total_tracks > 0 %}
<p class="fedistream-card__stats">
{{ post.total_tracks }} {{ post.total_tracks == 1 ? 'track' : 'tracks' }}
</p>
{% endif %}
</div>
</a>
</article>

View File

@@ -0,0 +1,47 @@
<?php
/**
* Artist card partial template.
*
* @package WP_FediStream
*
* @var array $post Artist data array.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<article class="fedistream-card fedistream-card--artist">
<a href="<?php echo esc_url( $post['permalink'] ?? '' ); ?>" class="fedistream-card__link">
<div class="fedistream-card__image">
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="<?php echo esc_attr( $post['title'] ?? '' ); ?>" loading="lazy">
<?php else : ?>
<div class="fedistream-card__placeholder fedistream-card__placeholder--artist">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>
</div>
<?php endif; ?>
</div>
<div class="fedistream-card__content">
<h3 class="fedistream-card__title"><?php echo esc_html( $post['title'] ?? '' ); ?></h3>
<p class="fedistream-card__meta">
<span class="fedistream-card__type"><?php echo esc_html( $post['artist_type_label'] ?? '' ); ?></span>
<?php if ( ! empty( $post['location'] ) ) : ?>
<span class="fedistream-card__location"><?php echo esc_html( $post['location'] ); ?></span>
<?php endif; ?>
</p>
<?php if ( isset( $post['album_count'] ) && $post['album_count'] > 0 ) : ?>
<p class="fedistream-card__stats">
<?php
printf(
/* translators: %d: number of albums */
esc_html( _n( '%d album', '%d albums', $post['album_count'], 'wp-fedistream' ) ),
(int) $post['album_count']
);
?>
</p>
<?php endif; ?>
</div>
</a>
</article>

View File

@@ -1,28 +0,0 @@
{# Artist card partial #}
<article class="fedistream-card fedistream-card--artist">
<a href="{{ post.permalink }}" class="fedistream-card__link">
<div class="fedistream-card__image">
{% if post.thumbnail %}
<img src="{{ post.thumbnail }}" alt="{{ post.title|e('html_attr') }}" loading="lazy">
{% else %}
<div class="fedistream-card__placeholder fedistream-card__placeholder--artist">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>
</div>
{% endif %}
</div>
<div class="fedistream-card__content">
<h3 class="fedistream-card__title">{{ post.title }}</h3>
<p class="fedistream-card__meta">
<span class="fedistream-card__type">{{ post.artist_type_label }}</span>
{% if post.location %}
<span class="fedistream-card__location">{{ post.location }}</span>
{% endif %}
</p>
{% if post.album_count is defined and post.album_count > 0 %}
<p class="fedistream-card__stats">
{{ post.album_count }} {{ post.album_count == 1 ? 'album' : 'albums' }}
</p>
{% endif %}
</div>
</a>
</article>

View File

@@ -0,0 +1,54 @@
<?php
/**
* Playlist card partial template.
*
* @package WP_FediStream
*
* @var array $post Playlist data array.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<article class="fedistream-card fedistream-card--playlist">
<a href="<?php echo esc_url( $post['permalink'] ?? '' ); ?>" class="fedistream-card__link">
<div class="fedistream-card__image fedistream-card__image--square">
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="<?php echo esc_attr( $post['title'] ?? '' ); ?>" loading="lazy">
<?php else : ?>
<div class="fedistream-card__placeholder fedistream-card__placeholder--playlist">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M15 6H3v2h12V6zm0 4H3v2h12v-2zM3 16h8v-2H3v2zM17 6v8.18c-.31-.11-.65-.18-1-.18-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3V8h3V6h-5z"/></svg>
</div>
<?php endif; ?>
<?php if ( isset( $post['visibility'] ) && 'private' === $post['visibility'] ) : ?>
<span class="fedistream-card__badge fedistream-card__badge--private">
<svg viewBox="0 0 24 24" fill="currentColor" width="12" height="12"><path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zM9 6c0-1.66 1.34-3 3-3s3 1.34 3 3v2H9V6z"/></svg>
</span>
<?php endif; ?>
</div>
<div class="fedistream-card__content">
<h3 class="fedistream-card__title"><?php echo esc_html( $post['title'] ?? '' ); ?></h3>
<?php if ( ! empty( $post['author'] ) ) : ?>
<p class="fedistream-card__author"><?php echo esc_html( $post['author'] ); ?></p>
<?php endif; ?>
<p class="fedistream-card__meta">
<?php if ( ! empty( $post['track_count'] ) ) : ?>
<span class="fedistream-card__tracks">
<?php
printf(
/* translators: %d: number of tracks */
esc_html( _n( '%d track', '%d tracks', $post['track_count'], 'wp-fedistream' ) ),
(int) $post['track_count']
);
?>
</span>
<?php endif; ?>
<?php if ( ! empty( $post['duration_formatted'] ) ) : ?>
<span class="fedistream-card__duration"><?php echo esc_html( $post['duration_formatted'] ); ?></span>
<?php endif; ?>
</p>
</div>
</a>
</article>

View File

@@ -1,29 +0,0 @@
{# Playlist card partial #}
<article class="fedistream-card fedistream-card--playlist">
<a href="{{ post.permalink }}" class="fedistream-card__link">
<div class="fedistream-card__image fedistream-card__image--square">
{% if post.thumbnail %}
<img src="{{ post.thumbnail }}" alt="{{ post.title|e('html_attr') }}" loading="lazy">
{% else %}
<div class="fedistream-card__placeholder fedistream-card__placeholder--playlist">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M15 6H3v2h12V6zm0 4H3v2h12v-2zM3 16h8v-2H3v2zM17 6v8.18c-.31-.11-.65-.18-1-.18-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3V8h3V6h-5z"/></svg>
</div>
{% endif %}
{% if post.visibility == 'private' %}
<span class="fedistream-card__badge fedistream-card__badge--private">
<svg viewBox="0 0 24 24" fill="currentColor" width="12" height="12"><path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zM9 6c0-1.66 1.34-3 3-3s3 1.34 3 3v2H9V6zm9 14H6V10h12v10zm-6-3c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2z"/></svg>
</span>
{% endif %}
</div>
<div class="fedistream-card__content">
<h3 class="fedistream-card__title">{{ post.title }}</h3>
<p class="fedistream-card__author">{{ post.author }}</p>
<p class="fedistream-card__meta">
<span class="fedistream-card__count">{{ post.track_count }} {{ post.track_count == 1 ? 'track' : 'tracks' }}</span>
{% if post.duration_formatted %}
<span class="fedistream-card__duration">{{ post.duration_formatted }}</span>
{% endif %}
</p>
</div>
</a>
</article>

View File

@@ -0,0 +1,56 @@
<?php
/**
* Track card partial template.
*
* @package WP_FediStream
*
* @var array $post Track data array.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<article class="fedistream-card fedistream-card--track">
<a href="<?php echo esc_url( $post['permalink'] ?? '' ); ?>" class="fedistream-card__link">
<div class="fedistream-card__image fedistream-card__image--square">
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="<?php echo esc_attr( $post['title'] ?? '' ); ?>" loading="lazy">
<?php elseif ( ! empty( $post['album_artwork'] ) ) : ?>
<img src="<?php echo esc_url( $post['album_artwork'] ); ?>" alt="<?php echo esc_attr( $post['title'] ?? '' ); ?>" loading="lazy">
<?php else : ?>
<div class="fedistream-card__placeholder fedistream-card__placeholder--track">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"/></svg>
</div>
<?php endif; ?>
<?php if ( ! empty( $post['explicit'] ) ) : ?>
<span class="fedistream-card__badge fedistream-card__badge--explicit">E</span>
<?php endif; ?>
</div>
<div class="fedistream-card__content">
<h3 class="fedistream-card__title"><?php echo esc_html( $post['title'] ?? '' ); ?></h3>
<?php if ( ! empty( $post['artists'] ) && is_array( $post['artists'] ) ) : ?>
<p class="fedistream-card__artist">
<?php
$artist_names = array_map(
function ( $artist ) {
return esc_html( $artist['name'] ?? '' );
},
$post['artists']
);
echo implode( ', ', $artist_names ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</p>
<?php endif; ?>
<p class="fedistream-card__meta">
<?php if ( ! empty( $post['album_title'] ) ) : ?>
<span class="fedistream-card__album"><?php echo esc_html( $post['album_title'] ); ?></span>
<?php endif; ?>
<?php if ( ! empty( $post['duration_formatted'] ) ) : ?>
<span class="fedistream-card__duration"><?php echo esc_html( $post['duration_formatted'] ); ?></span>
<?php endif; ?>
</p>
</div>
</a>
</article>

View File

@@ -1,37 +0,0 @@
{# Track card partial #}
<article class="fedistream-card fedistream-card--track">
<a href="{{ post.permalink }}" class="fedistream-card__link">
<div class="fedistream-card__image fedistream-card__image--square">
{% if post.thumbnail %}
<img src="{{ post.thumbnail }}" alt="{{ post.title|e('html_attr') }}" loading="lazy">
{% elseif post.album_artwork %}
<img src="{{ post.album_artwork }}" alt="{{ post.title|e('html_attr') }}" loading="lazy">
{% else %}
<div class="fedistream-card__placeholder fedistream-card__placeholder--track">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"/></svg>
</div>
{% endif %}
{% if post.explicit %}
<span class="fedistream-card__badge fedistream-card__badge--explicit">E</span>
{% endif %}
</div>
<div class="fedistream-card__content">
<h3 class="fedistream-card__title">{{ post.title }}</h3>
{% if post.artists %}
<p class="fedistream-card__artist">
{% for artist in post.artists %}
{{ artist.name }}{% if not loop.last %}, {% endif %}
{% endfor %}
</p>
{% endif %}
<p class="fedistream-card__meta">
{% if post.album_title %}
<span class="fedistream-card__album">{{ post.album_title }}</span>
{% endif %}
{% if post.duration_formatted %}
<span class="fedistream-card__duration">{{ post.duration_formatted }}</span>
{% endif %}
</p>
</div>
</a>
</article>