Skip to content
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

Merged
merged 14 commits into from
Aug 30, 2024

Conversation

arthur791004
Copy link
Contributor

@arthur791004 arthur791004 commented Aug 27, 2024

Fixes Automattic/wp-calypso#91098
Fixes #7370

Proposed changes:

  • The custom embed handler for both YouTube & Vimeo cannot get the title of the video resources so this PR aims to remove them in favor of Core's one.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

Copy link
Contributor

github-actions bot commented Aug 27, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the feat/remove-custom-embed branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack feat/remove-custom-embed
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Feature] Shortcodes / Embeds [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Aug 27, 2024
Copy link
Contributor

github-actions bot commented Aug 27, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen daily.
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for September 3, 2024 (scheduled code freeze on September 2, 2024).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions bot added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Tests] Includes Tests labels Aug 27, 2024
@arthur791004 arthur791004 force-pushed the feat/remove-custom-embed branch from 72d4cea to 0c9ff78 Compare August 27, 2024 11:26
@jeherve jeherve added [Focus] Accessibility Improving usability for all users (a11y) [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it labels Aug 27, 2024
* For bare URLs on their own line of the form.
*
* Accepted formats:
* https://vimeo.com/289091934/cd1f466bcc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be worth making sure that Core handles this format as well. Those are private videos, iirc. See this issue for more information:
Automattic/wp-calypso#57257

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check! I thought it's not supported by Vimeo now 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example of a live video would be https://vimeo.com/635643256/b6a59a4d1e
An example of a video to purchase would be https://vimeo.com/555942796/e712a2e45d

I tested the video that needs to purchase, and it works well. However, the above live video is outdated so I cannot check whether the live video with the above format works or not. But I tested another live video, https://vimeo.com/1003283038, and it works!

In short, I assume Core supports the vimeo video with the above format, e.g.: https://vimeo.com/555942796/e712a2e45d

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it supports all format as the Core uses http://vimeo.com/api/oembed.json endpoint to ask the information about the url, e.g. http://vimeo.com/api/oembed.json?url=http://vimeo.com/76979871

See http://developer.vimeo.com/apis/oembed

@arthur791004 arthur791004 force-pushed the feat/remove-custom-embed branch 6 times, most recently from 73d2b30 to 7f8c6bc Compare August 28, 2024 14:02
@arthur791004 arthur791004 self-assigned this Aug 29, 2024
@arthur791004 arthur791004 requested a review from a team August 29, 2024 02:25
@arthur791004 arthur791004 added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Status] Needs Team Review and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Aug 29, 2024
@arthur791004
Copy link
Contributor Author

The failing WordPress.com Tests is expected as we remove the wpcom_youtube_embed_crazy_url. So, we have to update the wpcom tests when deploying.

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good. I have some minor remarks on actually releasing this, below.

Comment on lines 2 to 4
Type: bugfix

Shortcode: Get rid of custom shortcodes for Youtube and Vimeo in favor of Core
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend updating this a bit:

Suggested change
Type: bugfix
Shortcode: Get rid of custom shortcodes for Youtube and Vimeo in favor of Core
Type: compat
Embeds: prioritize YouTube and Vimeo embeds provided by WordPress itself, over Jetpack's embedding solution.

*
* @return string Return output of Vimeo shortcode with the proper markup.
*/
function wpcom_vimeo_embed_url( $matches, $attr, $url ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of just removing the function, I would recommend marking it as deprecated first, and only remove it in a few releases. Since Vimeo embeds have been around for a long time, it's possible that third-parties currently do something with those functions.

Same for other functions in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

@@ -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]" ) );
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to test_shortcodes_vimeo_replace_url_with_iframe_in_the_content

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Status] Needs Team Review labels Aug 29, 2024
@arthur791004 arthur791004 added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Aug 29, 2024
@arthur791004 arthur791004 force-pushed the feat/remove-custom-embed branch from 942b555 to 12433e4 Compare August 29, 2024 12:37
@@ -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
Copy link
Member

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.

When needing to add a package version number inside a DocBlock, please use `$$next-version$$` as such:
- `@since $$next-version$$`
- `@deprecated $$next-version$$`
- `@deprecated since $$next-version$$`
- `_deprecated_function( __METHOD__, 'package-$$next-version$$' );` (other WordPress deprecation functions also work, but note it must be all on one line).
The `$$next-version$$` specifier will be automatically replaced with the correct package version number the next time a new version of that package is released.

Suggested change
* @deprecated since x.x.x
* @deprecated since $$next-version$$

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @deprecated since x.x.x
* @deprecated since $$next-version$$

*/
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @deprecated since x.x.x
* @deprecated since $$next-version$$

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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 _deprecated_function:
https://developer.wordpress.org/reference/functions/_deprecated_function/

- Deprecate classes, [functions](https://developer.wordpress.org/reference/functions/_deprecated_function/), and methods in the same way, while still returning its replacement if there is one.
- Deprecated code should remain in Jetpack for 6 months, so third-parties have time to find out about the deprecations and update their codebase.

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Aug 29, 2024
@arthur791004 arthur791004 merged commit c43d404 into trunk Aug 30, 2024
57 of 58 checks passed
@arthur791004 arthur791004 deleted the feat/remove-custom-embed branch August 30, 2024 02:36
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Aug 30, 2024
@github-actions github-actions bot added this to the jetpack/13.8 milestone Aug 30, 2024
@jeherve
Copy link
Member

jeherve commented Sep 2, 2024

8676719-zen seems to report issues when trying to embed a private YouTube video. @arthur791004 Do you think you could take a look at that?

@arthur791004
Copy link
Contributor Author

arthur791004 commented Sep 5, 2024

I tested a scheduled video, and

  • In the editor, it doesn't work and I don't think it's related to this change. But as 8676719-zd-a8c mentioned, it seemed to work in the editor before 🤔
  • In the frontend, it worked before as the wpcom_youtube_embed_crazy_url would convert the YouTube URL to the embed block. However, it doesn't work after this PR as the Core won't convert it to the embed block on the server side. Instead, you have to use the shortcode to display it

Now the current experience on both editor and frontend is the same, it would be better to propose changes to Gutenberg to support it in the editor. Does it make sense?


YouTube – only public and “unlisted” videos and playlists can be embedded. “private” videos cannot be embedded.

BTW referring to https://wordpress.org/documentation/article/embeds/, it seems the “private” video is not supported by Core, and the scheduled video is a private video before the scheduled time.

@jeherve
Copy link
Member

jeherve commented Sep 5, 2024

it would be better to propose changes to Gutenberg to support it in the editor. Does it make sense?

Yes, that would be a nice improvement.

@arthur791004
Copy link
Contributor Author

But the problem seems that the current YouTube oembed endpoint won't return the information of the private video 🥲

Here is the endpoint: https://www.youtube.com/oembed?format=json&url=<youtube_url>

gogdzl pushed a commit that referenced this pull request Oct 25, 2024
…r of Core (#39096)

* Shortcode: Get rid of custom shortcodes for Youtube and Vimeo in favor of Core

* changelog

* Fix tests

* Fix lint

* Fix tests

* Extend regex

* Don't need to mock http response

* Add youtube test back

* Update phan

* Deprecate functions instead of removal

* Update changelog

* Rename tests

* Fix lint

* Use 54910next-version54910
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Shortcodes / Embeds [Focus] Accessibility Improving usability for all users (a11y) [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
2 participants