Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
171d758
Connectors: Show filesystem credentials modal on plugin install
westonruter May 15, 2026
c75cf6c
Use more specific array types
westonruter May 15, 2026
7da7cfd
Avoid use of empty()
westonruter May 15, 2026
cfeeea4
Connectors: Harden wp.updates install fallback per review
westonruter May 15, 2026
8d3b1c2
Connectors: Fix AI plugin callout install when FS credentials required
westonruter May 16, 2026
9ae49aa
Merge remote-tracking branch 'origin/trunk' into fix/65223-connectors…
westonruter May 16, 2026
675d2eb
Connectors: Use strict false check for filesystem credentials sentinel
westonruter May 16, 2026
516b74b
Connectors: Fix AiPluginCallout test mock and add FS-credentials cove…
westonruter May 18, 2026
530755e
Connectors: Use @types/jquery instead of a hand-rolled jQuery shape
westonruter May 18, 2026
6b1ccfb
Merge branch 'trunk' into fix/65223-connectors-fs-credentials
t-hamano Jun 2, 2026
e6b5ff5
Merge branch 'trunk' into fix/65223-connectors-fs-credentials
claude Oct 14, 2026
265ba3f
Connectors: Detect filesystem credentials need from REST fs_unavailab…
claude Oct 14, 2026
cc37947
Add backport changelog entry for wordpress-develop#13953
claude Oct 14, 2026
38dd6bc
Merge branch 'trunk' into fix/65223-connectors-fs-credentials
t-hamano Nov 11, 2026
515d920
Remove unnecessary require_once statements
t-hamano Nov 11, 2026
2a80081
Fix install button stuck on "Installing…" on invalid admin-ajax respo…
t-hamano Nov 11, 2026
a55a646
Open filesystem credentials modal before install and catch invalid re…
t-hamano Nov 11, 2026
8326644
Merge branch 'trunk' into fix/65223-connectors-fs-credentials
t-hamano Nov 11, 2026
49ca8c3
Pass the install button to the credentials modal instead of reading t…
claude Nov 11, 2026
5c827e9
Update the backport changelog to the new core PR
claude Nov 11, 2026
987e3ef
Point the backport changelog entry to the new core PR
claude Nov 11, 2026
e1673b5
Merge branch 'trunk' into fix/65223-connectors-fs-credentials
peterwilsoncc Nov 15, 2026
0560835
Follow inline docs style-guide for multiline comemnts.
peterwilsoncc Nov 15, 2026
2ca9b03
Merge branch 'trunk' into fix/65223-connectors-fs-credentials
peterwilsoncc Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion lib/experimental/connectors/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function _gutenberg_connectors_add_settings_menu_item(): void {
remove_submenu_page( 'options-general.php', 'connectors-wp-admin' );
remove_submenu_page( 'options-general.php', 'options-connectors.php' );

add_submenu_page(
$hook_suffix = add_submenu_page(
'options-general.php',
__( 'Connectors', 'gutenberg' ),
__( 'Connectors', 'gutenberg' ),
Expand All @@ -32,6 +32,74 @@ function _gutenberg_connectors_add_settings_menu_item(): void {
'gutenberg_options_connectors_wp_admin_render_page',
1
);

if ( $hook_suffix ) {
add_action( "load-{$hook_suffix}", '_gutenberg_connectors_load_screen' );
}
}

/**
* Sets up the Connectors screen for plugin installation via the standard
* `wp.updates` AJAX flow.
*
* Plugin installation from the Connectors screen goes through the REST
* `/wp/v2/plugins` endpoint, which fails outright when the filesystem method
* is not `direct` and credentials have not yet been stored. Enqueuing the
* `updates` script and printing the standard "Connection Information" modal
* mirrors what Plugins > Add Plugin already provides, so the React layer
* can fall back to `wp.updates.installPlugin()` for the credentials flow.
*
* @access private
*/
function _gutenberg_connectors_load_screen(): void {
wp_enqueue_script( 'updates' );
add_action( 'admin_footer', '_gutenberg_connectors_print_filesystem_credentials_modal' );
}

/**
* Prints the filesystem credentials modal on the Connectors screen.
*
* @access private
*/
function _gutenberg_connectors_print_filesystem_credentials_modal(): void {
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/template.php';

wp_print_request_filesystem_credentials_modal();
wp_print_admin_notice_templates();
}

/**
* Exposes whether the current request can install plugins directly to the
* Connectors script module.
*
* When the filesystem method is anything other than `direct` and stored
* credentials are not yet available, the REST plugin endpoint will reject
* an install attempt up front. Surfacing this state to the client lets the
* React layer pre-emptively route through `wp.updates.installPlugin()`,
* which displays the standard filesystem credentials modal.
*
* @access private
*
* @param array $data Existing script module data.
* @return array Script module data with the filesystem flag added.
Comment thread
westonruter marked this conversation as resolved.
Resolved
*/
function _gutenberg_connectors_add_filesystem_data_to_script_module_data( array $data ): array {
require_once ABSPATH . 'wp-admin/includes/file.php';

$method = get_filesystem_method();
if ( 'direct' === $method ) {
$data['filesystemCredentialsRequired'] = false;
return $data;
}

ob_start();
$stored = request_filesystem_credentials( self_admin_url() );
ob_end_clean();

$data['filesystemCredentialsRequired'] = empty( $stored );
Comment thread
westonruter marked this conversation as resolved.
Resolved
return $data;
}
add_filter( 'script_module_data_options-connectors-wp-admin', '_gutenberg_connectors_add_filesystem_data_to_script_module_data' );

require __DIR__ . '/default-connectors.php';
6 changes: 6 additions & 0 deletions routes/connectors-home/default-connectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface ConnectorData {
interface ConnectorScriptModuleData {
connectors?: Record< string, ConnectorData >;
isFileModDisabled?: boolean;
filesystemCredentialsRequired?: boolean;
}

function getConnectorScriptModuleData(): ConnectorScriptModuleData {
Expand All @@ -71,6 +72,10 @@ export function getIsFileModDisabled(): boolean {
return !! getConnectorScriptModuleData().isFileModDisabled;
}

export function getRequiresFilesystemCredentials(): boolean {
return !! getConnectorScriptModuleData().filesystemCredentialsRequired;
}

const CONNECTOR_LOGOS: Record< string, React.ComponentType > = {
google: GeminiLogo,
openai: OpenAILogo,
Expand Down Expand Up @@ -170,6 +175,7 @@ function ApiKeyConnector( {
isActivated: plugin?.isActivated,
keySource: auth?.keySource,
initialIsConnected: auth?.isConnected,
requiresFilesystemCredentials: getRequiresFilesystemCredentials(),
} );
const isExternallyConfigured =
keySource === 'env' || keySource === 'constant';
Expand Down
138 changes: 131 additions & 7 deletions routes/connectors-home/use-connector-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,100 @@ interface UseConnectorPluginOptions {
isActivated?: boolean;
keySource?: ApiKeySource;
initialIsConnected?: boolean;
requiresFilesystemCredentials?: boolean;
}

interface WpUpdatesInstallPluginResponse {
slug: string;
plugin?: string;
}

interface WpUpdatesInstallPluginErrorResponse {
slug: string;
errorCode?: string;
errorMessage?: string;
}

interface WpUpdates {
installPlugin: ( args: { slug: string } ) => void;
}
Comment thread
t-hamano marked this conversation as resolved.
Resolved

interface WpUpdatesGlobal {
wp?: {
updates?: WpUpdates;
};
jQuery?: ( target: Document ) => {
one: (
event: string,
handler: (
event: unknown,
response:
| WpUpdatesInstallPluginResponse
| WpUpdatesInstallPluginErrorResponse
) => void
) => unknown;
off: ( event: string, handler: unknown ) => unknown;
};
}
Comment thread
t-hamano marked this conversation as resolved.
Resolved

function installPluginViaWpUpdates( slug: string ): Promise< void > {
return new Promise( ( resolve, reject ) => {
const w = window as unknown as WpUpdatesGlobal;
const jq = w.jQuery;
const updates = w.wp?.updates;
if ( ! jq || ! updates?.installPlugin ) {
reject( new Error( 'wp.updates.installPlugin is not available.' ) );
return;
}

const onSuccess = (
_event: unknown,
response:
| WpUpdatesInstallPluginResponse
| WpUpdatesInstallPluginErrorResponse
) => {
if (
( response as WpUpdatesInstallPluginResponse ).slug !== slug
) {
return;
}
cleanup();
resolve();
};
const onError = (
_event: unknown,
response:
| WpUpdatesInstallPluginResponse
| WpUpdatesInstallPluginErrorResponse
) => {
if (
( response as WpUpdatesInstallPluginErrorResponse ).slug !==
slug
) {
return;
}
cleanup();
const errResponse = response as WpUpdatesInstallPluginErrorResponse;
reject(
new Error( errResponse.errorMessage ?? 'Install failed.' )
);
};
const onCancel = () => {
cleanup();
reject( new Error( 'Filesystem credentials request canceled.' ) );
};
const cleanup = () => {
jq( document ).off( 'wp-plugin-install-success', onSuccess );
jq( document ).off( 'wp-plugin-install-error', onError );
jq( document ).off( 'credential-modal-cancel', onCancel );
};

jq( document ).one( 'wp-plugin-install-success', onSuccess );
jq( document ).one( 'wp-plugin-install-error', onError );
jq( document ).one( 'credential-modal-cancel', onCancel );

updates.installPlugin( { slug } );
Comment thread
t-hamano marked this conversation as resolved.
Resolved
Comment thread
t-hamano marked this conversation as resolved.
Resolved
} );
}

interface UseConnectorPluginReturn {
Expand All @@ -45,6 +139,7 @@ export function useConnectorPlugin( {
isActivated,
keySource = 'none',
initialIsConnected = false,
requiresFilesystemCredentials = false,
}: UseConnectorPluginOptions ): UseConnectorPluginReturn {
const [ isExpanded, setIsExpanded ] = useState( false );
const [ isBusy, setIsBusy ] = useState( false );
Expand Down Expand Up @@ -168,12 +263,35 @@ export function useConnectorPlugin( {
}
setIsBusy( true );
try {
await saveEntityRecord(
'root',
'plugin',
{ slug: pluginSlug, status: 'active' },
{ throwOnError: true }
);
if ( requiresFilesystemCredentials ) {
// The REST plugin endpoint rejects installs up front when
// FS_METHOD is not 'direct' and credentials have not been
// stored. Route through wp.updates.installPlugin() so the
// standard "Connection Information" modal handles credential
// entry, then activate via REST.
await installPluginViaWpUpdates( pluginSlug );
if ( pluginBasename ) {
await saveEntityRecord(
'root',
'plugin',
{ plugin: pluginBasename, status: 'active' },
{ throwOnError: true }
);
Comment thread
t-hamano marked this conversation as resolved.
Resolved
}
// Refresh plugin entity so derived state reflects install.
invalidateResolution( 'getEntityRecord', [
'root',
'plugin',
pluginBasename,
] );
} else {
await saveEntityRecord(
'root',
'plugin',
{ slug: pluginSlug, status: 'active' },
{ throwOnError: true }
);
}
setPluginStatusOverride( 'active' );
// Re-fetch settings since the new plugin may register new settings.
invalidateResolution( 'getEntityRecord', [ 'root', 'site' ] );
Expand All @@ -189,7 +307,13 @@ export function useConnectorPlugin( {
type: 'snackbar',
}
);
} catch {
} catch ( error ) {
// A user-initiated cancel of the filesystem credentials dialog
// should silently abort the install without a snackbar.
const message = error instanceof Error ? error.message : '';
if ( message === 'Filesystem credentials request canceled.' ) {
return;
}
Comment thread
t-hamano marked this conversation as resolved.
Resolved
createErrorNotice(
sprintf(
/* translators: %s: Name of the connector (e.g. "OpenAI"). */
Expand Down
Loading