-
Notifications
You must be signed in to change notification settings - Fork 817
WPCOM_JSON_API_Endpoint: Add individual checks for array properties to prevent warnings #43656
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
base: trunk
Are you sure you want to change the base?
WPCOM_JSON_API_Endpoint: Add individual checks for array properties to prevent warnings #43656
Conversation
…s an array returned
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Code Coverage SummaryCoverage changed in 1 file.
|
$metadata = wp_get_attachment_metadata( $media_item->ID ); | ||
if ( isset( $metadata['height'], $metadata['width'] ) ) { | ||
if ( isset( $metadata['height'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No warnings were being generated for this, other than a codesniffer message suggestingisset
should only check one parameter at a time, hence the change. Same further down as well (around line 1774).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix proposed in the previous PR resulted in some fatals such as Fatal error: Uncaught Error: Cannot use object of type WP_Error as array (in class.wpcom-json-api-upload-media-v1-1-endpoint.php:168).
Out of curiosity, since the previous fix seems to cover all these cases how come we are not fixing this in class.wpcom-json-api-upload-media-v1-1-endpoint.php:168
by removing 'file' => $media_item['ID'],
?
I believe we should fix this one anyways. Unless there were more fatals other than the ones coming from that endpoint
Fixes VULCAN-128
Proposed changes:
Undefined property: stdClass::$ID
(on lines 1677, 1685, 1697, 1698, 1709)Undefined property: stdClass::$post_parent
(on lines 1701, 1886)Undefined property: stdClass::$guid
(line 1699)Fatal error: Uncaught Error: Cannot use object of type WP_Error as array
(inclass.wpcom-json-api-upload-media-v1-1-endpoint.php:168
).$media_item
is not a properWP_Post
object, individual property checks have been added throughout the function instead.null
is used as a fallback for$response
values in most cases as this would replicate what would be returned if properties were undefined, but in some cases I've added an empty string instead where an empty string would make more sense (alt
,description
, for example).Other information:
Jetpack product discussion
pdWQjU-1g0-p2
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
To replicate the warnings:
While I can't replicate the warnings 'naturally', they can be replicated with a bit of manipulation:
https://developer.wordpress.com/docs/api/console/
- and open up the Network tab in the browser console.media_urls
add a URL for a video already on your Simple site (or any other URL to a video such as a sample video online). You could add a link to an image URL as well.$media_item
here (inproduction
, assuming that is the Jetpack plugin folder being used while testing), override$media_item
with a new object. Format such as:To test the fix:
$media_item
from before (but inmoon
orsun
, whichever is active), and there should be no warnings.$media_path
item and test again, the video / image should upload as expected still.