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,73 @@
<?php
/**
* Tracks list shortcode template.
*
* @package WP_FediStream
*
* @var array $posts Array of track data.
* @var int $columns Number of columns.
* @var string $title Section title.
*/
// Prevent direct file access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$columns = $columns ?? 1;
?>
<div class="fedistream-shortcode fedistream-shortcode--tracks">
<?php if ( ! empty( $title ) ) : ?>
<h3 class="fedistream-shortcode__title"><?php echo esc_html( $title ); ?></h3>
<?php endif; ?>
<?php if ( ! empty( $posts ) && is_array( $posts ) ) : ?>
<div class="fedistream-tracklist fedistream-tracklist--numbered">
<?php foreach ( $posts as $index => $post ) : ?>
<div class="fedistream-tracklist__item" data-track-id="<?php echo esc_attr( $post['id'] ?? '' ); ?>">
<span class="fedistream-tracklist__rank"><?php echo esc_html( $index + 1 ); ?></span>
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="" class="fedistream-tracklist__artwork">
<?php else : ?>
<div class="fedistream-tracklist__artwork fedistream-tracklist__artwork--placeholder">
<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; ?>
<div class="fedistream-tracklist__info">
<a href="<?php echo esc_url( $post['permalink'] ?? '#' ); ?>" class="fedistream-tracklist__title"><?php echo esc_html( $post['title'] ?? '' ); ?></a>
<span class="fedistream-tracklist__artist">
<?php if ( ! empty( $post['artists'] ) && is_array( $post['artists'] ) ) : ?>
<?php
$artist_links = array();
foreach ( $post['artists'] as $artist ) {
$artist_links[] = sprintf(
'<a href="%s">%s</a>',
esc_url( $artist['url'] ?? '#' ),
esc_html( $artist['name'] ?? '' )
);
}
echo implode( ', ', $artist_links ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
<?php elseif ( ! empty( $post['artist'] ) ) : ?>
<?php echo esc_html( $post['artist'] ); ?>
<?php endif; ?>
</span>
</div>
<?php if ( ! empty( $post['play_count'] ) ) : ?>
<span class="fedistream-tracklist__plays"><?php echo esc_html( number_format( $post['play_count'] ) ); ?></span>
<?php endif; ?>
<?php if ( ! empty( $post['duration_formatted'] ) ) : ?>
<span class="fedistream-tracklist__duration"><?php echo esc_html( $post['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>
<?php else : ?>
<div class="fedistream-empty">
<p><?php esc_html_e( 'No tracks found.', 'wp-fedistream' ); ?></p>
</div>
<?php endif; ?>
</div>