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

Jetpack plugin - JSON API: Fix Warnings in post endpoints #38365

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Jetpack plugin - JSON API: Fix Warnings in post endpoints
8 changes: 3 additions & 5 deletions projects/plugins/jetpack/sal/class.json-api-post-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ public function get_author() {
// phpcs:disable WordPress.NamingConventions.ValidVariableName
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
$active_blog = get_active_blog_for_user( $user->ID );
$site_id = $active_blog->blog_id;
$site_id = $active_blog->blog_id ?? -1;
$profile_URL = "https://gravatar.com/{$user->user_login}";
} else {
$profile_URL = 'https://gravatar.com/' . md5( strtolower( trim( $user->user_email ) ) );
Expand Down Expand Up @@ -1017,11 +1017,9 @@ private function get_media_item_v1_1( $media_id ) {
}
}

$response['videopress_guid'] = $info->guid;
$response['videopress_guid'] = $info->guid ?? null;
Copy link
Contributor

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?

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 believe it wouldn't as it's safe to check object properties and sub-properties with isset directly. Checkout https://onlinephp.io/c/bacc9

Copy link
Contributor

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.

$response['videopress_processing_done'] = true;
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;
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}
}

Expand Down
Loading