diff --git a/projects/packages/videopress/changelog/add-videopress-playlist-entry-site-links b/projects/packages/videopress/changelog/add-videopress-playlist-entry-site-links
new file mode 100644
index 000000000000..0f7de6a65a34
--- /dev/null
+++ b/projects/packages/videopress/changelog/add-videopress-playlist-entry-site-links
@@ -0,0 +1,4 @@
+Significance: patch
+Type: changed
+
+Video Playlist: Open this site's video pages in the same tab, and mark the entry of the video being viewed.
diff --git a/projects/packages/videopress/src/class-channel.php b/projects/packages/videopress/src/class-channel.php
index d2fac3501612..d095435592f8 100644
--- a/projects/packages/videopress/src/class-channel.php
+++ b/projects/packages/videopress/src/class-channel.php
@@ -174,6 +174,17 @@ public static function video_url( $attachment ) {
return '' === $guid ? '' : add_query_arg( 'v', $guid, user_trailingslashit( home_url( '/' . self::ENDPOINT ) ) );
}
+ /**
+ * Whether a URL points at this site rather than, say, videopress.com.
+ *
+ * @param string $url The URL.
+ * @return bool
+ */
+ public static function is_site_url( $url ) {
+ $host = wp_parse_url( (string) $url, PHP_URL_HOST );
+ return is_string( $host ) && strtolower( $host ) === strtolower( (string) wp_parse_url( home_url(), PHP_URL_HOST ) );
+ }
+
/**
* Public query vars: `v` selects the video, `videopress_video` marks the page.
*
@@ -302,4 +313,26 @@ public static function queried_video_block( $parsed_block ) {
}
return $parsed_block;
}
+
+ /**
+ * Whether this request is a channel video page.
+ *
+ * @return bool
+ */
+ public static function is_video_page() {
+ return (bool) get_query_var( self::QUERY_VAR );
+ }
+
+ /**
+ * The GUID of the video page's video, or an empty string.
+ *
+ * @return string
+ */
+ public static function queried_guid() {
+ if ( ! self::is_video_page() ) {
+ return '';
+ }
+ $post = self::current_video();
+ return $post instanceof WP_Post ? self::guid( $post ) : '';
+ }
}
diff --git a/projects/packages/videopress/src/class-initializer.php b/projects/packages/videopress/src/class-initializer.php
index 496d1047f7ae..4d02e46e90bd 100644
--- a/projects/packages/videopress/src/class-initializer.php
+++ b/projects/packages/videopress/src/class-initializer.php
@@ -911,6 +911,7 @@ public static function render_videopress_playlist_block( $block_attributes, $con
$show_number = $enabled( 'showPositionNumber', false );
$show_runtime = $enabled( 'showTotalRuntime' );
$muted = $enabled( 'muteByDefault', false );
+ $current_guid = Channel::is_enabled() ? Channel::queried_guid() : '';
$classes = array( 'videopress-playlist', 'is-layout-' . $layout );
if ( $enabled( 'darkPlayer', false ) ) {
@@ -1011,18 +1012,25 @@ public static function render_videopress_playlist_block( $block_attributes, $con
);
$entry_close = '';
} else {
- // No player to load the video into: the entry opens its VideoPress page instead.
+ // No player to load the video into: the entry opens the video's page instead.
+ /**
+ * Filters where a playlist entry opens when the block has no player.
+ *
+ * @since 0.55.0
+ *
+ * @param string $url The video's page on videopress.com.
+ * @param string $guid The video GUID.
+ */
+ $entry_url = apply_filters( 'videopress_playlist_entry_url', 'https://videopress.com/v/' . $entry['guid'], $entry['guid'] );
+ $on_site = Channel::is_site_url( $entry_url );
+ $is_current = '' !== $current_guid && $entry['guid'] === $current_guid;
$entry_open = sprintf(
- '',
- /**
- * Filters where a playlist entry opens when the block has no player.
- *
- * @since 0.55.0
- *
- * @param string $url The video's page on videopress.com.
- * @param string $guid The video GUID.
- */
- esc_url( apply_filters( 'videopress_playlist_entry_url', 'https://videopress.com/v/' . $entry['guid'], $entry['guid'] ) ),
+ '',
+ $is_current ? ' is-current' : '',
+ esc_url( $entry_url ),
+ // Channel pages stay in the tab; videopress.com opens a new one.
+ $on_site ? '' : ' target="_blank" rel="noopener noreferrer"',
+ $is_current ? ' aria-current="true"' : '',
esc_attr( $entry['guid'] ),
esc_attr( $title ),
esc_attr( $position ),
@@ -1032,7 +1040,7 @@ public static function render_videopress_playlist_block( $block_attributes, $con
}
$items .= sprintf(
- '%1$s' .
+ '%1$s' .
'%2$s%3$s%4$s%5$s' .
'%6$s%7$s%8$s' .
'%9$s',
@@ -1044,7 +1052,8 @@ public static function render_videopress_playlist_block( $block_attributes, $con
esc_html( $title ),
$resolution_markup,
$duration_markup,
- $entry_close
+ $entry_close,
+ ! $has_player && '' !== $current_guid && $entry['guid'] === $current_guid ? ' is-current' : ''
);
}
diff --git a/projects/packages/videopress/tests/php/Playlist_Block_Test.php b/projects/packages/videopress/tests/php/Playlist_Block_Test.php
index 4644c98e263e..ae9927720fac 100644
--- a/projects/packages/videopress/tests/php/Playlist_Block_Test.php
+++ b/projects/packages/videopress/tests/php/Playlist_Block_Test.php
@@ -337,6 +337,56 @@ public function test_render_without_player_links_entries_to_videopress() {
);
}
+ /**
+ * Entries mapped to a page on this site open in the same tab and mark the
+ * video being viewed; videopress.com keeps a new tab.
+ */
+ public function test_render_without_player_keeps_site_links_in_the_tab() {
+ add_filter(
+ 'videopress_playlist_entry_url',
+ function ( $url, $guid ) {
+ return 'abcDEF12' === $guid ? home_url( '/videopress/?v=' . $guid ) : $url;
+ },
+ 10,
+ 2
+ );
+ add_filter( 'videopress_channel_enabled', '__return_true' );
+ set_query_var( \Automattic\Jetpack\VideoPress\Channel::QUERY_VAR, 1 );
+ $GLOBALS['post'] = get_post( $this->video_attachment( 'abcDEF12' ) ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+
+ $markup = VideoPress_Initializer::render_videopress_playlist_block( $this->attributes( array( 'showPlayer' => false ) ) );
+
+ $this->assertStringContainsString(
+ 'assertStringContainsString( '', $markup );
+ $this->assertStringContainsString(
+ 'assertSame( 1, substr_count( $markup, 'target="_blank"' ) );
+ }
+
+ /**
+ * A VideoPress attachment whose GUID lookup is pre-cached.
+ *
+ * @param string $guid VideoPress GUID.
+ * @return int Attachment ID.
+ */
+ private function video_attachment( $guid ) {
+ $id = wp_insert_post(
+ array(
+ 'post_type' => 'attachment',
+ 'post_status' => 'inherit',
+ 'post_mime_type' => 'video/videopress',
+ 'post_title' => 'Video ' . $guid,
+ )
+ );
+ update_post_meta( $id, 'videopress_guid', $guid );
+ return $id;
+ }
+
/**
* A hidden player set to show on click renders click-to-play entries and an
* empty, hidden stage for the view script to reveal.
diff --git a/projects/plugins/jetpack/changelog/add-videopress-playlist-entry-site-links b/projects/plugins/jetpack/changelog/add-videopress-playlist-entry-site-links
new file mode 100644
index 000000000000..22688eda588b
--- /dev/null
+++ b/projects/plugins/jetpack/changelog/add-videopress-playlist-entry-site-links
@@ -0,0 +1,4 @@
+Significance: patch
+Type: enhancement
+
+VideoPress: Open this site's video pages from a Video Playlist in the same tab, and mark the video being viewed.
diff --git a/projects/plugins/videopress/changelog/add-videopress-playlist-entry-site-links b/projects/plugins/videopress/changelog/add-videopress-playlist-entry-site-links
new file mode 100644
index 000000000000..bd0c2ac967ca
--- /dev/null
+++ b/projects/plugins/videopress/changelog/add-videopress-playlist-entry-site-links
@@ -0,0 +1,4 @@
+Significance: patch
+Type: changed
+
+Open this site's video pages from a Video Playlist in the same tab, and mark the video being viewed.