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

103
templates/single/artist.php Normal file
View File

@@ -0,0 +1,103 @@
<?php
/**
* Single artist template.
*
* @package WP_FediStream
*
* @var array $post Artist data array.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$plugin = \WP_FediStream\Plugin::get_instance();
?>
<article class="fedistream-single fedistream-single--artist">
<header class="fedistream-single__header">
<div class="fedistream-single__hero">
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="<?php echo esc_attr( $post['title'] ?? '' ); ?>" class="fedistream-single__image fedistream-single__image--artist">
<?php else : ?>
<div class="fedistream-single__placeholder fedistream-single__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-single__info">
<h1 class="fedistream-single__title"><?php echo esc_html( $post['title'] ?? '' ); ?></h1>
<?php if ( ! empty( $post['artist_type_label'] ) ) : ?>
<p class="fedistream-single__type"><?php echo esc_html( $post['artist_type_label'] ); ?></p>
<?php endif; ?>
<?php if ( ! empty( $post['genres'] ) && is_array( $post['genres'] ) ) : ?>
<div class="fedistream-single__genres">
<?php foreach ( $post['genres'] as $genre ) : ?>
<a href="<?php echo esc_url( $genre['url'] ?? '#' ); ?>" class="fedistream-tag"><?php echo esc_html( $genre['name'] ?? '' ); ?></a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</header>
<?php if ( ! empty( $post['content'] ) ) : ?>
<section class="fedistream-single__content">
<h2 class="fedistream-section__title"><?php esc_html_e( 'About', 'wp-fedistream' ); ?></h2>
<div class="fedistream-single__description">
<?php echo wp_kses_post( $post['content'] ); ?>
</div>
</section>
<?php endif; ?>
<?php if ( ! empty( $post['social_links'] ) && is_array( $post['social_links'] ) ) : ?>
<section class="fedistream-single__social">
<h2 class="fedistream-section__title"><?php esc_html_e( 'Connect', 'wp-fedistream' ); ?></h2>
<div class="fedistream-social-links">
<?php foreach ( $post['social_links'] as $platform => $url ) : ?>
<a href="<?php echo esc_url( $url ); ?>" class="fedistream-social-link fedistream-social-link--<?php echo esc_attr( $platform ); ?>" target="_blank" rel="noopener noreferrer">
<?php echo esc_html( $platform ); ?>
</a>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
<?php if ( ! empty( $post['albums'] ) && is_array( $post['albums'] ) ) : ?>
<section class="fedistream-single__albums">
<h2 class="fedistream-section__title"><?php esc_html_e( 'Discography', 'wp-fedistream' ); ?></h2>
<div class="fedistream-grid fedistream-grid--albums">
<?php foreach ( $post['albums'] as $album ) : ?>
<?php echo $plugin->render_partial( 'partials/card-album', array( 'post' => $album ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
<?php if ( ! empty( $post['tracks'] ) && is_array( $post['tracks'] ) ) : ?>
<section class="fedistream-single__tracks">
<h2 class="fedistream-section__title"><?php esc_html_e( 'Popular Tracks', 'wp-fedistream' ); ?></h2>
<div class="fedistream-tracklist">
<?php foreach ( $post['tracks'] as $index => $track ) : ?>
<div class="fedistream-tracklist__item" data-track-id="<?php echo esc_attr( $track['id'] ?? '' ); ?>">
<span class="fedistream-tracklist__number"><?php echo esc_html( $index + 1 ); ?></span>
<?php if ( ! empty( $track['thumbnail'] ) ) : ?>
<img src="<?php echo esc_url( $track['thumbnail'] ); ?>" alt="" class="fedistream-tracklist__artwork">
<?php endif; ?>
<div class="fedistream-tracklist__info">
<a href="<?php echo esc_url( $track['permalink'] ?? '#' ); ?>" class="fedistream-tracklist__title"><?php echo esc_html( $track['title'] ?? '' ); ?></a>
<?php if ( ! empty( $track['album_title'] ) ) : ?>
<span class="fedistream-tracklist__album"><?php echo esc_html( $track['album_title'] ); ?></span>
<?php endif; ?>
</div>
<?php if ( ! empty( $track['duration_formatted'] ) ) : ?>
<span class="fedistream-tracklist__duration"><?php echo esc_html( $track['duration_formatted'] ); ?></span>
<?php endif; ?>
<button type="button" class="fedistream-tracklist__play" aria-label="<?php esc_attr_e( 'Play', 'wp-fedistream' ); ?>">
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
</button>
</div>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
</article>