diff --git a/backport-changelog/7.0/11779.md b/backport-changelog/7.0/11779.md new file mode 100644 index 00000000000000..08557620ebadf9 --- /dev/null +++ b/backport-changelog/7.0/11779.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/11779 + +* https://github.com/WordPress/gutenberg/pull/77521 diff --git a/lib/experimental/connectors/default-connectors.php b/lib/experimental/connectors/default-connectors.php index 3f71f7b46eef06..d12ed5391e7a72 100644 --- a/lib/experimental/connectors/default-connectors.php +++ b/lib/experimental/connectors/default-connectors.php @@ -554,7 +554,8 @@ function _gutenberg_get_connector_script_module_data( array $data ): array { $connectors[ $connector_id ] = $connector_out; } ksort( $connectors ); - $data['connectors'] = $connectors; + $data['connectors'] = $connectors; + $data['isFileModDisabled'] = ! wp_is_file_mod_allowed( 'install_plugins' ); return $data; } remove_filter( 'script_module_data_options-connectors-wp-admin', '_wp_connectors_get_connector_script_module_data' ); diff --git a/routes/connectors-home/ai-plugin-callout.tsx b/routes/connectors-home/ai-plugin-callout.tsx index 2431dfeff2ae86..aa63a8e02e6a37 100644 --- a/routes/connectors-home/ai-plugin-callout.tsx +++ b/routes/connectors-home/ai-plugin-callout.tsx @@ -197,11 +197,6 @@ export function AiPluginCallout() { return null; } - // Not installed and no permissions to install. - if ( pluginStatus === 'not-installed' && canInstallPlugins === false ) { - return null; - } - // Installed but can't activate (no manage permissions). if ( pluginStatus === 'inactive' && canManagePlugins === false ) { return null; @@ -215,6 +210,8 @@ export function AiPluginCallout() { ( ! initialHasConnectedProvider || justActivated ); const showInstallActivate = pluginStatus === 'not-installed' || pluginStatus === 'inactive'; + const hideButtons = + pluginStatus === 'not-installed' && canInstallPlugins === false; const getMessage = () => { if ( isJustConnected ) { @@ -262,29 +259,30 @@ export function AiPluginCallout() { a: , } ) }

- { showInstallActivate ? ( - - ) : ( - - ) } + { ! hideButtons && + ( showInstallActivate ? ( + + ) : ( + + ) ) } diff --git a/routes/connectors-home/default-connectors.tsx b/routes/connectors-home/default-connectors.tsx index 1ab02370bd8a36..2f2dec2db0e9e7 100644 --- a/routes/connectors-home/default-connectors.tsx +++ b/routes/connectors-home/default-connectors.tsx @@ -12,8 +12,8 @@ import { type ConnectorRenderProps, } from '@wordpress/connectors'; import { select } from '@wordpress/data'; -import { __ } from '@wordpress/i18n'; -import { Badge } from '@wordpress/ui'; +import { __, sprintf } from '@wordpress/i18n'; +import { Badge, Link } from '@wordpress/ui'; /** * Internal dependencies @@ -43,22 +43,34 @@ interface ConnectorData { authentication: NonNullable< ConnectorConfig[ 'authentication' ] >; } -/** - * Reads connector data passed from PHP via the script module data mechanism. - */ -export function getConnectorData(): Record< string, ConnectorData > { +interface ConnectorScriptModuleData { + connectors?: Record< string, ConnectorData >; + isFileModDisabled?: boolean; +} + +function getConnectorScriptModuleData(): ConnectorScriptModuleData { try { - const parsed = JSON.parse( + return JSON.parse( document.getElementById( 'wp-script-module-data-options-connectors-wp-admin' - )?.textContent ?? '' + )?.textContent ?? '{}' ); - return parsed?.connectors ?? {}; } catch { return {}; } } +/** + * Reads connector data passed from PHP via the script module data mechanism. + */ +export function getConnectorData(): Record< string, ConnectorData > { + return getConnectorScriptModuleData().connectors ?? {}; +} + +export function getIsFileModDisabled(): boolean { + return !! getConnectorScriptModuleData().isFileModDisabled; +} + const CONNECTOR_LOGOS: Record< string, React.ComponentType > = { google: GeminiLogo, openai: OpenAILogo, @@ -96,6 +108,19 @@ const ConnectedBadge = () => ( ); +const PluginDirectoryLink = ( { slug }: { slug: string } ) => ( + + { __( 'Learn more' ) } + +); + const UnavailableActionBadge = () => { __( 'Not available' ) }; function ApiKeyConnector( { @@ -166,7 +191,12 @@ function ApiKeyConnector( { actionArea={ { isConnected && } - { showUnavailableBadge && } + { showUnavailableBadge && + ( pluginSlug ? ( + + ) : ( + + ) ) } { showActionButton && (