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,49 @@
<?php
/**
* Album archive template.
*
* @package WP_FediStream
*
* @var array $posts Array of album data.
* @var string $archive_title Archive title.
* @var string $archive_description Archive description.
* @var array $pagination Pagination data.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$plugin = \WP_FediStream\Plugin::get_instance();
?>
<div class="fedistream-archive fedistream-archive--albums">
<header class="fedistream-archive__header">
<h1 class="fedistream-archive__title"><?php esc_html_e( 'Albums', 'wp-fedistream' ); ?></h1>
<?php if ( ! empty( $archive_description ) ) : ?>
<div class="fedistream-archive__description"><?php echo wp_kses_post( $archive_description ); ?></div>
<?php endif; ?>
</header>
<?php if ( ! empty( $posts ) && is_array( $posts ) ) : ?>
<div class="fedistream-grid fedistream-grid--albums">
<?php foreach ( $posts as $post ) : ?>
<?php echo $plugin->render_partial( 'partials/card-album', array( 'post' => $post ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php endforeach; ?>
</div>
<?php if ( ! empty( $pagination['links'] ) ) : ?>
<nav class="fedistream-pagination">
<?php
foreach ( $pagination['links'] as $link ) {
echo $link; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
</nav>
<?php endif; ?>
<?php else : ?>
<div class="fedistream-empty">
<p><?php esc_html_e( 'No albums found.', 'wp-fedistream' ); ?></p>
</div>
<?php endif; ?>
</div>

View File

@@ -1,27 +0,0 @@
{# Album archive template #}
<div class="fedistream-archive fedistream-archive--albums">
<header class="fedistream-archive__header">
<h1 class="fedistream-archive__title">{{ __('Albums', 'wp-fedistream') }}</h1>
{% if archive_description %}
<div class="fedistream-archive__description">{{ archive_description }}</div>
{% endif %}
</header>
{% if posts is not empty %}
<div class="fedistream-grid fedistream-grid--albums">
{% for post in posts %}
{% include 'partials/card-album.twig' with { post: post } %}
{% endfor %}
</div>
{% if pagination %}
<nav class="fedistream-pagination">
{{ pagination|raw }}
</nav>
{% endif %}
{% else %}
<div class="fedistream-empty">
<p>{{ __('No albums found.', 'wp-fedistream') }}</p>
</div>
{% endif %}
</div>

View File

@@ -0,0 +1,49 @@
<?php
/**
* Artist archive template.
*
* @package WP_FediStream
*
* @var array $posts Array of artist data.
* @var string $archive_title Archive title.
* @var string $archive_description Archive description.
* @var array $pagination Pagination data.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$plugin = \WP_FediStream\Plugin::get_instance();
?>
<div class="fedistream-archive fedistream-archive--artists">
<header class="fedistream-archive__header">
<h1 class="fedistream-archive__title"><?php esc_html_e( 'Artists', 'wp-fedistream' ); ?></h1>
<?php if ( ! empty( $archive_description ) ) : ?>
<div class="fedistream-archive__description"><?php echo wp_kses_post( $archive_description ); ?></div>
<?php endif; ?>
</header>
<?php if ( ! empty( $posts ) && is_array( $posts ) ) : ?>
<div class="fedistream-grid fedistream-grid--artists">
<?php foreach ( $posts as $post ) : ?>
<?php echo $plugin->render_partial( 'partials/card-artist', array( 'post' => $post ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php endforeach; ?>
</div>
<?php if ( ! empty( $pagination['links'] ) ) : ?>
<nav class="fedistream-pagination">
<?php
foreach ( $pagination['links'] as $link ) {
echo $link; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
</nav>
<?php endif; ?>
<?php else : ?>
<div class="fedistream-empty">
<p><?php esc_html_e( 'No artists found.', 'wp-fedistream' ); ?></p>
</div>
<?php endif; ?>
</div>

View File

@@ -1,27 +0,0 @@
{# Artist archive template #}
<div class="fedistream-archive fedistream-archive--artists">
<header class="fedistream-archive__header">
<h1 class="fedistream-archive__title">{{ __('Artists', 'wp-fedistream') }}</h1>
{% if archive_description %}
<div class="fedistream-archive__description">{{ archive_description }}</div>
{% endif %}
</header>
{% if posts is not empty %}
<div class="fedistream-grid fedistream-grid--artists">
{% for post in posts %}
{% include 'partials/card-artist.twig' with { post: post } %}
{% endfor %}
</div>
{% if pagination %}
<nav class="fedistream-pagination">
{{ pagination|raw }}
</nav>
{% endif %}
{% else %}
<div class="fedistream-empty">
<p>{{ __('No artists found.', 'wp-fedistream') }}</p>
</div>
{% endif %}
</div>

View File

@@ -0,0 +1,49 @@
<?php
/**
* Playlist archive template.
*
* @package WP_FediStream
*
* @var array $posts Array of playlist data.
* @var string $archive_title Archive title.
* @var string $archive_description Archive description.
* @var array $pagination Pagination data.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$plugin = \WP_FediStream\Plugin::get_instance();
?>
<div class="fedistream-archive fedistream-archive--playlists">
<header class="fedistream-archive__header">
<h1 class="fedistream-archive__title"><?php esc_html_e( 'Playlists', 'wp-fedistream' ); ?></h1>
<?php if ( ! empty( $archive_description ) ) : ?>
<div class="fedistream-archive__description"><?php echo wp_kses_post( $archive_description ); ?></div>
<?php endif; ?>
</header>
<?php if ( ! empty( $posts ) && is_array( $posts ) ) : ?>
<div class="fedistream-grid fedistream-grid--playlists">
<?php foreach ( $posts as $post ) : ?>
<?php echo $plugin->render_partial( 'partials/card-playlist', array( 'post' => $post ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php endforeach; ?>
</div>
<?php if ( ! empty( $pagination['links'] ) ) : ?>
<nav class="fedistream-pagination">
<?php
foreach ( $pagination['links'] as $link ) {
echo $link; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
</nav>
<?php endif; ?>
<?php else : ?>
<div class="fedistream-empty">
<p><?php esc_html_e( 'No playlists found.', 'wp-fedistream' ); ?></p>
</div>
<?php endif; ?>
</div>

View File

@@ -1,27 +0,0 @@
{# Playlist archive template #}
<div class="fedistream-archive fedistream-archive--playlists">
<header class="fedistream-archive__header">
<h1 class="fedistream-archive__title">{{ __('Playlists', 'wp-fedistream') }}</h1>
{% if archive_description %}
<div class="fedistream-archive__description">{{ archive_description }}</div>
{% endif %}
</header>
{% if posts is not empty %}
<div class="fedistream-grid fedistream-grid--playlists">
{% for post in posts %}
{% include 'partials/card-playlist.twig' with { post: post } %}
{% endfor %}
</div>
{% if pagination %}
<nav class="fedistream-pagination">
{{ pagination|raw }}
</nav>
{% endif %}
{% else %}
<div class="fedistream-empty">
<p>{{ __('No playlists found.', 'wp-fedistream') }}</p>
</div>
{% endif %}
</div>

View File

@@ -0,0 +1,72 @@
<?php
/**
* Taxonomy archive template (Genre, Mood).
*
* @package WP_FediStream
*
* @var array $posts Array of post data.
* @var string $archive_title Archive title.
* @var string $archive_description Archive description.
* @var string $taxonomy_name Taxonomy name (Genre, Mood).
* @var object $term Current term object.
* @var array $pagination Pagination data.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$plugin = \WP_FediStream\Plugin::get_instance();
?>
<div class="fedistream-archive fedistream-archive--taxonomy">
<header class="fedistream-archive__header">
<h1 class="fedistream-archive__title">
<?php if ( ! empty( $taxonomy_name ) ) : ?>
<?php echo esc_html( $taxonomy_name ); ?>:
<?php endif; ?>
<?php echo esc_html( $archive_title ?? '' ); ?>
</h1>
<?php if ( ! empty( $archive_description ) ) : ?>
<div class="fedistream-archive__description"><?php echo wp_kses_post( $archive_description ); ?></div>
<?php endif; ?>
</header>
<?php if ( ! empty( $posts ) && is_array( $posts ) ) : ?>
<div class="fedistream-grid fedistream-grid--mixed">
<?php foreach ( $posts as $post ) : ?>
<?php
$post_type = $post['post_type'] ?? '';
switch ( $post_type ) {
case 'fedistream_artist':
echo $plugin->render_partial( 'partials/card-artist', array( 'post' => $post ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
break;
case 'fedistream_album':
echo $plugin->render_partial( 'partials/card-album', array( 'post' => $post ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
break;
case 'fedistream_track':
echo $plugin->render_partial( 'partials/card-track', array( 'post' => $post ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
break;
case 'fedistream_playlist':
echo $plugin->render_partial( 'partials/card-playlist', array( 'post' => $post ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
break;
}
?>
<?php endforeach; ?>
</div>
<?php if ( ! empty( $pagination['links'] ) ) : ?>
<nav class="fedistream-pagination">
<?php
foreach ( $pagination['links'] as $link ) {
echo $link; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
</nav>
<?php endif; ?>
<?php else : ?>
<div class="fedistream-empty">
<p><?php esc_html_e( 'No content found in this category.', 'wp-fedistream' ); ?></p>
</div>
<?php endif; ?>
</div>

View File

@@ -1,37 +0,0 @@
{# Taxonomy archive template (Genre, Mood) #}
<div class="fedistream-archive fedistream-archive--taxonomy">
<header class="fedistream-archive__header">
<h1 class="fedistream-archive__title">
{% if taxonomy_name %}{{ taxonomy_name }}: {% endif %}{{ term.name }}
</h1>
{% if term.description %}
<div class="fedistream-archive__description">{{ term.description }}</div>
{% endif %}
</header>
{% if posts is not empty %}
<div class="fedistream-grid fedistream-grid--mixed">
{% for post in posts %}
{% if post.post_type == 'fedistream_artist' %}
{% include 'partials/card-artist.twig' with { post: post } %}
{% elseif post.post_type == 'fedistream_album' %}
{% include 'partials/card-album.twig' with { post: post } %}
{% elseif post.post_type == 'fedistream_track' %}
{% include 'partials/card-track.twig' with { post: post } %}
{% elseif post.post_type == 'fedistream_playlist' %}
{% include 'partials/card-playlist.twig' with { post: post } %}
{% endif %}
{% endfor %}
</div>
{% if pagination %}
<nav class="fedistream-pagination">
{{ pagination|raw }}
</nav>
{% endif %}
{% else %}
<div class="fedistream-empty">
<p>{{ __('No content found in this category.', 'wp-fedistream') }}</p>
</div>
{% endif %}
</div>

View File

@@ -0,0 +1,49 @@
<?php
/**
* Track archive template.
*
* @package WP_FediStream
*
* @var array $posts Array of track data.
* @var string $archive_title Archive title.
* @var string $archive_description Archive description.
* @var array $pagination Pagination data.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$plugin = \WP_FediStream\Plugin::get_instance();
?>
<div class="fedistream-archive fedistream-archive--tracks">
<header class="fedistream-archive__header">
<h1 class="fedistream-archive__title"><?php esc_html_e( 'Tracks', 'wp-fedistream' ); ?></h1>
<?php if ( ! empty( $archive_description ) ) : ?>
<div class="fedistream-archive__description"><?php echo wp_kses_post( $archive_description ); ?></div>
<?php endif; ?>
</header>
<?php if ( ! empty( $posts ) && is_array( $posts ) ) : ?>
<div class="fedistream-grid fedistream-grid--tracks">
<?php foreach ( $posts as $post ) : ?>
<?php echo $plugin->render_partial( 'partials/card-track', array( 'post' => $post ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php endforeach; ?>
</div>
<?php if ( ! empty( $pagination['links'] ) ) : ?>
<nav class="fedistream-pagination">
<?php
foreach ( $pagination['links'] as $link ) {
echo $link; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
</nav>
<?php endif; ?>
<?php else : ?>
<div class="fedistream-empty">
<p><?php esc_html_e( 'No tracks found.', 'wp-fedistream' ); ?></p>
</div>
<?php endif; ?>
</div>

View File

@@ -1,27 +0,0 @@
{# Track archive template #}
<div class="fedistream-archive fedistream-archive--tracks">
<header class="fedistream-archive__header">
<h1 class="fedistream-archive__title">{{ __('Tracks', 'wp-fedistream') }}</h1>
{% if archive_description %}
<div class="fedistream-archive__description">{{ archive_description }}</div>
{% endif %}
</header>
{% if posts is not empty %}
<div class="fedistream-grid fedistream-grid--tracks">
{% for post in posts %}
{% include 'partials/card-track.twig' with { post: post } %}
{% endfor %}
</div>
{% if pagination %}
<nav class="fedistream-pagination">
{{ pagination|raw }}
</nav>
{% endif %}
{% else %}
<div class="fedistream-empty">
<p>{{ __('No tracks found.', 'wp-fedistream') }}</p>
</div>
{% endif %}
</div>