SAL: expose has_password field in post API response#47938
SAL: expose has_password field in post API response#47938gabrielcaires wants to merge 6 commits intotrunkfrom
Conversation
Add a `has_password` boolean field to the post object format that
indicates whether a post is password protected, regardless of the
current user's permissions.
This allows the WordPress.com Reader to detect password-protected posts
from Atomic/Jetpack sites even when the requesting user is a site owner,
where `current_user_can('edit_post')` bypasses the usual WP_Error path.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
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 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
There was a problem hiding this comment.
Pull request overview
This PR updates Jetpack’s SAL-backed WordPress.com REST v1.1 post endpoints to expose a new boolean has_password field so clients (notably the Reader) can reliably detect password-protected posts even when the password field is filtered/omitted.
Changes:
- Add
has_passwordto the v1.1 post response schema and render it viarender_response_keys(). - Add
SAL_Post::get_has_password()to detect whetherpost_passwordis non-empty.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
projects/plugins/jetpack/sal/class.json-api-post-base.php |
Adds get_has_password() to the SAL post wrapper for detecting password protection. |
projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-post-v1-1-endpoint.php |
Documents and exposes has_password in v1.1 post responses via a new render switch case. |
projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-post-v1-1-endpoint.php
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-post-v1-1-endpoint.php
Show resolved
Hide resolved
…ost-v1-1-endpoint.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Automattic/jetpack/sessions/128a46d5-4eee-4032-9a33-ca3c58162d63 Co-authored-by: gabrielcaires <38718+gabrielcaires@users.noreply.github.com>
Code Coverage SummaryCoverage changed in 3 files.
|
projects/plugins/jetpack/changelog/update-fix-466-add-has-password-field
Outdated
Show resolved
Hide resolved
…word-field Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Initial plan * SAL: Add has_password field to post API response, fix PHPCS class name Agent-Logs-Url: https://github.com/Automattic/jetpack/sessions/96aeb0a5-16dd-4046-b6ed-5c39575ff33e Co-authored-by: gabrielcaires <38718+gabrielcaires@users.noreply.github.com> * SAL: Use ! empty() for has_password check (more idiomatic WordPress) Agent-Logs-Url: https://github.com/Automattic/jetpack/sessions/96aeb0a5-16dd-4046-b6ed-5c39575ff33e Co-authored-by: gabrielcaires <38718+gabrielcaires@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gabrielcaires <38718+gabrielcaires@users.noreply.github.com> Co-authored-by: Gabriel Caires <gabriel.caires@automattic.com>
Part of READ-446
Expose has_password field to permit reader show better information about how the user can see the post.
Summary
has_passwordboolean field to$post_object_formatinWPCOM_JSON_API_Post_v1_1_Endpointcase 'has_password':inrender_response_keys()calling$post->get_has_password()get_has_password()method toSAL_Post— returnstrueifpost_passwordis non-empty, regardless of whether the current user can view the password valueSalPostsTestcoversget_has_password()directly on the SAL wrapper;WPCOM_JSON_API_Get_Post_v1_1_Endpoint_Testcovers thehas_passwordfield in the v1.1 API responseDoes this pull request change what data or activity we track or use?
N/A
Why
When a site owner (user with
edit_postcapability) requests a password-protected post via the WordPress.com Reader,can_access_post()bypasses theWP_Errorpath. The existingpasswordfield is filtered out before reaching the Reader endpoint. A dedicated boolean field allows the Reader to reliably detect password-protected posts and show the standard placeholder, regardless of whether the current user can view the password value.Companion change to wpcom PR wpcom/pull/210471 (READ-446).
Testing instructions: