Performance Lab: Show filesystem credentials modal on plugin install#2482
Draft
westonruter wants to merge 2 commits into
Draft
Performance Lab: Show filesystem credentials modal on plugin install#2482westonruter wants to merge 2 commits into
westonruter wants to merge 2 commits into
Conversation
When `FS_METHOD` is not `direct` and FTP/SSH credentials have not been stored, `Plugin_Upgrader::install()` returns `false` without raising a `WP_Error`, so the `:activate` REST endpoint falls through with a generic `plugin_not_found` 404 and the click on Activate appears to do nothing. The standard `Plugins > Add Plugin` flow handles the same case by displaying the "Connection Information" modal. Print that modal on the Performance Features screen, expose `filesystemCredentialsRequired` to the activation JS, and route the install through `wp.updates.installPlugin()` when credentials are required so the legacy AJAX install path supplies them. The install helper resolves with `'installed' | 'canceled'` so cancel is a normal control-flow outcome rather than an exception. After install, the existing REST `:activate` call performs the activation step (which no longer needs filesystem access).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #2482 +/- ##
==========================================
+ Coverage 69.33% 69.58% +0.24%
==========================================
Files 90 90
Lines 7749 7773 +24
==========================================
+ Hits 5373 5409 +36
+ Misses 2376 2364 -12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Cover the code paths added for the FS_METHOD-not-direct install flow: - perflab_load_features_page() registers the admin_footer modal printer. - perflab_enqueue_features_page_scripts() enqueues `updates` and prints the window.perflabPluginActivate inline data. - perflab_filesystem_credentials_required() returns false for the `direct` method, true when credentials are missing, and false when credentials are available (request_filesystem_credentials filter). - perflab_print_filesystem_credentials_modal() prints nothing for the `direct` method and the dialog markup when credentials are required. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the Performance Features install/activate flow when
FS_METHODis notdirect— for example,ftpext/ftpsockets.To reproduce on
trunk: withdefine( 'FS_METHOD', 'ftpsockets' );inwp-config.php, visit Settings → Performance and click Activate on a not-yet-installed feature plugin (e.g. Performant Translations). The click appears to do nothing — the button briefly says "Activating…" and then reverts. Under the hoodPOST /wp-json/performance-lab/v1/features/{slug}:activatereturns 404plugin_not_found. The chain of failures is silent:Plugin_Upgrader::install()callsWP_Upgrader::fs_connect(), which callsrequest_filesystem_credentials( false, … )— that returnsfalsewhen credentials aren't available.fs_connect()then returnsfalsewithout populating$skin->errors, soPlugin_Upgrader::install()returnsfalse(not aWP_Error).perflab_install_and_activate_plugin()falls through all of itsis_wp_error/$skin->get_errors()->has_errors()checks, then hits theget_plugins( '/' . $plugin_slug )empty check and returns the misleadingplugin_not_founderror.Plugins > Add Plugin handles the same case by displaying the standard "Connection Information" modal. This PR mirrors that flow on the Performance Features screen.
This is the Performance Lab adaptation of the same fix made for the Connectors screen in Gutenberg in WordPress/gutenberg#78367 (for Core-65223).
Changes
plugins/performance-lab/includes/admin/load.phpperflab_load_features_page()registers anadmin_footeraction to print the standard filesystem credentials modal.perflab_enqueue_features_page_scripts()enqueues theupdatesscript and useswp_add_inline_script(printed'before'the activation handler) to exposewindow.perflabPluginActivate.filesystemCredentialsRequired.perflab_filesystem_credentials_required()helper returns true whenget_filesystem_method() !== 'direct'andrequest_filesystem_credentials( self_admin_url() )isfalse.plugins/performance-lab/includes/admin/plugin-activate-ajax.jsfilesystemCredentialsRequiredis true, the install is routed through a newinstallPluginViaWpUpdates()helper that wrapswp.updates.installPlugin()and resolves with'installed' | 'canceled'. Cancellation is a normal control-flow outcome of the promise — not an error message string — so the caller branches on the discriminated return value, not onerror.message.wp.updates, etc.) still reject and flow through the existing} catch {path unchanged.:activatecall performs the activation step (which no longer needs filesystem access).The
plugin-activate-ajax.min.jsis generated bynpm run build:plugin:performance-laband is gitignored, so it isn't part of the diff.Test plan
wp-config.php, setdefine( 'FS_METHOD', 'ftpsockets' );(or'ftpext'). See Trac comment for how to set this up.performant-translationsis not installed, then visit Settings → Performance.directfilesystem environment — the install proceeds via REST as before, no modal.How AI was used
This fix was implemented with Claude Code as an adaptation of the Connectors-screen fix made for Gutenberg in WordPress/gutenberg#78367.
The Performance Lab work was kicked off with this prompt:
Summary of the conversation that followed:
plugin-activate-ajax.js→POST /performance-lab/v1/features/{slug}:activate→perflab_install_and_activate_plugin()→Plugin_Upgrader::install(). Confirmed viaWP_Upgrader::fs_connect()that the upgrader silently returnsfalsewhen filesystem credentials are missing, with no error set on the skin — which is why the helper falls through to theplugin_not_foundbranch.FS_METHOD=ftpsocketsand captured thePOST … 404 {"code":"plugin_not_found",…}response confirming the silent failure mode.wp.updatesand print the standard credentials modal on the Performance Features page; pass afilesystemCredentialsRequiredflag from PHP viawp_add_inline_script; have the activation JS route throughwp.updates.installPlugin()first when that flag is set, then continue to the existing REST:activatecall.new Error( 'Filesystem credentials request canceled.' )and matching the message string at the call site. Reviewer flagged this as brittle. RedesignedinstallPluginViaWpUpdates()to resolve with the discriminated string'installed' | 'canceled'instead — cancel is a normal resolved value, real errors still reject. Documented the return type via JSDoc.empty( $stored )(forbidden by the project's rule level); replaced withfalse === $stored. ESLint required JSDoc alignment fixes, auto-applied. PHPCS and TypeScript checks clean.npm run build:plugin:performance-lab. (First in-browser test ran the old cached JS; a hard reload picked up the new build.) Clicked Activate, FTP modal opened, entered valid credentials, plugin installed via FTP and activated, button flipped to Active. Verifiedwp plugin status performant-translationsreturnedStatus: Active. Cleaned up by deleting the test install and theftp_credentialsoption.Relationship to the Gutenberg PR's review feedback
This PR is a sibling of WordPress/gutenberg#78367, which received Copilot review feedback after this implementation was written. Because the Performance Lab work post-dated (and learned from) that review, the corrected patterns were applied here from the start — no follow-up changes are needed:
.on()not.one()for the install handlers —installPluginViaWpUpdates()registerswp-plugin-install-success/-error/credential-modal-cancelwith.on()+ an explicit slug-filteredcleanup(), so a concurrent install of a different plugin can't consume a one-shot handler and strand the promise. (Gutenberg fix: discussion_r3250956734.)'installed' | 'canceled'rather than throwing/matching a hard-coded message. (Gutenberg fix: discussion_r3250956865.)empty()— usesfalse === $storedto satisfy this repo's PHPStan rule level.pluginBasenameactivation note (discussion_r3250928328) does not apply here: Performance Lab activates via its own slug-basedPOST /performance-lab/v1/features/{slug}:activateendpoint, not the core/wp/v2/pluginspath.