-
Notifications
You must be signed in to change notification settings - Fork 800
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
Jetpack plugin - JSON API: Fix Warnings in post endpoints #38365
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
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 🤖 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. Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped. 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. |
@@ -1017,11 +1017,9 @@ private function get_media_item_v1_1( $media_id ) { | |||
} | |||
} | |||
|
|||
$response['videopress_guid'] = $info->guid; | |||
$response['videopress_guid'] = $info->guid ?? null; |
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.
I'm wondering if this should be is_object($info) ? $info->guid ?? null : null
? If guid is still a bool it would seem like this would still trigger a warning as we're trying to access a property on a bool?
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.
I believe it wouldn't as it's safe to check object properties and sub-properties with isset
directly. Checkout https://onlinephp.io/c/bacc9
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.
Ah true, it doesn't actually generate a PHP warning using isset, only editor notices in test cases.
if ( '0000-00-00 00:00:00' === $info->finish_date_gmt ) { | ||
$response['videopress_processing_done'] = false; | ||
} | ||
$response['videopress_processing_done'] = isset( $info->finish_date_gmt ) && '0000-00-00 00:00:00' !== $info->finish_date_gmt ? $info->finish_date_gmt : false; |
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.
With this one, would we also need to check if $info
is an object initially, for the same reason as the above comment?
So $response['videopress_processing_done'] = is_object($info) && isset($info->finish_date_gmt) && '0000-00-00 00:00:00' !== $info->finish_date_gmt ? $info->finish_date_gmt : false;
perhaps?
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.
Same as #38365 (comment)
Fixes the following Warnings in
class.json-api-post-base.php
:Attempt to read property "blog_id" on null
in line 794Attempt to read property "guid" on bool
in line 1020Undefined property: stdClass::$finish_date_gmt
in line 1022Attempt to read property "finish_date_gmt" on bool
in line 1022Proposed changes:
SAL_Post::get_author
: Ensure$active_blog->blog_id
is set before using it - Related toAttempt to read property "blog_id" on null
SAL_Post::get_media_item_v1_1
: Take into account thatvideo_get_info_by_blogpostid
may returnfalse
- Related toAttempt to read property "guid" on bool
andAttempt to read property "finish_date_gmt" on bool
SAL_Post::get_media_item_v1_1
: Take into account thatfinish_date_gmt
might be missing whenvideo_get_info_by_blogpostid
is executed on WPCOM - Related toUndefined property: stdClass::$finish_date_gmt
Other information:
Jetpack product discussion
p1HpG7-tpT-p2
Does this pull request change what data or activity we track or use?
No
Testing instructions: