Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add the new source data to the media REST API endpoint#3025

Closed
mukeshpanchal27 wants to merge 5 commits into
WordPress:trunkfrom
mukeshpanchal27:add/source-to-media-rest-api-endpoint
Closed

Add the new source data to the media REST API endpoint#3025
mukeshpanchal27 wants to merge 5 commits into
WordPress:trunkfrom
mukeshpanchal27:add/source-to-media-rest-api-endpoint

Conversation

@mukeshpanchal27

@mukeshpanchal27 mukeshpanchal27 commented Jul 26, 2022

Copy link
Copy Markdown
Member

The PR adds new source data to the media REST API endpoint.

Trac ticket: https://core.trac.wordpress.org/ticket/55443


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@mukeshpanchal27 mukeshpanchal27 marked this pull request as ready for review July 26, 2022 11:09

@felixarntz felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mukeshpanchal27 This looks off to a great start. I left some feedback on some nit-pick code improvements, but the most important thing here is about how to handle the full size, similar to what I mentioned in the plugin PR.

Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php Outdated
@felixarntz

Copy link
Copy Markdown
Member

@mukeshpanchal27 I've added the Trac ticket link to https://core.trac.wordpress.org/ticket/55443 since that should be committed as part of that ticket, as a follow-up to https://core.trac.wordpress.org/changeset/53751.

@aaemnnosttv aaemnnosttv left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looking good @mukeshpanchal27 ! I left a few suggestions around the tests for your consideration. Someone else should be the one to approve this though 😄

Comment thread tests/phpunit/tests/rest-api/rest-attachments-controller.php Outdated
Comment on lines +2294 to +2296
// WebP may not be supported by the server, in which case it will be stripped from the results.
if ( wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
foreach ( $mime_types as $mime_type ) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this entire block only relevant when webp is supported or would this only apply when $mime_type === 'image/webp'? Are these assertions not also valuable for image/jpeg?

Ideally I think we could remove the conditional here by setting up the test in a way where we control the support in a predictable way E.g. it_should_allow_the_upload_of_a_web_p_image_if_at_least_one_editor_supports_the_format

Then maybe we would have two separate test cases: one for where it is supported and one where it is not 🙂

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have adjusted the WebP support conditions so if the server does not support WebP, then the test only tests the image/jpeg mime type.

Does it make sense, or do I need to add two separate test cases?

@mehulkaklotar mehulkaklotar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mukeshpanchal27 all changes looks good, I have one comment about using referenced variables in loop. Please have a look.

Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php Outdated

@felixarntz felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mukeshpanchal27 Great work! This is looking almost good to commit. Only a few tiny nit-picks left to address.

Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php Outdated
Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php Outdated
Comment thread tests/phpunit/tests/rest-api/rest-attachments-controller.php

@felixarntz felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mukeshpanchal27 Just one tiny thing, other than that this looks great!

Comment thread src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php Outdated

@felixarntz felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Excellent, thank you @mukeshpanchal27!

@felixarntz

Copy link
Copy Markdown
Member

Committed to trunk in https://core.trac.wordpress.org/changeset/53786.

I made just one small tweak I realized last minute: It's safer to use the actual image URL from wp_get_attachment_image_src() and replace the relevant file name with the file information. This is similar to how image_downsize() does it, so we should use that here rather than dirname().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants