PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | modules/shortcodes/vimeo.php +30 -18 13.6.216.3-a.1 View file →
@@ -13,8 +13,12 @@
13 13 *
14 14 * @package automattic/jetpack
15 15 */
16 16
17 +if ( ! defined( 'ABSPATH' ) ) {
18 + exit( 0 );
19 +}
20 +
17 21 /**
18 22 * Extract Vimeo ID from shortcode.
19 23 *
20 24 * @param array $atts Shortcode attributes.
@@ -21,18 +25,27 @@
21 25 */
22 26 function jetpack_shortcode_get_vimeo_id( $atts ) {
23 27 if ( isset( $atts[0] ) ) {
24 28 $atts[0] = trim( $atts[0], '=' );
25 - $id = false;
26 29 if ( is_numeric( $atts[0] ) ) {
27 - $id = (int) $atts[0];
28 - } elseif ( preg_match( '|vimeo\.com/(\d+)/?$|i', $atts[0], $match ) ) {
29 - $id = (int) $match[1];
30 - } elseif ( preg_match( '|player\.vimeo\.com/video/(\d+)/?$|i', $atts[0], $match ) ) {
31 - $id = (int) $match[1];
30 + return (int) $atts[0];
32 31 }
33 32
34 - return $id;
33 + /**
34 + * Extract Vimeo ID from the URL. For examples:
35 + * https://vimeo.com/12345
36 + * https://vimeo.com/289091934/cd1f466bcc
37 + * https://vimeo.com/album/2838732/video/6342264
38 + * https://vimeo.com/groups/758728/videos/897094040
39 + * https://vimeo.com/channels/staffpicks/123456789
40 + * https://vimeo.com/album/1234567/video/7654321
41 + * https://player.vimeo.com/video/18427511
42 + */
43 + $pattern = '/(?:https?:\/\/)?vimeo\.com\/(?:groups\/\d+\/videos\/|album\/\d+\/video\/|video\/|channels\/[^\/]+\/videos\/|[^\/]+\/)?([0-9]+)(?:[^\'\"0-9<]|$)/i';
44 + $match = array();
45 + if ( preg_match( $pattern, $atts[0], $match ) ) {
46 + return (int) $match[1];
47 + }
35 48 }
36 49
37 50 return 0;
38 51 }
@@ -249,8 +262,9 @@
249 262 /**
250 263 * Callback to modify output of embedded Vimeo video using Jetpack's shortcode.
251 264 *
252 265 * @since 3.9
266 + * @deprecated since 13.8
253 267 *
254 268 * @param array $matches Regex partial matches against the URL passed.
255 269 * @param array $attr Attributes received in embed response.
256 270 * @param array $url Requested URL to be embedded.
@@ -257,8 +271,9 @@
257 271 *
258 272 * @return string Return output of Vimeo shortcode with the proper markup.
259 273 */
260 274 function wpcom_vimeo_embed_url( $matches, $attr, $url ) {
275 + _deprecated_function( __FUNCTION__, 'jetpack-13.8' );
261 276 $vimeo_info = array( $url );
262 277
263 278 // If we are able to extract a video ID, use it in the shortcode instead of the full URL.
264 279 if ( ! empty( $matches['video_id'] ) ) {
@@ -277,23 +292,17 @@
277 292 * https://vimeo.com/6342264
278 293 * http://player.vimeo.com/video/18427511
279 294 *
280 295 * @since 3.9
296 + * @deprecated since 13.8
281 297 *
282 298 * @uses wpcom_vimeo_embed_url
283 299 */
284 300 function wpcom_vimeo_embed_url_init() {
301 + _deprecated_function( __FUNCTION__, 'jetpack-13.8' );
285 302 wp_embed_register_handler( 'wpcom_vimeo_embed_url', '#https?://(?:[^/]+\.)?vimeo\.com/(?:album/(?<album_id>\d+)/)?(?:video/)?(?<video_id>\d+)(?:/.*)?$#i', 'wpcom_vimeo_embed_url' );
286 303 }
287 304
288 -/*
289 - * Register handler to modify Vimeo embeds using Jetpack's shortcode output.
290 - * This does not happen on WordPress.com, since embeds are handled by core there.
291 - */
292 -if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) {
293 - add_action( 'init', 'wpcom_vimeo_embed_url_init' );
294 -}
295 -
296 305 /**
297 306 * Transform a Vimeo embed iFrame into a Vimeo shortcode.
298 307 *
299 308 * @param string $content Post content.
@@ -336,10 +345,13 @@
336 345 }
337 346
338 347 return $content;
339 348 }
340 -add_filter( 'pre_kses', 'vimeo_embed_to_shortcode' );
341 349
350 +if ( jetpack_shortcodes_should_hook_pre_kses() ) {
351 + add_filter( 'pre_kses', 'vimeo_embed_to_shortcode' );
352 +}
353 +
342 354 /**
343 355 * Replaces shortcodes and plain-text URLs to Vimeo videos with Vimeo embeds.
344 356 * Covers shortcode usage [vimeo 1234] | [vimeo https://vimeo.com/1234] | [vimeo http://vimeo.com/1234]
345 357 * Or plain text URLs https://vimeo.com/1234 | vimeo.com/1234 | //vimeo.com/1234
@@ -373,9 +385,9 @@
373 385 *
374 386 * Could erroneously capture:
375 387 * <a href="some.link/maybe/even/vimeo">This video (vimeo.com/12345) is teh cat's meow!</a>
376 388 */
377 - $plain_url = "(?:[^'\">]?\/?(?:https?:\/\/)?vimeo\.com[^0-9]+)([0-9]+)(?:[^'\"0-9<]|$)";
389 + $plain_url = "(?:[^'\">]?\/?(?:https?:\/\/)?vimeo\.com\/(?:groups\/\d+\/videos\/|album\/\d+\/video\/|video\/|channels\/[^\/]+\/videos\/|[^\/]+\/)?)([0-9]+)(?:[^'\"0-9<]|$)";
378 390
379 391 return jetpack_preg_replace_callback_outside_tags(
380 392 sprintf( '#%s|%s#i', $shortcode, $plain_url ),
381 393 'vimeo_link_callback',
@@ -392,9 +404,9 @@
392 404 * @param array $matches An array containing a Vimeo URL.
393 405 * @return string The Vimeo HTML embed code.
394 406 */
395 407 function vimeo_link_callback( $matches ) {
396 - $id = isset( $matches[2] ) ? $matches[2] : $matches[1];
408 + $id = $matches[2] ?? $matches[1];
397 409 if ( isset( $id ) && ctype_digit( $id ) ) {
398 410 return "\n" . vimeo_shortcode( array( 'id' => $id ) ) . "\n";
399 411 }
400 412 return $matches[0];