From d2088328353bf831733962d4e7811b4284b865fa Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Mon, 27 Sep 2021 21:16:15 +0200 Subject: [PATCH] [not verified] Podcast Player Block: avoid use of extract() (#21199) Co-authored-by: Konstantin Obenland Co-authored-by: Samiff --- ...fusion-sync-jeherve-D67274-code-1632761166 | 4 ++++ .../blocks/podcast-player/podcast-player.php | 12 ---------- .../templates/playlist-track.php | 23 ++++++++---------- .../templates/podcast-header-title.php | 24 ++++++++----------- .../templates/podcast-header.php | 20 +++++++--------- .../templates/podcast-title.php | 21 +++++++--------- 6 files changed, 41 insertions(+), 63 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/fusion-sync-jeherve-D67274-code-1632761166 diff --git a/projects/plugins/jetpack/changelog/fusion-sync-jeherve-D67274-code-1632761166 b/projects/plugins/jetpack/changelog/fusion-sync-jeherve-D67274-code-1632761166 new file mode 100644 index 0000000000000..bcec6ab14e3e7 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fusion-sync-jeherve-D67274-code-1632761166 @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Podcast Player Block: avoid use of extract() diff --git a/projects/plugins/jetpack/extensions/blocks/podcast-player/podcast-player.php b/projects/plugins/jetpack/extensions/blocks/podcast-player/podcast-player.php index 771728418062d..9b3af865e9948 100644 --- a/projects/plugins/jetpack/extensions/blocks/podcast-player/podcast-player.php +++ b/projects/plugins/jetpack/extensions/blocks/podcast-player/podcast-player.php @@ -299,18 +299,6 @@ function render( $name, $template_props = array(), $print = true ) { return ''; } - /* - * Optionally provided an assoc array of data to pass to template. - * IMPORTANT: It will be extracted into variables. - */ - if ( is_array( $template_props ) ) { - /* - * It ignores the `discouraging` sniffer rule for extract, since it's needed - * to make the templating system works. - */ - extract( $template_props ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract - } - if ( $print ) { include $template_path; } else { diff --git a/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/playlist-track.php b/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/playlist-track.php index afdc9551cd07d..0789816e0edc8 100644 --- a/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/playlist-track.php +++ b/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/playlist-track.php @@ -10,21 +10,18 @@ /** * Template variables. * - * @var array $attachment - * @var array $primary_colors - * @var array $secondary_colors - * @var bool $is_active + * @var array $template_props */ -$track_title = $attachment['title']; -$track_link = empty( $attachment['link'] ) ? $attachment['src'] : $attachment['link']; -$track_duration = ! empty( $attachment['duration'] ) ? $attachment['duration'] : ''; +$track_title = $template_props['attachment']['title']; +$track_link = empty( $template_props['attachment']['link'] ) ? $template_props['attachment']['src'] : $template_props['attachment']['link']; +$track_duration = ! empty( $template_props['attachment']['duration'] ) ? $template_props['attachment']['duration'] : ''; -$class = 'jetpack-podcast-player__track ' . $secondary_colors['class']; -$style = $secondary_colors['style']; -if ( $is_active ) { - $class = 'jetpack-podcast-player__track is-active ' . $primary_colors['class']; - $style = $primary_colors['style']; +$class = 'jetpack-podcast-player__track ' . $template_props['secondary_colors']['class']; +$style = $template_props['secondary_colors']['style']; +if ( $template_props['is_active'] ) { + $class = 'jetpack-podcast-player__track is-active ' . $template_props['primary_colors']['class']; + $style = $template_props['primary_colors']['style']; } ?> @@ -37,7 +34,7 @@ class="" class="jetpack-podcast-player__track-link jetpack-podcast-player__link" href="" role="button" - + > diff --git a/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/podcast-header-title.php b/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/podcast-header-title.php index 4218a3e9acbd6..763aa83a1f228 100644 --- a/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/podcast-header-title.php +++ b/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/podcast-header-title.php @@ -10,27 +10,23 @@ /** * Template variables. * - * @var string $player_id - * @var string $title - * @var string $link - * @var array $track - * @var array $primary_colors + * @var string $template_props */ -if ( ! isset( $title ) && empty( $track['title'] ) ) { +if ( ! isset( $template_props['title'] ) && empty( $template_props['track']['title'] ) ) { return; } -$track_link = empty( $track['link'] ) ? $track['src'] : $track['link']; +$track_link = empty( $template_props['track']['link'] ) ? $template_props['track']['src'] : $template_props['track']['link']; ?> -

+

+ class="jetpack-podcast-player__current-track-title " + > - + - $title, - 'link' => $link, + 'title' => $template_props['title'], + 'link' => $template_props['link'], ) ); ?> diff --git a/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/podcast-header.php b/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/podcast-header.php index 7747f24d263e1..b6167df2fc7d7 100644 --- a/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/podcast-header.php +++ b/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/podcast-header.php @@ -11,14 +11,10 @@ * Template variables. * * @var array $template_props - * @var string $player_id - * @var string $title - * @var string $link - * @var array $primary_colors */ /** - * Block attributes + * Block attributes. */ $attributes = (array) $template_props['attributes']; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable $show_cover_art = (bool) $attributes['showCoverArt']; @@ -32,9 +28,9 @@
- +
- +
@@ -43,11 +39,11 @@ render( 'podcast-header-title', array( - 'player_id' => $player_id, - 'title' => $title, - 'link' => $link, + 'player_id' => $template_props['player_id'], + 'title' => $template_props['title'], + 'link' => $template_props['link'], 'track' => $track, - 'primary_colors' => $primary_colors, + 'primary_colors' => $template_props['primary_colors'], ) ); } @@ -58,7 +54,7 @@ if ( $show_episode_description && ! empty( $track ) && isset( $track['description'] ) ) : ?>
diff --git a/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/podcast-title.php b/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/podcast-title.php index 4cce0807b7090..ce5b59caec132 100644 --- a/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/podcast-title.php +++ b/projects/plugins/jetpack/extensions/blocks/podcast-player/templates/podcast-title.php @@ -10,30 +10,27 @@ /** * Template variables. * - * @var string $title - * @var string $link + * @var string $template_props */ -if ( empty( $title ) ) { +if ( empty( $template_props['title'] ) ) { return; } ?> - + - + + else : + echo esc_html( $template_props['title'] ); + endif; + ?>