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,84 @@
<?php
/**
* Artist shortcode template.
*
* @package WP_FediStream
*
* @var array $post Artist data array.
* @var string $layout Layout style (full, card, compact).
* @var bool $show_albums Whether to show albums.
* @var bool $show_tracks Whether to show tracks.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$plugin = \WP_FediStream\Plugin::get_instance();
$layout = $layout ?? 'full';
?>
<div class="fedistream-shortcode fedistream-shortcode--artist fedistream-shortcode--<?php echo esc_attr( $layout ); ?>">
<div class="fedistream-artist">
<div class="fedistream-artist__header">
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="<?php echo esc_attr( $post['title'] ?? '' ); ?>" class="fedistream-artist__image">
<?php else : ?>
<div class="fedistream-artist__placeholder">
<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 class="fedistream-artist__info">
<h3 class="fedistream-artist__name">
<a href="<?php echo esc_url( $post['permalink'] ?? '#' ); ?>"><?php echo esc_html( $post['title'] ?? '' ); ?></a>
</h3>
<?php if ( ! empty( $post['artist_type_label'] ) ) : ?>
<span class="fedistream-artist__type"><?php echo esc_html( $post['artist_type_label'] ); ?></span>
<?php endif; ?>
<?php if ( ! empty( $post['genres'] ) && is_array( $post['genres'] ) ) : ?>
<div class="fedistream-artist__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>
</div>
<?php if ( 'full' === $layout && ! empty( $post['content'] ) ) : ?>
<div class="fedistream-artist__bio">
<?php echo wp_kses_post( $post['content'] ); ?>
</div>
<?php endif; ?>
<?php if ( ! empty( $show_albums ) && ! empty( $post['albums'] ) && is_array( $post['albums'] ) ) : ?>
<div class="fedistream-artist__albums">
<h4 class="fedistream-section__title"><?php esc_html_e( 'Albums', 'wp-fedistream' ); ?></h4>
<div class="fedistream-grid fedistream-grid--small">
<?php foreach ( array_slice( $post['albums'], 0, 4 ) as $album ) : ?>
<?php echo $plugin->render_partial( 'partials/card-album', array( 'post' => $album ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<?php if ( ! empty( $show_tracks ) && ! empty( $post['tracks'] ) && is_array( $post['tracks'] ) ) : ?>
<div class="fedistream-artist__tracks">
<h4 class="fedistream-section__title"><?php esc_html_e( 'Popular Tracks', 'wp-fedistream' ); ?></h4>
<div class="fedistream-tracklist fedistream-tracklist--compact">
<?php foreach ( array_slice( $post['tracks'], 0, 5 ) 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>
<div class="fedistream-tracklist__info">
<a href="<?php echo esc_url( $track['permalink'] ?? '#' ); ?>" class="fedistream-tracklist__title"><?php echo esc_html( $track['title'] ?? '' ); ?></a>
</div>
<?php if ( ! empty( $track['duration_formatted'] ) ) : ?>
<span class="fedistream-tracklist__duration"><?php echo esc_html( $track['duration_formatted'] ); ?></span>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
</div>