Connection: register WP Abilities API reads#48735
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 🤖 🔴 Action required: Please include detailed testing steps, explaining how to test your change, like so: 🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so: Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage Summary1 file is newly checked for coverage.
|
Summary
Adds two read-only abilities to the
automattic/jetpack-connectionpackage so AI agents can inspect site- and user-level Jetpack connection state through the standardwp-abilities/v1REST surface.Slugs registered:
jetpack-connection/get-connection-status— site-level state as{ site_connected, user_connected, master_user, plan_class, blog_id, registration_url, jetpack_version }. Zero-arg. Read-only. Idempotent.jetpack-connection/get-current-user-connection— calling user's state as{ id, login, connected, is_master_user, connect_url }. ReturnsWP_Error(jetpack_connection_not_logged_in) for anonymous callers. Read-only. Idempotent.Both abilities extend
Automattic\Jetpack\WP_Abilities\Registrar, are gated behind the package-widejetpack_wp_abilities_enabledfilter (defaultfalse), and useManager::is_connected()/Manager::has_connected_user()/Manager::is_user_connected()rather than raw option reads.Writes (registering / disconnecting / transferring ownership) are deliberately deferred to a follow-up PR.
Cross-consumer wiring
The Connection package is consumed by every Jetpack-family plugin (jetpack, boost, social, search, protect, backup, etc.), so registration is wired from
projects/packages/connection/actions.phpatplugins_loadedpriority 20. As soon as a site opts in to abilities via thejetpack_wp_abilities_enabledfilter, every connection-consuming plugin will see these two slugs without each one needing its own wiring.Rollout plan reference
Maps to §4.2 (package-backed abilities live in their package) and §4.5 (cross-consumer wiring via
actions.php) of the Abilities Everywhere rollout plan.Test plan
composer phpunit -- --filter Connection_Abilities_Testpasses locally (16 tests, 69 assertions).should_registerfilter), abstract getters (slug / definition / specs), permission callbacks (anonymous denied / authenticated allowed), execute happy paths for both abilities (withConnection_Managerstub injected via a newjetpack_connection_abilities_managerfilter), and the anonymousWP_Errorpath forget-current-user-connection.phpcsclean on the new/changed files using the repo.phpcs.xml.distruleset.changelogger validateexits 0; changelog entry added atprojects/packages/connection/changelog/add-connection-abilities(typeadded, significanceminor).add_filter( 'jetpack_wp_abilities_enabled', '__return_true' ), confirm both slugs show up viawp_get_abilities()and/wp-json/wp-abilities/v1/abilities.