Skip to content

Commit

Permalink
Shortcode: Get rid of custom shortcodes for Youtube and Vimeo in favo…
Browse files Browse the repository at this point in the history
…r of Core
  • Loading branch information
arthur791004 committed Aug 27, 2024
1 parent 5281706 commit 66d775e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 67 deletions.
47 changes: 0 additions & 47 deletions projects/plugins/jetpack/modules/shortcodes/vimeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,53 +246,6 @@ class_exists( 'Jetpack_AMP_Support' )
}
add_shortcode( 'vimeo', 'vimeo_shortcode' );

/**
* Callback to modify output of embedded Vimeo video using Jetpack's shortcode.
*
* @since 3.9
*
* @param array $matches Regex partial matches against the URL passed.
* @param array $attr Attributes received in embed response.
* @param array $url Requested URL to be embedded.
*
* @return string Return output of Vimeo shortcode with the proper markup.
*/
function wpcom_vimeo_embed_url( $matches, $attr, $url ) {
$vimeo_info = array( $url );

// If we are able to extract a video ID, use it in the shortcode instead of the full URL.
if ( ! empty( $matches['video_id'] ) ) {
$vimeo_info = array( 'id' => $matches['video_id'] );
}

return vimeo_shortcode( $vimeo_info );
}

/**
* For bare URLs on their own line of the form.
*
* Accepted formats:
* https://vimeo.com/289091934/cd1f466bcc
* https://vimeo.com/album/2838732/video/6342264
* https://vimeo.com/6342264
* http://player.vimeo.com/video/18427511
*
* @since 3.9
*
* @uses wpcom_vimeo_embed_url
*/
function wpcom_vimeo_embed_url_init() {
wp_embed_register_handler( 'wpcom_vimeo_embed_url', '#https?://(?:[^/]+\.)?vimeo\.com/(?:album/(?<album_id>\d+)/)?(?:video/)?(?<video_id>\d+)(?:/.*)?$#i', 'wpcom_vimeo_embed_url' );
}

/*
* Register handler to modify Vimeo embeds using Jetpack's shortcode output.
* This does not happen on WordPress.com, since embeds are handled by core there.
*/
if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) {
add_action( 'init', 'wpcom_vimeo_embed_url_init' );
}

/**
* Transform a Vimeo embed iFrame into a Vimeo shortcode.
*
Expand Down
20 changes: 0 additions & 20 deletions projects/plugins/jetpack/modules/shortcodes/youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,26 +523,6 @@ function jetpack_shortcode_youtube_dimensions( $query_args ) {
return array( $w, $h );
}

/**
* For bare URLs on their own line of the form
* http://www.youtube.com/v/9FhMMmqzbD8?fs=1&hl=en_US
*
* @param array $matches Regex partial matches against the URL passed.
* @param array $attr Attributes received in embed response.
* @param array $url Requested URL to be embedded.
*/
function wpcom_youtube_embed_crazy_url( $matches, $attr, $url ) {
return youtube_id( $url );
}

/**
* Add a new handler to automatically transform custom Youtube URLs (like playlists) into embeds.
*/
function wpcom_youtube_embed_crazy_url_init() {
wp_embed_register_handler( 'wpcom_youtube_embed_crazy_url', '#https?://(?:www\.)?(?:youtube.com/(?:v/|playlist|watch[/\#?])|youtu\.be/).*#i', 'wpcom_youtube_embed_crazy_url' );
}
add_action( 'init', 'wpcom_youtube_embed_crazy_url_init' );

if (
! is_admin()
/**
Expand Down

0 comments on commit 66d775e

Please sign in to comment.