Skip to content

Commit caf93b0

Browse files
gzioloclaude
andcommitted
Address review feedback for connector logo URL support
- Remove static default-connector-logo.svg file, use inline JSX instead - Add file_exists() check in _gutenberg_resolve_ai_provider_logo_url() - Document logo_url in _gutenberg_get_connector_settings() docblock - Use site_url() instead of hardcoded URLs in tests - Add test for non-existent file path returning null - Use try/finally for test cleanup safety Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f14d436 commit caf93b0

File tree

5 files changed

+89
-21
lines changed

5 files changed

+89
-21
lines changed

lib/experimental/connectors/default-connector-logo.svg

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/experimental/connectors/default-connectors.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ function _gutenberg_resolve_ai_provider_logo_url( string $path ): ?string {
100100

101101
$path = wp_normalize_path( $path );
102102

103+
if ( ! file_exists( $path ) ) {
104+
return null;
105+
}
106+
103107
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
104108
if ( str_starts_with( $path, $mu_plugin_dir . '/' ) ) {
105109
return plugins_url( substr( $path, strlen( $mu_plugin_dir ) ), WPMU_PLUGIN_DIR . '/.' );
@@ -136,6 +140,7 @@ function _gutenberg_resolve_ai_provider_logo_url( string $path ): ?string {
136140
* @type array $plugin Optional. Plugin data for install/activate UI.
137141
* @type string $slug The WordPress.org plugin slug.
138142
* }
143+
* @type string $logo_url Optional. URL to the connector's logo image.
139144
* @type array $authentication {
140145
* Authentication configuration. When method is 'api_key', includes
141146
* credentials_url and setting_name. When 'none', only method is present.
@@ -232,7 +237,7 @@ function _gutenberg_get_connector_settings(): array {
232237
$connectors[ $connector_id ] = array(
233238
'name' => $name ? $name : ucwords( $connector_id ),
234239
'description' => $description ? $description : '',
235-
'logo_url' => $logo_url ? $logo_url : plugins_url( 'default-connector-logo.svg', __FILE__ ),
240+
'logo_url' => $logo_url,
236241
'type' => 'ai_provider',
237242
'authentication' => $authentication,
238243
);

phpunit/experimental/connectors/resolve-ai-provider-logo-url-test.php

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,54 @@ public function test_returns_null_when_path_is_empty() {
1111
}
1212

1313
public function test_resolves_plugin_dir_path_to_url() {
14-
$result = _gutenberg_resolve_ai_provider_logo_url( WP_PLUGIN_DIR . '/my-plugin/logo.svg' );
15-
$this->assertSame( 'http://localhost:8889/wp-content/plugins/my-plugin/logo.svg', $result );
14+
$logo_path = WP_PLUGIN_DIR . '/my-plugin/logo.svg';
15+
16+
// Create the file so file_exists() passes.
17+
wp_mkdir_p( dirname( $logo_path ) );
18+
file_put_contents( $logo_path, '<svg></svg>' );
19+
20+
try {
21+
$result = _gutenberg_resolve_ai_provider_logo_url( $logo_path );
22+
$this->assertSame( site_url( '/wp-content/plugins/my-plugin/logo.svg' ), $result );
23+
} finally {
24+
unlink( $logo_path );
25+
rmdir( dirname( $logo_path ) );
26+
}
1627
}
1728

1829
public function test_resolves_mu_plugin_dir_path_to_url() {
19-
$result = _gutenberg_resolve_ai_provider_logo_url( WPMU_PLUGIN_DIR . '/my-mu-plugin/logo.svg' );
20-
$this->assertSame( 'http://localhost:8889/wp-content/mu-plugins/my-mu-plugin/logo.svg', $result );
30+
$logo_path = WPMU_PLUGIN_DIR . '/my-mu-plugin/logo.svg';
31+
32+
// Create the file so file_exists() passes.
33+
wp_mkdir_p( dirname( $logo_path ) );
34+
file_put_contents( $logo_path, '<svg></svg>' );
35+
36+
try {
37+
$result = _gutenberg_resolve_ai_provider_logo_url( $logo_path );
38+
$this->assertSame( site_url( '/wp-content/mu-plugins/my-mu-plugin/logo.svg' ), $result );
39+
} finally {
40+
unlink( $logo_path );
41+
rmdir( dirname( $logo_path ) );
42+
}
43+
}
44+
45+
public function test_returns_null_when_file_does_not_exist() {
46+
$result = _gutenberg_resolve_ai_provider_logo_url( WP_PLUGIN_DIR . '/nonexistent/logo.svg' );
47+
$this->assertNull( $result );
2148
}
2249

2350
/**
2451
* @expectedIncorrectUsage _gutenberg_resolve_ai_provider_logo_url
2552
*/
2653
public function test_returns_null_and_triggers_doing_it_wrong_for_path_outside_plugin_dirs() {
27-
$result = _gutenberg_resolve_ai_provider_logo_url( '/some/random/path/logo.svg' );
28-
$this->assertNull( $result );
54+
$tmp_file = tempnam( sys_get_temp_dir(), 'logo_' );
55+
file_put_contents( $tmp_file, '<svg></svg>' );
56+
57+
try {
58+
$result = _gutenberg_resolve_ai_provider_logo_url( $tmp_file );
59+
$this->assertNull( $result );
60+
} finally {
61+
unlink( $tmp_file );
62+
}
2963
}
3064
}

routes/connectors-home/default-connectors.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ import { Badge } from '@wordpress/ui';
1515
* Internal dependencies
1616
*/
1717
import { useConnectorPlugin } from './use-connector-plugin';
18-
import { OpenAILogo, ClaudeLogo, GeminiLogo } from './logos';
18+
import {
19+
OpenAILogo,
20+
ClaudeLogo,
21+
GeminiLogo,
22+
DefaultConnectorLogo,
23+
} from './logos';
1924

2025
type ConnectorAuthentication =
2126
| { method: 'api_key'; settingName: string; credentialsUrl: string | null }
@@ -68,7 +73,7 @@ function getConnectorLogo(
6873
if ( Logo ) {
6974
return <Logo />;
7075
}
71-
return undefined;
76+
return <DefaultConnectorLogo />;
7277
}
7378

7479
const ConnectedBadge = () => (

routes/connectors-home/logos.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,42 @@ export const ClaudeLogo = () => (
3030
</svg>
3131
);
3232

33+
// Default connector logo (WordPress logo with connector plug badge)
34+
export const DefaultConnectorLogo = () => (
35+
<svg
36+
width="40"
37+
height="40"
38+
viewBox="0 0 128 128"
39+
fill="none"
40+
xmlns="http://www.w3.org/2000/svg"
41+
>
42+
<rect width="128" height="128" fill="#1E1E1E" />
43+
<path
44+
d="M63.3813 24.1033C41.6317 24.1033 24 41.7349 24 63.4846C24 85.2342 41.6317 102.866 63.3813 102.866C85.1309 102.866 102.763 85.2342 102.763 63.4846C102.763 41.7349 85.1309 24.1033 63.3813 24.1033ZM63.3813 26.4662C68.3798 26.4662 73.2274 27.4445 77.7898 29.3741C79.9829 30.3017 82.0984 31.4499 84.0773 32.7869C86.0378 34.1114 87.8815 35.6325 89.5572 37.3087C91.2329 38.9844 92.7545 40.8281 94.079 42.7885C95.4159 44.7675 96.5642 46.883 97.4918 49.076C99.4213 53.6384 100.4 58.486 100.4 63.4846C100.4 68.4831 99.4213 73.3307 97.4918 77.8931C96.5642 80.0861 95.4159 82.2012 94.079 84.1801C92.7545 86.141 91.2329 87.9847 89.5572 89.6605C87.8815 91.3362 86.0378 92.8577 84.0773 94.1822C82.0984 95.5192 79.9829 96.6674 77.7898 97.595C73.2274 99.5246 68.3798 100.503 63.3813 100.503C58.3828 100.503 53.5352 99.5246 48.9728 97.595C46.7797 96.6674 44.6642 95.5192 42.6853 94.1822C40.7248 92.8577 38.8811 91.3362 37.2054 89.6605C35.5297 87.9847 34.0081 86.141 32.6836 84.1801C31.3466 82.2012 30.1984 80.0861 29.2708 77.8931C27.3413 73.3307 26.3629 68.4831 26.3629 63.4846C26.3629 58.486 27.3413 53.6384 29.2708 49.076C30.1984 46.883 31.3466 44.7675 32.6836 42.7885C34.0081 40.8281 35.5297 38.9844 37.2054 37.3087C38.8811 35.6325 40.7248 34.1114 42.6853 32.7869C44.6642 31.4499 46.7797 30.3017 48.9728 29.3741C53.5352 27.4445 58.3828 26.4662 63.3813 26.4662Z"
45+
fill="white"
46+
/>
47+
<path
48+
d="M93.3017 48.0216C93.4454 49.0824 93.5262 50.2205 93.5262 51.4461C93.5262 54.8243 92.8918 58.6234 90.9863 63.3748L80.7878 92.7847C90.7154 87.0119 97.3912 76.285 97.3912 63.9986C97.3912 58.2085 95.9078 52.765 93.3017 48.0216ZM64.5863 66.9117L54.5662 95.9474C57.5588 96.8255 60.7223 97.3042 63.9998 97.3042C67.8883 97.3042 71.6186 96.6349 75.0891 95.4158C74.9999 95.2735 74.9173 95.1222 74.8496 94.9569L64.5863 66.9117ZM86.5419 62.3191C86.5419 58.2019 85.059 55.3521 83.7893 53.1345C82.0965 50.39 80.5089 48.068 80.5089 45.3235C80.5089 42.2624 82.8365 39.4126 86.1164 39.4126C86.2648 39.4126 86.4047 39.4304 86.5489 39.4397C80.6079 34.0107 72.6929 30.6958 63.9998 30.6958C52.3339 30.6958 42.0711 36.6657 36.1005 45.7061C36.8842 45.7309 37.6233 45.7469 38.2493 45.7469C41.7414 45.7469 47.149 45.3235 47.149 45.3235C48.9483 45.2181 49.1606 47.8558 47.3626 48.068C47.3626 48.068 45.5529 48.2792 43.5413 48.3841L55.7002 84.459L63.0086 62.6006L57.8067 48.3841C56.0078 48.2792 54.3047 48.068 54.3047 48.068C52.5044 47.9617 52.7152 45.2181 54.5165 45.3235C54.5165 45.3235 60.0296 45.7469 63.3105 45.7469C66.8022 45.7469 72.2107 45.3235 72.2107 45.3235C74.011 45.2181 74.2228 47.8558 72.4239 48.068C72.4239 48.068 70.6123 48.2792 68.6021 48.3841L80.6695 84.1841L84.1142 73.2975C85.6445 68.5396 86.5419 65.169 86.5419 62.3191ZM30.6085 63.9986C30.6085 77.1805 38.2887 88.5734 49.4282 93.971L33.4996 50.4453C31.6471 54.5868 30.6085 59.1705 30.6085 63.9986Z"
49+
fill="white"
50+
/>
51+
<rect x="69.5" y="69.5" width="43" height="43" rx="21.5" fill="white" />
52+
<rect
53+
x="69.5"
54+
y="69.5"
55+
width="43"
56+
height="43"
57+
rx="21.5"
58+
stroke="#1E1E1E"
59+
strokeWidth="3"
60+
/>
61+
<rect x="86" y="82" width="2" height="6" rx="1" fill="#1E1E1E" />
62+
<rect x="94" y="82" width="2" height="6" rx="1" fill="#1E1E1E" />
63+
<rect x="83" y="88" width="16" height="7" rx="2" fill="#1E1E1E" />
64+
<rect x="89" y="95" width="4" height="3" fill="#1E1E1E" />
65+
<rect x="86" y="98" width="10" height="2" rx="1" fill="#1E1E1E" />
66+
</svg>
67+
);
68+
3369
// Gemini logo as inline SVG
3470
export const GeminiLogo = () => (
3571
<svg

0 commit comments

Comments
 (0)