Skip to content

SAL_Site: Prevent warnings due to reading properties on null #44195

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

Merged

Conversation

coder-karen
Copy link
Contributor

@coder-karen coder-karen commented Jul 4, 2025

Fixes VULCAN-228

Proposed changes:

  • This PR adds property checks within the user_can_view_post function, specifically with regard to checking the $parent_post, and therefore the $post_status_obj value. Both get_post and get_post_status_object can return null so we should allow for that, and ensure the rest of the code continues processing as before if these values are null.
  • What we are preventing are warnings that were being output in logs.

Logs: e1891edb5a21bf2c639db4455ebc23cc-logstash

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

pdWQjU-1g0-p2

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

  • Code-review

  • You can also test this by visiting the URL mentioned in the Linear issue, and then on trunk observing a new entry in the above linked Logstash logs.

  • If you are have sandboxed https://public-api. wordpress.com/, you should also see an error while tailing for errors: tail -f /tmp/php-errors

  • You can confirm the change prevents the warning and doesn't impact the output by using the commands in the generated comment below and sandboxing https://public-api. wordpress.com/, while tailing for errors. No errors should be generated.

@coder-karen coder-karen self-assigned this Jul 4, 2025
@coder-karen coder-karen added [Type] Bug When a feature is broken and / or not performing as intended [Status] In Progress labels Jul 4, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the update/class-json-api-site-base-prevent-prop-warnings branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/class-json-api-site-base-prevent-prop-warnings

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Jul 4, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

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:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: August 5, 2025
    • Code freeze: August 4, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

Copy link

jp-launch-control bot commented Jul 4, 2025

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

@coder-karen coder-karen marked this pull request as ready for review July 4, 2025 16:18
@coder-karen coder-karen added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Jul 4, 2025
@coder-karen coder-karen requested a review from a team July 4, 2025 16:18
Comment on lines 788 to 793
if (
( 'trash' === $post->post_status && current_user_can( 'edit_post', $post->ID ) )
|| 'auto-draft' === $post->post_status
) {
$authorized = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker, but we could check here if $authorized was already set to true, and not evaluate. Similar how it was before with the short-circuit logic.

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 idea - added in 4adf206

Copy link
Contributor

@darssen darssen left a comment

Choose a reason for hiding this comment

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

Thanks for working on this one @coder-karen

Changes look good from a code review perspective. Left a minor comment.

darssen
darssen previously approved these changes Jul 7, 2025
Copy link
Contributor

@darssen darssen left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Co-authored-by: Juanma Rodriguez Escriche <juanma.rodriguez.escriche@automattic.com>
@coder-karen coder-karen merged commit afe2063 into trunk Jul 7, 2025
67 checks passed
@coder-karen coder-karen deleted the update/class-json-api-site-base-prevent-prop-warnings branch July 7, 2025 11:54
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Jul 7, 2025
@github-actions github-actions bot added this to the jetpack/14.9 milestone Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants