diff --git a/projects/plugins/jetpack/.phan/baseline.php b/projects/plugins/jetpack/.phan/baseline.php index 63c5c04ab2a06..117dd15b1a02a 100644 --- a/projects/plugins/jetpack/.phan/baseline.php +++ b/projects/plugins/jetpack/.phan/baseline.php @@ -22,30 +22,30 @@ // PhanTypeArraySuspiciousNullable : 60+ occurrences // PhanRedefineFunction : 50+ occurrences // PhanTypeMismatchArgumentNullable : 50+ occurrences - // PhanTypeExpectedObjectPropAccess : 45+ occurrences // PhanParamTooMany : 40+ occurrences // PhanPluginDuplicateAdjacentStatement : 40+ occurrences + // PhanTypeExpectedObjectPropAccess : 40+ occurrences // PhanTypeMismatchArgumentInternal : 40+ occurrences // PhanUndeclaredProperty : 35+ occurrences // PhanParamSignatureMismatch : 25+ occurrences - // PhanPluginSimplifyExpressionBool : 25+ occurrences // PhanTypeMismatchDefault : 25+ occurrences // PhanTypeMismatchPropertyProbablyReal : 25+ occurrences // PhanTypeMissingReturn : 25+ occurrences // PhanTypeSuspiciousNonTraversableForeach : 25+ occurrences // PhanDeprecatedProperty : 20+ occurrences + // PhanPluginSimplifyExpressionBool : 20+ occurrences // PhanTypeArraySuspicious : 20+ occurrences // PhanTypeMismatchDimFetch : 20+ occurrences // PhanPluginMixedKeyNoKey : 15+ occurrences // PhanSuspiciousMagicConstant : 15+ occurrences // PhanTypeExpectedObjectPropAccessButGotNull : 15+ occurrences - // PhanTypeMismatchArgumentNullableInternal : 15+ occurrences // PhanTypeMismatchPropertyDefault : 15+ occurrences // PhanUndeclaredMethod : 15+ occurrences // PhanPluginDuplicateExpressionAssignmentOperation : 10+ occurrences // PhanRedefineClass : 10+ occurrences // PhanRedundantConditionInLoop : 10+ occurrences // PhanTypeInvalidDimOffset : 10+ occurrences + // PhanTypeMismatchArgumentNullableInternal : 10+ occurrences // PhanTypeMismatchProperty : 10+ occurrences // PhanTypeMismatchReturnNullable : 10+ occurrences // PhanUndeclaredFunction : 10+ occurrences @@ -56,12 +56,12 @@ // PhanTypeMismatchArgumentInternalReal : 7 occurrences // PhanCommentAbstractOnInheritedMethod : 6 occurrences // PhanDeprecatedClass : 5 occurrences - // PhanImpossibleCondition : 5 occurrences // PhanNonClassMethodCall : 5 occurrences // PhanTypeArraySuspiciousNull : 5 occurrences // PhanTypeMismatchDimAssignment : 5 occurrences // PhanTypeSuspiciousStringExpression : 5 occurrences // PhanAccessMethodInternal : 4 occurrences + // PhanImpossibleCondition : 4 occurrences // PhanTypeInvalidLeftOperandOfAdd : 4 occurrences // PhanTypeInvalidLeftOperandOfBitwiseOp : 4 occurrences // PhanTypeInvalidRightOperandOfBitwiseOp : 4 occurrences @@ -71,15 +71,12 @@ // PhanImpossibleTypeComparison : 3 occurrences // PhanPluginUnreachableCode : 3 occurrences // PhanStaticPropIsStaticType : 3 occurrences - // PhanTypeConversionFromArray : 3 occurrences // PhanTypeMismatchArgumentReal : 3 occurrences // PhanTypeObjectUnsetDeclaredProperty : 3 occurrences // PhanUndeclaredMethodInCallable : 3 occurrences - // PhanCompatibleNegativeStringOffset : 2 occurrences // PhanImpossibleConditionInLoop : 2 occurrences // PhanParamTooManyCallable : 2 occurrences // PhanPluginDuplicateSwitchCaseLooseEquality : 2 occurrences - // PhanRedefineFunctionInternal : 2 occurrences // PhanStaticCallToNonStatic : 2 occurrences // PhanTypeMismatchArgumentInternalProbablyReal : 2 occurrences // PhanUndeclaredClassInCallable : 2 occurrences @@ -87,13 +84,10 @@ // PhanDeprecatedPartiallySupportedCallable : 1 occurrence // PhanEmptyFQSENInCallable : 1 occurrence // PhanEmptyForeach : 1 occurrence - // PhanInfiniteRecursion : 1 occurrence // PhanPluginDuplicateSwitchCase : 1 occurrence // PhanPluginInvalidPregRegex : 1 occurrence - // PhanPluginRedundantAssignmentInLoop : 1 occurrence // PhanPluginUseReturnValueInternalKnown : 1 occurrence - // PhanTypeComparisonFromArray : 1 occurrence - // PhanTypeInvalidRightOperandOfNumericOp : 1 occurrence + // PhanTypeConversionFromArray : 1 occurrence // PhanTypeVoidArgument : 1 occurrence // PhanUndeclaredConstant : 1 occurrence // PhanUndeclaredExtendedClass : 1 occurrence @@ -392,7 +386,7 @@ 'modules/shortcodes/vimeo.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument'], 'modules/shortcodes/vr.php' => ['PhanPluginDuplicateConditionalNullCoalescing'], 'modules/shortcodes/wordads.php' => ['PhanNoopNew'], - 'modules/shortcodes/youtube.php' => ['PhanRedefineFunction', 'PhanTypeMismatchArgument'], + 'modules/shortcodes/youtube.php' => ['PhanRedefineFunction'], 'modules/shortlinks.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal'], 'modules/simple-payments/simple-payments.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchReturn'], 'modules/sitemaps/sitemap-buffer-fallback.php' => ['PhanTypeArraySuspicious'], diff --git a/projects/plugins/jetpack/changelog/feat-remove-custom-embed b/projects/plugins/jetpack/changelog/feat-remove-custom-embed new file mode 100644 index 0000000000000..fa651da5d0d6c --- /dev/null +++ b/projects/plugins/jetpack/changelog/feat-remove-custom-embed @@ -0,0 +1,4 @@ +Significance: patch +Type: compat + +Embeds: prioritize YouTube and Vimeo embeds provided by WordPress itself, over Jetpack's embedding solution. diff --git a/projects/plugins/jetpack/modules/shortcodes/vimeo.php b/projects/plugins/jetpack/modules/shortcodes/vimeo.php index b462c9a09fab9..b155083f478e5 100644 --- a/projects/plugins/jetpack/modules/shortcodes/vimeo.php +++ b/projects/plugins/jetpack/modules/shortcodes/vimeo.php @@ -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 $$next-version$$ * * @param array $matches Regex partial matches against the URL passed. * @param array $attr Attributes received in embed response. @@ -258,6 +268,7 @@ class_exists( 'Jetpack_AMP_Support' ) * @return string Return output of Vimeo shortcode with the proper markup. */ function wpcom_vimeo_embed_url( $matches, $attr, $url ) { + _deprecated_function( __FUNCTION__, 'jetpack-$$next-version$$' ); $vimeo_info = array( $url ); // If we are able to extract a video ID, use it in the shortcode instead of the full URL. @@ -278,21 +289,15 @@ function wpcom_vimeo_embed_url( $matches, $attr, $url ) { * http://player.vimeo.com/video/18427511 * * @since 3.9 + * @deprecated since $$next-version$$ * * @uses wpcom_vimeo_embed_url */ function wpcom_vimeo_embed_url_init() { + _deprecated_function( __FUNCTION__, 'jetpack-$$next-version$$' ); wp_embed_register_handler( 'wpcom_vimeo_embed_url', '#https?://(?:[^/]+\.)?vimeo\.com/(?:album/(?\d+)/)?(?:video/)?(?\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 +379,7 @@ function vimeo_link( $content ) { * Could erroneously capture: * This video (vimeo.com/12345) is teh cat's meow! */ - $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 ), diff --git a/projects/plugins/jetpack/modules/shortcodes/youtube.php b/projects/plugins/jetpack/modules/shortcodes/youtube.php index 14acabc318087..12a04cda37be7 100644 --- a/projects/plugins/jetpack/modules/shortcodes/youtube.php +++ b/projects/plugins/jetpack/modules/shortcodes/youtube.php @@ -527,21 +527,26 @@ 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 $$next-version$$ + * + * @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 ) { + _deprecated_function( __FUNCTION__, 'jetpack-$$next-version$$' ); return youtube_id( $url ); } /** * Add a new handler to automatically transform custom Youtube URLs (like playlists) into embeds. + * + * @deprecated since $$next-version$$ */ function wpcom_youtube_embed_crazy_url_init() { + _deprecated_function( __FUNCTION__, 'jetpack-$$next-version$$' ); 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() diff --git a/projects/plugins/jetpack/tests/php/modules/shortcodes/test-class.vimeo.php b/projects/plugins/jetpack/tests/php/modules/shortcodes/test-class.vimeo.php index 09dc5ce546e9b..52dccdc8416d6 100644 --- a/projects/plugins/jetpack/tests/php/modules/shortcodes/test-class.vimeo.php +++ b/projects/plugins/jetpack/tests/php/modules/shortcodes/test-class.vimeo.php @@ -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]" ) ); do_action( 'init' ); setup_postdata( $post ); diff --git a/projects/plugins/jetpack/tests/php/modules/shortcodes/test-class.youtube.php b/projects/plugins/jetpack/tests/php/modules/shortcodes/test-class.youtube.php index 44620dd0c6b96..b2268909170d0 100644 --- a/projects/plugins/jetpack/tests/php/modules/shortcodes/test-class.youtube.php +++ b/projects/plugins/jetpack/tests/php/modules/shortcodes/test-class.youtube.php @@ -97,14 +97,13 @@ public function get_youtube_id_options() { * @covers ::youtube_shortcode * @since 3.9 */ - public function test_replace_url_with_iframe_in_the_content() { + public function test_shortcodes_youtube_replace_url_with_iframe_in_the_content() { global $post; $youtube_id = 'JaNH56Vpg-A'; $url = 'http://www.youtube.com/watch?v=' . $youtube_id; - $post = self::factory()->post->create_and_get( array( 'post_content' => $url ) ); + $post = self::factory()->post->create_and_get( array( 'post_content' => "[youtube $url]" ) ); - wpcom_youtube_embed_crazy_url_init(); setup_postdata( $post ); ob_start(); // This below is needed since Core inserts "loading=lazy" right after the iframe opener.