diff options
Diffstat (limited to 'plugins/jetpack/modules/shortcodes/spotify.php')
-rw-r--r-- | plugins/jetpack/modules/shortcodes/spotify.php | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/plugins/jetpack/modules/shortcodes/spotify.php b/plugins/jetpack/modules/shortcodes/spotify.php index ff3c38b7..33719534 100644 --- a/plugins/jetpack/modules/shortcodes/spotify.php +++ b/plugins/jetpack/modules/shortcodes/spotify.php @@ -5,16 +5,11 @@ * Usage: * [spotify id="spotify:track:4bz7uB4edifWKJXSDxwHcs" width="400" height="100"] * - * @package Jetpack + * @package automattic/jetpack */ if ( ! shortcode_exists( 'spotify' ) ) { add_shortcode( 'spotify', 'jetpack_spotify_shortcode' ); - - if ( get_option( 'embed_autourls' ) ) { - // If user enabled autourls, also convert syntax like spotify:track:4bz7uB4edifWKJXSDxwHcs. - add_filter( 'the_content', 'jetpack_spotify_embed_ids', 7 ); - } } /** @@ -53,7 +48,27 @@ function jetpack_spotify_shortcode( $atts = array(), $content = '' ) { // Spotify accepts both URLs and their Spotify ID format, so let them sort it out and validate. $embed_url = add_query_arg( 'uri', rawurlencode( $id ), 'https://embed.spotify.com/' ); - return '<iframe src="' . esc_url( $embed_url ) . '" style="display:block; margin:0 auto; width:' . esc_attr( $atts['width'] ) . 'px; height:' . esc_attr( $atts['height'] ) . 'px;" frameborder="0" allowtransparency="true"></iframe>'; + // If the shortcode is displayed in a WPCOM notification, display a simple link only. + // When the shortcode is displayed in the WPCOM Reader, use iframe instead. + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { + require_once WP_CONTENT_DIR . '/lib/display-context.php'; + $context = A8C\Display_Context\get_current_context(); + if ( A8C\Display_Context\NOTIFICATIONS === $context ) { + return sprintf( + '<a href="%1$s" target="_blank" rel="noopener noreferrer">%1$s</a>', + esc_url( $id ) + ); + } elseif ( A8C\Display_Context\READER === $context ) { + return sprintf( + '<iframe src="%1$s" height="%2$s" width="%3$s"></iframe>', + esc_url( $embed_url ), + esc_attr( $atts['height'] ), + esc_attr( $atts['width'] ) + ); + } + } + + return '<iframe src="' . esc_url( $embed_url ) . '" style="display:block; margin:0 auto; width:' . esc_attr( $atts['width'] ) . 'px; height:' . esc_attr( $atts['height'] ) . 'px;" frameborder="0" allowtransparency="true" loading="lazy"></iframe>'; } /** @@ -75,7 +90,8 @@ function jetpack_spotify_embed_ids( $content ) { continue; } - if ( substr( ltrim( $element ), 0, 8 ) !== 'spotify:' ) { + // If this element does not contain a Spotify embed, continue. + if ( false === strpos( $element, 'spotify:' ) ) { continue; } @@ -84,6 +100,7 @@ function jetpack_spotify_embed_ids( $content ) { return implode( '', $textarr ); } +add_filter( 'the_content', 'jetpack_spotify_embed_ids', 7 ); /** * Call shortcode with ID provided by matching pattern. |