-
Notifications
You must be signed in to change notification settings - Fork 800
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
Shortcode: Get rid of custom shortcodes for YouTube and Vimeo in favor of Core #39096
Changes from 13 commits
c608921
ecdd534
4c73a05
e2c350e
bbafe54
c6c4bde
b753546
4588624
0bf1767
82dfc89
2cc018e
0dbdff6
12433e4
c0176f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: compat | ||
|
||
Embeds: prioritize YouTube and Vimeo embeds provided by WordPress itself, over Jetpack's embedding solution. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,16 +22,25 @@ | |||||
function jetpack_shortcode_get_vimeo_id( $atts ) { | ||||||
if ( isset( $atts[0] ) ) { | ||||||
$atts[0] = trim( $atts[0], '=' ); | ||||||
$id = false; | ||||||
if ( is_numeric( $atts[0] ) ) { | ||||||
$id = (int) $atts[0]; | ||||||
} elseif ( preg_match( '|vimeo\.com/(\d+)/?$|i', $atts[0], $match ) ) { | ||||||
$id = (int) $match[1]; | ||||||
} elseif ( preg_match( '|player\.vimeo\.com/video/(\d+)/?$|i', $atts[0], $match ) ) { | ||||||
$id = (int) $match[1]; | ||||||
return (int) $atts[0]; | ||||||
} | ||||||
|
||||||
return $id; | ||||||
/** | ||||||
* Extract Vimeo ID from the URL. For examples: | ||||||
* https://vimeo.com/12345 | ||||||
* https://vimeo.com/289091934/cd1f466bcc | ||||||
* https://vimeo.com/album/2838732/video/6342264 | ||||||
* https://vimeo.com/groups/758728/videos/897094040 | ||||||
* https://vimeo.com/channels/staffpicks/123456789 | ||||||
* https://vimeo.com/album/1234567/video/7654321 | ||||||
* https://player.vimeo.com/video/18427511 | ||||||
*/ | ||||||
$pattern = '/(?:https?:\/\/)?vimeo\.com\/(?:groups\/\d+\/videos\/|album\/\d+\/video\/|video\/|channels\/[^\/]+\/videos\/|[^\/]+\/)?([0-9]+)(?:[^\'\"0-9<]|$)/i'; | ||||||
$match = array(); | ||||||
if ( preg_match( $pattern, $atts[0], $match ) ) { | ||||||
return (int) $match[1]; | ||||||
} | ||||||
} | ||||||
|
||||||
return 0; | ||||||
|
@@ -250,6 +259,7 @@ class_exists( 'Jetpack_AMP_Support' ) | |||||
* Callback to modify output of embedded Vimeo video using Jetpack's shortcode. | ||||||
* | ||||||
* @since 3.9 | ||||||
* @deprecated since x.x.x | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On top of that deprecation warning, I think you could add a warning to developers via jetpack/docs/coding-guidelines.md Lines 54 to 55 in f0fa2c8
|
||||||
* | ||||||
* @param array $matches Regex partial matches against the URL passed. | ||||||
* @param array $attr Attributes received in embed response. | ||||||
|
@@ -278,21 +288,14 @@ function wpcom_vimeo_embed_url( $matches, $attr, $url ) { | |||||
* http://player.vimeo.com/video/18427511 | ||||||
* | ||||||
* @since 3.9 | ||||||
* @deprecated since x.x.x | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* | ||||||
* @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. | ||||||
* | ||||||
|
@@ -374,7 +377,7 @@ function vimeo_link( $content ) { | |||||
* Could erroneously capture: | ||||||
* <a href="some.link/maybe/even/vimeo">This video (vimeo.com/12345) is teh cat's meow!</a> | ||||||
*/ | ||||||
$plain_url = "(?:[^'\">]?\/?(?:https?:\/\/)?vimeo\.com[^0-9]+)([0-9]+)(?:[^'\"0-9<]|$)"; | ||||||
$plain_url = "(?:[^'\">]?\/?(?:https?:\/\/)?vimeo\.com\/(?:groups\/\d+\/videos\/|album\/\d+\/video\/|video\/|channels\/[^\/]+\/videos\/|[^\/]+\/)?)([0-9]+)(?:[^'\"0-9<]|$)"; | ||||||
|
||||||
return jetpack_preg_replace_callback_outside_tags( | ||||||
sprintf( '#%s|%s#i', $shortcode, $plain_url ), | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -527,21 +527,24 @@ function jetpack_shortcode_youtube_dimensions( $query_args ) { | |||||
* 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. | ||||||
* @deprecated since x.x.x | ||||||
* | ||||||
* @param array $matches Regex partial matches against the URL passed. | ||||||
* @param array $attr Attributes received in embed response. | ||||||
* @param string $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. | ||||||
* | ||||||
* @deprecated since x.x.x | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
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() | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,7 +175,7 @@ public function get_vimeo_urls() { | |
* @param string $url The URL to test. | ||
* @param string $video_id The expected video ID. | ||
*/ | ||
public function test_replace_url_with_iframe_in_the_content( $url, $video_id ) { | ||
public function test_shortcodes_vimeo_replace_url_with_iframe_in_the_content( $url, $video_id ) { | ||
if ( | ||
( defined( 'IS_WPCOM' ) && IS_WPCOM ) | ||
|| ( defined( 'IS_ATOMIC' ) && IS_ATOMIC ) | ||
|
@@ -186,7 +186,7 @@ public function test_replace_url_with_iframe_in_the_content( $url, $video_id ) { | |
|
||
global $post; | ||
|
||
$post = self::factory()->post->create_and_get( array( 'post_content' => $url ) ); | ||
$post = self::factory()->post->create_and_get( array( 'post_content' => "[vimeo $url]" ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the content goes from just a URL to a shortcode with a URL, should the function name be updated accordingly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to |
||
|
||
do_action( 'init' ); | ||
setup_postdata( $post ); | ||
|
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.
You can use the
$$next-version$$
placeholder; it will be automatically replaced on release.jetpack/projects/packages/README.md
Lines 116 to 123 in d3f5823