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

[Media] Migrate WPCom media upload to /wp/v2 endpoints #14537

Merged
merged 8 commits into from
Nov 29, 2024

Conversation

selanthiraiyan
Copy link
Contributor

@selanthiraiyan selanthiraiyan commented Nov 27, 2024

Closes: #14232

Description

This PR updates the handling of the media operations (upload and fetch) to the user the /wp/v2 endpoints instead of the legacy /v1.1 ones, this is needed to fix upload problems for sites with XMLRPC issues.

Changes

  • Remove code which was using v1.1 endpoint for uploading media.
  • Call v2 endpoint method for all types of sites, including JCP and Application password login.
  • Update unit tests.

⚠️ There is a known issue related to loading media from WP media library and updating Product ID to media. #14550 We can work on this in a separate PR.

Steps to reproduce

a. No Jetpack case (Application Password)

  1. Have a .org site with no Jetpack,
  2. Install "Disable XML-RPC-API" plugin.
  3. In the app, login to site with application password,
  4. Go to Products > Add Product > Add Product Image
  5. Try uploading images from your device
  6. Save and Publish the product and validate that image uploads work.

b. Jetpack CP site case

  1. Have a .org site with no Jetpack but with a plugin with Jetpack CP (I use "Blaze Ads" and connect WPCOM account while attempting to create a Blaze campaign from the wp-admin page)
  2. Install "Disable XML-RPC-API" plugin.
  3. Setup the Jetpack CP plugin and connect it to your WordPress.com account
  4. In the app, login to site with WordPress.com account,
  5. Go to Products > Add Product > Add Product Image
  6. Try uploading images from your device
  7. Save and Publish the product and validate that image uploads work.

c. WordPress.com / full Jetpack site case

  1. Have a .org site with Jetpack plugin
  2. Install "Disable XML-RPC-API" plugin.
  3. Setup the Jetpack plugin and connect it to your WordPress.com account,
  4. In the app, login to site with WordPress.com account,
  5. Go to Products > Add Product > Add Product Image
  6. Try uploading images from your device
  7. Save and Publish the product and validate that image uploads work.

Testing information

  • I tested that images can uploaded for all the three site types. (JCP, Jetpack, Self-hosted application password login).

Screenshots

Screenshot 2024-11-27 at 9 56 28 PM
Simulator.Screen.Recording.-.iPhone.16.-.2024-11-27.at.21.57.32.mp4

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Nov 27, 2024

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr14537-3e96abc
Version21.2
Bundle IDcom.automattic.alpha.woocommerce
Commit3e96abc
App Center BuildWooCommerce - Prototype Builds #11853
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@selanthiraiyan selanthiraiyan added this to the 21.3 milestone Nov 28, 2024
@selanthiraiyan selanthiraiyan added the feature: add/edit products Related to adding or editing products. label Nov 28, 2024
@selanthiraiyan selanthiraiyan marked this pull request as ready for review November 28, 2024 06:18
@itsmeichigo itsmeichigo self-assigned this Nov 29, 2024
Copy link
Contributor

@itsmeichigo itsmeichigo left a comment

Choose a reason for hiding this comment

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

Tested with simulator iPhone 16 Pro iOS 18.0 and confirmed that uploading images works for sites (non-JP, JCP, or JP sites) without XMLRPC ✅

Comment on lines 21 to 24
func uploadMedia(siteID: Int64,
productID: Int64,
mediaItem: UploadableMedia,
completion: @escaping (Result<WordPressMedia, Error>) -> Void)
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nit: indentation needs to be updated here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Done in de07dbd

RELEASE-NOTES.txt Outdated Show resolved Hide resolved
@selanthiraiyan selanthiraiyan merged commit ef049cb into trunk Nov 29, 2024
14 checks passed
@selanthiraiyan selanthiraiyan deleted the feat/14232-media-upload-endpoint branch November 29, 2024 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: add/edit products Related to adding or editing products.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Product] Use wp/v2 endpoint for uploading images
3 participants