-
Notifications
You must be signed in to change notification settings - Fork 814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Podcast player: Render podcast header markup by server-side #15221
Merged
retrofox
merged 9 commits into
feature/podcast-player
from
update/podcast-header-ss-rendering
Apr 1, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4a0f6ca
podcast-player: add template render function
retrofox 6d416b6
podcast-player: add header template
retrofox d453fc3
podcast-player: render podcast title
retrofox d0d5bd4
[not verified] Fix to use dedicated templates
getdave 85a58cb
podcast-player: fix sniffer errors. esc values. rename vars
retrofox 1aad998
podcast-player: add disabling sniffer rule doc
retrofox daaba6f
Update extensions/blocks/podcast-player/podcast-player.php
retrofox 0c4b7a0
podcast-player: rename render data param name
retrofox b5f7778
podcast-player: improve doc
retrofox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
extensions/blocks/podcast-player/templates/podcast-header-title.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Podcast Header Title template. | ||
* | ||
* @package Jetpack | ||
*/ | ||
|
||
namespace Automattic\Jetpack\Extensions\Podcast_Player; | ||
|
||
// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable | ||
// phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase | ||
|
||
if ( ! isset( $title ) && empty( $track ) && ! isset( $track['title'] ) ) { | ||
return; | ||
} | ||
?> | ||
|
||
<h2 id=<?php echo esc_attr( $playerId ); ?>__title" class="jetpack-podcast-player__title"> | ||
<?php if ( ! empty( $track ) && isset( $track['title'] ) ) : ?> | ||
<span class="jetpack-podcast-player__current-track-title"> | ||
<?php echo esc_attr( $track['title'] ); ?> | ||
</span> | ||
<?php endif; ?> | ||
|
||
<?php if ( ! empty( $track ) && isset( $track['title'] ) && isset( $title ) ) : ?> | ||
<span class="jetpack-podcast-player--visually-hidden"> - </span> | ||
<?php endif; ?> | ||
|
||
<?php if ( isset( $title ) ) : ?> | ||
<?php | ||
render( | ||
'podcast-title', | ||
array( | ||
'title' => $title, | ||
'link' => $link, | ||
) | ||
); | ||
?> | ||
<?php endif; ?> | ||
</h2> | ||
|
||
<?php | ||
// phpcs:enable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase | ||
// phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable |
59 changes: 59 additions & 0 deletions
59
extensions/blocks/podcast-player/templates/podcast-header.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Podcast Header template. | ||
* | ||
* @package Jetpack | ||
*/ | ||
|
||
namespace Automattic\Jetpack\Extensions\Podcast_Player; | ||
|
||
// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable | ||
// phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase | ||
|
||
/** | ||
* Block attributes | ||
*/ | ||
$attributes = (array) $template_props['attributes']; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable | ||
$show_cover_art = (bool) $attributes['showCoverArt']; | ||
$show_episode_description = (bool) $attributes['showEpisodeDescription']; | ||
|
||
// Current track. | ||
$track = ! empty( $template_props['tracks'] ) ? $template_props['tracks'][0] : array(); | ||
?> | ||
|
||
<div class="jetpack-podcast-player__header"> | ||
<div class="jetpack-podcast-player__current-track-info" aria-live="polite"> | ||
<?php if ( $show_cover_art && isset( $cover ) ) : ?> | ||
<div class="jetpack-podcast-player__cover"> | ||
<img class="jetpack-podcast-player__cover-image" src=<?php echo esc_url( $cover ); ?>alt="" /> | ||
</div> | ||
|
||
<?php | ||
render( | ||
'podcast-header-title', | ||
array( | ||
'playerId' => $playerId, | ||
'title' => $title, | ||
'link' => $link, | ||
'track' => $track, | ||
) | ||
); | ||
?> | ||
<?php endif; ?> | ||
</div> | ||
|
||
<?php | ||
if ( $show_episode_description && ! empty( $track ) && isset( $track['description'] ) ) : | ||
?> | ||
<div | ||
id="<?php echo esc_attr( $playerId ); ?>__track-description" | ||
class="jetpack-podcast-player__track-description" | ||
> | ||
<?php echo esc_attr( $track['description'] ); ?> | ||
</div> | ||
<?php endif; ?> | ||
</div> | ||
|
||
<?php | ||
// phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable | ||
// phpcs:enable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase |
35 changes: 35 additions & 0 deletions
35
extensions/blocks/podcast-player/templates/podcast-title.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* Podcast Title template. | ||
* | ||
* @package Jetpack | ||
*/ | ||
|
||
namespace Automattic\Jetpack\Extensions\Podcast_Player; | ||
|
||
// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable | ||
// phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase | ||
|
||
if ( ! isset( $title ) ) { | ||
return; | ||
} | ||
?> | ||
|
||
<?php if ( isset( $link ) ) : ?> | ||
<a | ||
class="jetpack-podcast-player__podcast-title" | ||
href="<?php echo esc_url( $link ); ?>" | ||
target="_blank" | ||
rel="noopener noreferrer nofollow" | ||
> | ||
<?php echo esc_attr( $title ); ?> | ||
</a> | ||
<?php else : ?> | ||
<span class="jetpack-podcast-player__podcast-title"> | ||
<?php echo esc_attr( $title ); ?> | ||
</span>; | ||
<?php endif; ?> | ||
|
||
<?php | ||
// phpcs:enable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase | ||
// phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish there was a better way to do this?
It looks like we can set certain variables to be ignored from this
UNdefinedVariable
check.https://github.com/sirbrillig/phpcs-variable-analysis#customization
I proposed we
$data
to$templateProps
.phpcs.xml.dist
under thevalidUndefinedVariableNames
property to ignore the var$templateProps
.render
so that it doesn't perform anextract()
and simply passes the$templateProps
array.$templateProps
(or not) as required without having to worry about disablingphpcs
warnings.@jeherve what do you think about this? Having to litter each template with these disable rules feels really horrible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that sounds like a good plan!