Connection: Add hooks for external storage provider registration#48022
Connection: Add hooks for external storage provider registration#48022bindlegirl wants to merge 3 commits intotrunkfrom
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 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 2 files.
|
There was a problem hiding this comment.
Pull request overview
Adds two WordPress actions around external storage provider registration/first-read to make provider registration timing reliable, and ensures Jetpack connection status caching is invalidated when a provider is registered after an initial is_connected() evaluation.
Changes:
- Fire
jetpack_external_storage_initonce, before the firstExternal_Storage::get_value()read, to allow “late” provider registration. - Fire
jetpack_external_storage_provider_registeredafterExternal_Storage::register_provider()and invalidate memoized connection status inManager. - Add/extend integration and unit tests covering the new hooks and cache invalidation behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| projects/packages/connection/src/class-external-storage.php | Adds one-time init hook before first read; adds provider-registered hook after registration. |
| projects/packages/connection/src/class-manager.php | Resets memoized is_connected() when an external storage provider is registered. |
| projects/packages/connection/tests/php/External_Storage_Test.php | Adds tests for init/registered hooks; updates teardown to reset new static state. |
| projects/packages/connection/tests/php/ManagerIntegrationTest.php | Adds integration test verifying stale is_connected() cache is invalidated after provider registration. |
| projects/packages/connection/changelog/add-external-storage-provider-hooks | Documents the newly added hooks in the connection package changelog. |
projects/packages/connection/tests/php/ManagerIntegrationTest.php
Outdated
Show resolved
Hide resolved
fgiannar
left a comment
There was a problem hiding this comment.
Nice work here, Ana!
I only have a small recommendation: I believe that the cleanup logic in the unit tests you added should happen in tearDown or at least before the assertions.
Plus in test_registering_provider_invalidates_stale_is_connected shouldn't we also reset init_fired same way we do with provider?
- Move action hook cleanup (remove_all_filters) into tearDown() in External_Storage_Test so cleanup is guaranteed even if assertions fail. - Wrap assertions in try/finally in ManagerIntegrationTest to guarantee provider and init_fired cleanup. - Reset init_fired in ManagerIntegrationTest cleanup (per fgiannar). Made-with: Cursor
reset_connection_status() takes no parameters; explicitly pass 0 accepted_args so WordPress does not forward the provider argument. Made-with: Cursor
Proposed changes
jetpack_external_storage_initaction that fires before the first external storage read inExternal_Storage::get_value(). This gives mu-plugins (like CIAB/Garden) a guaranteed-safe point to register their storage provider viaadd_action()— no Jetpack classes need to exist at hook-registration time.jetpack_external_storage_provider_registeredaction that fires afterExternal_Storage::register_provider()is called.Manager::add_connection_status_invalidation_hooks()listens for this and resets the memoizedis_connected()result, so a provider registered "too late" still gets picked up on the next check.Why
On CIAB/Garden sites, connection data comes from external storage (Atomic Persistent Data), not the database. The storage provider is registered from a mu-plugin that loads before Jetpack. However, there was no guaranteed moment tween "Jetpack classes are available" and "Jetpack's first
is_connected()call." A recent early call tois_connected()during Jetpack's load (newsletter module) caused the result to be memoized asfalsebefore the provider was registered, breaking Big Sky's assembler on garden sites.These two hooks solve the problem from both directions:
Both are backward compatible. Existing consumers (wpcomsh/Atomic) register at include time before any reads; the new actions fire harmlessly with no effect.
Related product discussion/links
is_connected()memoizationDoes this pull request change what data or activity we track or use?
No.
Testing instructions
jetpack test php packes/connectiontest_init_action_fires_on_first_get_value— verifies the init action fires exactly oncetest_init_action_allows_late_provider_registration— verifies a provider registered during the init action serves the triggering readtest_provider_registered_action_fires— verifies the registered action fires with the correct provider instancetest_registering_provider_invalidates_stale_is_connected— verifies registering a provider afteris_connected()returnedfalseclears the cached result