You've already forked wp-fedistream
feat: Replace Twig with native PHP templates
All checks were successful
Create Release Package / build-release (push) Successful in 55s
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:
70
templates/widgets/featured-artist.php
Normal file
70
templates/widgets/featured-artist.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Featured Artist Widget Template.
|
||||
*
|
||||
* @package WP_FediStream
|
||||
*
|
||||
* @var array $post Artist data array.
|
||||
*/
|
||||
|
||||
// Prevent direct file access.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<?php if ( ! empty( $post ) ) : ?>
|
||||
<div class="fedistream-widget__featured">
|
||||
<a href="<?php echo esc_url( $post['permalink'] ?? '#' ); ?>" class="fedistream-widget__featured-link">
|
||||
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
|
||||
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="<?php echo esc_attr( $post['title'] ?? '' ); ?>" class="fedistream-widget__featured-image">
|
||||
<?php else : ?>
|
||||
<span class="fedistream-widget__placeholder fedistream-widget__placeholder--large">
|
||||
<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>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
<div class="fedistream-widget__featured-info">
|
||||
<h4 class="fedistream-widget__featured-name">
|
||||
<a href="<?php echo esc_url( $post['permalink'] ?? '#' ); ?>"><?php echo esc_html( $post['title'] ?? '' ); ?></a>
|
||||
</h4>
|
||||
<?php if ( ! empty( $post['artist_type_label'] ) ) : ?>
|
||||
<span class="fedistream-widget__featured-type"><?php echo esc_html( $post['artist_type_label'] ); ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if ( ! empty( $post['genres'] ) && is_array( $post['genres'] ) ) : ?>
|
||||
<div class="fedistream-widget__featured-genres">
|
||||
<?php foreach ( array_slice( $post['genres'], 0, 3 ) as $genre ) : ?>
|
||||
<a href="<?php echo esc_url( $genre['url'] ?? '#' ); ?>" class="fedistream-tag fedistream-tag--small"><?php echo esc_html( $genre['name'] ?? '' ); ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ( ! empty( $post['album_count'] ) || ! empty( $post['track_count'] ) ) : ?>
|
||||
<div class="fedistream-widget__featured-stats">
|
||||
<?php if ( ! empty( $post['album_count'] ) ) : ?>
|
||||
<span>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %d: number of albums */
|
||||
esc_html( _n( '%d album', '%d albums', $post['album_count'], 'wp-fedistream' ) ),
|
||||
(int) $post['album_count']
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php if ( ! empty( $post['track_count'] ) ) : ?>
|
||||
<span>
|
||||
<?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; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<p class="fedistream-widget__empty"><?php esc_html_e( 'No artist selected.', 'wp-fedistream' ); ?></p>
|
||||
<?php endif; ?>
|
||||
@@ -1,41 +0,0 @@
|
||||
{# Featured Artist Widget Template #}
|
||||
{% if post %}
|
||||
<div class="fedistream-widget__featured">
|
||||
<a href="{{ post.permalink }}" class="fedistream-widget__featured-link">
|
||||
{% if post.thumbnail %}
|
||||
<img src="{{ post.thumbnail }}" alt="{{ post.title|e('html_attr') }}" class="fedistream-widget__featured-image">
|
||||
{% else %}
|
||||
<span class="fedistream-widget__placeholder fedistream-widget__placeholder--large">
|
||||
<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>
|
||||
</span>
|
||||
{% endif %}
|
||||
</a>
|
||||
<div class="fedistream-widget__featured-info">
|
||||
<h4 class="fedistream-widget__featured-name">
|
||||
<a href="{{ post.permalink }}">{{ post.title }}</a>
|
||||
</h4>
|
||||
{% if post.artist_type %}
|
||||
<span class="fedistream-widget__featured-type">{{ post.artist_type }}</span>
|
||||
{% endif %}
|
||||
{% if post.genres is not empty %}
|
||||
<div class="fedistream-widget__featured-genres">
|
||||
{% for genre in post.genres|slice(0, 3) %}
|
||||
<a href="{{ genre.link }}" class="fedistream-tag fedistream-tag--small">{{ genre.name }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if post.album_count or post.track_count %}
|
||||
<div class="fedistream-widget__featured-stats">
|
||||
{% if post.album_count %}
|
||||
<span>{{ post.album_count }} {{ post.album_count == 1 ? __('album', 'wp-fedistream') : __('albums', 'wp-fedistream') }}</span>
|
||||
{% endif %}
|
||||
{% if post.track_count %}
|
||||
<span>{{ post.track_count }} {{ post.track_count == 1 ? __('track', 'wp-fedistream') : __('tracks', 'wp-fedistream') }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="fedistream-widget__empty">{{ __('No artist selected.', 'wp-fedistream') }}</p>
|
||||
{% endif %}
|
||||
@@ -1,10 +1,25 @@
|
||||
{# Now Playing Widget Template #}
|
||||
<?php
|
||||
/**
|
||||
* Now Playing Widget Template.
|
||||
*
|
||||
* @package WP_FediStream
|
||||
*
|
||||
* @var bool $show_player Whether to show player controls.
|
||||
*/
|
||||
|
||||
// Prevent direct file access.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$show_player = $show_player ?? true;
|
||||
?>
|
||||
<div class="fedistream-now-playing" data-widget="now-playing">
|
||||
<div class="fedistream-now-playing__idle">
|
||||
<span class="fedistream-now-playing__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>
|
||||
</span>
|
||||
<span class="fedistream-now-playing__message">{{ __('Nothing playing', 'wp-fedistream') }}</span>
|
||||
<span class="fedistream-now-playing__message"><?php esc_html_e( 'Nothing playing', 'wp-fedistream' ); ?></span>
|
||||
</div>
|
||||
<div class="fedistream-now-playing__active" style="display: none;">
|
||||
<div class="fedistream-now-playing__track">
|
||||
@@ -14,16 +29,16 @@
|
||||
<span class="fedistream-now-playing__artist"></span>
|
||||
</div>
|
||||
</div>
|
||||
{% if show_player %}
|
||||
<?php if ( $show_player ) : ?>
|
||||
<div class="fedistream-now-playing__controls">
|
||||
<button type="button" class="fedistream-now-playing__btn fedistream-now-playing__btn--prev" aria-label="{{ __('Previous', 'wp-fedistream') }}">
|
||||
<button type="button" class="fedistream-now-playing__btn fedistream-now-playing__btn--prev" aria-label="<?php esc_attr_e( 'Previous', 'wp-fedistream' ); ?>">
|
||||
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M6 6h2v12H6zm3.5 6l8.5 6V6z"/></svg>
|
||||
</button>
|
||||
<button type="button" class="fedistream-now-playing__btn fedistream-now-playing__btn--play" aria-label="{{ __('Play/Pause', 'wp-fedistream') }}">
|
||||
<button type="button" class="fedistream-now-playing__btn fedistream-now-playing__btn--play" aria-label="<?php esc_attr_e( 'Play/Pause', 'wp-fedistream' ); ?>">
|
||||
<svg class="fedistream-now-playing__icon fedistream-now-playing__icon--play" viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
|
||||
<svg class="fedistream-now-playing__icon fedistream-now-playing__icon--pause" viewBox="0 0 24 24" fill="currentColor"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>
|
||||
</button>
|
||||
<button type="button" class="fedistream-now-playing__btn fedistream-now-playing__btn--next" aria-label="{{ __('Next', 'wp-fedistream') }}">
|
||||
<button type="button" class="fedistream-now-playing__btn fedistream-now-playing__btn--next" aria-label="<?php esc_attr_e( 'Next', 'wp-fedistream' ); ?>">
|
||||
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M6 18l8.5-6L6 6v12zM16 6v12h2V6h-2z"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
@@ -36,6 +51,6 @@
|
||||
<span class="fedistream-now-playing__time fedistream-now-playing__time--total">0:00</span>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
45
templates/widgets/popular-tracks.php
Normal file
45
templates/widgets/popular-tracks.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Popular Tracks Widget Template.
|
||||
*
|
||||
* @package WP_FediStream
|
||||
*
|
||||
* @var array $posts Array of track data.
|
||||
*/
|
||||
|
||||
// Prevent direct file access.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<?php if ( ! empty( $posts ) && is_array( $posts ) ) : ?>
|
||||
<ol class="fedistream-widget__list fedistream-widget__list--tracks">
|
||||
<?php foreach ( $posts as $post ) : ?>
|
||||
<li class="fedistream-widget__item" data-track-id="<?php echo esc_attr( $post['id'] ?? '' ); ?>">
|
||||
<a href="<?php echo esc_url( $post['permalink'] ?? '#' ); ?>" class="fedistream-widget__link">
|
||||
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
|
||||
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="<?php echo esc_attr( $post['title'] ?? '' ); ?>" class="fedistream-widget__image">
|
||||
<?php else : ?>
|
||||
<span class="fedistream-widget__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>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<span class="fedistream-widget__info">
|
||||
<span class="fedistream-widget__title"><?php echo esc_html( $post['title'] ?? '' ); ?></span>
|
||||
<?php if ( ! empty( $post['artist'] ) ) : ?>
|
||||
<span class="fedistream-widget__artist"><?php echo esc_html( $post['artist'] ); ?></span>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
<?php if ( ! empty( $post['play_count'] ) ) : ?>
|
||||
<span class="fedistream-widget__plays"><?php echo esc_html( number_format( $post['play_count'] ) ); ?></span>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
<button type="button" class="fedistream-widget__play" data-track-id="<?php echo esc_attr( $post['id'] ?? '' ); ?>" aria-label="<?php esc_attr_e( 'Play', 'wp-fedistream' ); ?>">
|
||||
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
|
||||
</button>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
<?php else : ?>
|
||||
<p class="fedistream-widget__empty"><?php esc_html_e( 'No tracks yet.', 'wp-fedistream' ); ?></p>
|
||||
<?php endif; ?>
|
||||
@@ -1,32 +0,0 @@
|
||||
{# Popular Tracks Widget Template #}
|
||||
{% if posts is not empty %}
|
||||
<ol class="fedistream-widget__list fedistream-widget__list--tracks">
|
||||
{% for post in posts %}
|
||||
<li class="fedistream-widget__item" data-track-id="{{ post.id }}">
|
||||
<a href="{{ post.permalink }}" class="fedistream-widget__link">
|
||||
{% if post.thumbnail %}
|
||||
<img src="{{ post.thumbnail }}" alt="{{ post.title|e('html_attr') }}" class="fedistream-widget__image">
|
||||
{% else %}
|
||||
<span class="fedistream-widget__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>
|
||||
</span>
|
||||
{% endif %}
|
||||
<span class="fedistream-widget__info">
|
||||
<span class="fedistream-widget__title">{{ post.title }}</span>
|
||||
{% if post.artist %}
|
||||
<span class="fedistream-widget__artist">{{ post.artist }}</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
{% if post.play_count %}
|
||||
<span class="fedistream-widget__plays">{{ post.play_count|number_format }}</span>
|
||||
{% endif %}
|
||||
</a>
|
||||
<button type="button" class="fedistream-widget__play" data-track-id="{{ post.id }}" aria-label="{{ __('Play', 'wp-fedistream') }}">
|
||||
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
|
||||
</button>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
{% else %}
|
||||
<p class="fedistream-widget__empty">{{ __('No tracks yet.', 'wp-fedistream') }}</p>
|
||||
{% endif %}
|
||||
42
templates/widgets/recent-releases.php
Normal file
42
templates/widgets/recent-releases.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Recent Releases Widget Template.
|
||||
*
|
||||
* @package WP_FediStream
|
||||
*
|
||||
* @var array $posts Array of album data.
|
||||
*/
|
||||
|
||||
// Prevent direct file access.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<?php if ( ! empty( $posts ) && is_array( $posts ) ) : ?>
|
||||
<ul class="fedistream-widget__list fedistream-widget__list--releases">
|
||||
<?php foreach ( $posts as $post ) : ?>
|
||||
<li class="fedistream-widget__item">
|
||||
<a href="<?php echo esc_url( $post['permalink'] ?? '#' ); ?>" class="fedistream-widget__link">
|
||||
<?php if ( ! empty( $post['thumbnail'] ) ) : ?>
|
||||
<img src="<?php echo esc_url( $post['thumbnail'] ); ?>" alt="<?php echo esc_attr( $post['title'] ?? '' ); ?>" class="fedistream-widget__image">
|
||||
<?php else : ?>
|
||||
<span class="fedistream-widget__placeholder">
|
||||
<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>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<span class="fedistream-widget__info">
|
||||
<span class="fedistream-widget__title"><?php echo esc_html( $post['title'] ?? '' ); ?></span>
|
||||
<?php if ( ! empty( $post['artist_name'] ) ) : ?>
|
||||
<span class="fedistream-widget__artist"><?php echo esc_html( $post['artist_name'] ); ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if ( ! empty( $post['release_date'] ) ) : ?>
|
||||
<span class="fedistream-widget__date"><?php echo esc_html( $post['release_date'] ); ?></span>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php else : ?>
|
||||
<p class="fedistream-widget__empty"><?php esc_html_e( 'No releases yet.', 'wp-fedistream' ); ?></p>
|
||||
<?php endif; ?>
|
||||
@@ -1,29 +0,0 @@
|
||||
{# Recent Releases Widget Template #}
|
||||
{% if posts is not empty %}
|
||||
<ul class="fedistream-widget__list fedistream-widget__list--releases">
|
||||
{% for post in posts %}
|
||||
<li class="fedistream-widget__item">
|
||||
<a href="{{ post.permalink }}" class="fedistream-widget__link">
|
||||
{% if post.thumbnail %}
|
||||
<img src="{{ post.thumbnail }}" alt="{{ post.title|e('html_attr') }}" class="fedistream-widget__image">
|
||||
{% else %}
|
||||
<span class="fedistream-widget__placeholder">
|
||||
<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>
|
||||
</span>
|
||||
{% endif %}
|
||||
<span class="fedistream-widget__info">
|
||||
<span class="fedistream-widget__title">{{ post.title }}</span>
|
||||
{% if post.artist %}
|
||||
<span class="fedistream-widget__artist">{{ post.artist }}</span>
|
||||
{% endif %}
|
||||
{% if post.release_date %}
|
||||
<span class="fedistream-widget__date">{{ post.release_date }}</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p class="fedistream-widget__empty">{{ __('No releases yet.', 'wp-fedistream') }}</p>
|
||||
{% endif %}
|
||||
Reference in New Issue
Block a user