Skip to content

Commit c9ea1f4

Browse files
authored
Merge branch 'trunk' into ticket/61996-fix-slug-conflict
2 parents 4b01d66 + 75b4131 commit c9ea1f4

3 files changed

Lines changed: 108 additions & 5 deletions

File tree

src/wp-admin/css/list-tables.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ div.action-links,
16091609
}
16101610

16111611
.plugin-card h3 {
1612-
margin: 0 12px 12px 0;
1612+
margin: 0 12px 16px 0;
16131613
font-size: 18px;
16141614
line-height: 1.3;
16151615
}

src/wp-includes/connectors.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,9 @@ function _wp_connectors_rest_settings_dispatch( WP_REST_Response $response, WP_R
549549
* @access private
550550
*/
551551
function _wp_register_default_connector_settings(): void {
552-
$ai_registry = AiClient::defaultRegistry();
553552
$registered_settings = get_registered_settings();
554553

555-
foreach ( wp_get_connectors() as $connector_id => $connector_data ) {
554+
foreach ( wp_get_connectors() as $connector_data ) {
556555
$auth = $connector_data['authentication'];
557556
if ( 'api_key' !== $auth['method'] || empty( $auth['setting_name'] ) ) {
558557
continue;
@@ -563,8 +562,11 @@ function _wp_register_default_connector_settings(): void {
563562
continue;
564563
}
565564

566-
// For AI providers, skip if the provider is not in the AI Client registry.
567-
if ( 'ai_provider' === $connector_data['type'] && ! $ai_registry->hasProvider( $connector_id ) ) {
565+
if ( ! isset( $connector_data['plugin']['is_active'] ) || ! is_callable( $connector_data['plugin']['is_active'] ) ) {
566+
continue;
567+
}
568+
569+
if ( ! call_user_func( $connector_data['plugin']['is_active'] ) ) {
568570
continue;
569571
}
570572

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
/**
4+
* Tests for _wp_register_default_connector_settings().
5+
*
6+
* @group connectors
7+
* @covers ::_wp_register_default_connector_settings
8+
*/
9+
class Tests_Connectors_WpRegisterDefaultConnectorSettings extends WP_UnitTestCase {
10+
11+
const CONNECTOR_ID = 'wp_test_non_ai_connector';
12+
const SETTING_NAME = 'connectors_test_non_ai_api_key';
13+
14+
/**
15+
* Snapshot of registered settings before each test.
16+
*
17+
* @var array
18+
*/
19+
private array $original_registered_settings = array();
20+
21+
/**
22+
* Snapshots the registered settings before each test.
23+
*/
24+
public function set_up(): void {
25+
parent::set_up();
26+
27+
global $wp_registered_settings;
28+
$this->original_registered_settings = $wp_registered_settings;
29+
}
30+
31+
/**
32+
* Removes the test connector and restores registered settings.
33+
*/
34+
public function tear_down(): void {
35+
$registry = WP_Connector_Registry::get_instance();
36+
if ( null !== $registry && $registry->is_registered( self::CONNECTOR_ID ) ) {
37+
$registry->unregister( self::CONNECTOR_ID );
38+
}
39+
40+
global $wp_registered_settings;
41+
$wp_registered_settings = $this->original_registered_settings;
42+
43+
parent::tear_down();
44+
}
45+
46+
/**
47+
* @ticket 65099
48+
*/
49+
public function test_non_ai_connector_skipped_when_is_active_returns_false(): void {
50+
WP_Connector_Registry::get_instance()->register(
51+
self::CONNECTOR_ID,
52+
array(
53+
'name' => 'Test Non-AI Connector',
54+
'description' => '',
55+
'type' => 'spam_filtering',
56+
'authentication' => array(
57+
'method' => 'api_key',
58+
'setting_name' => self::SETTING_NAME,
59+
),
60+
'plugin' => array(
61+
'file' => 'test/test.php',
62+
'is_active' => static function (): bool {
63+
return false;
64+
},
65+
),
66+
)
67+
);
68+
69+
_wp_register_default_connector_settings();
70+
71+
$this->assertArrayNotHasKey( self::SETTING_NAME, get_registered_settings() );
72+
}
73+
74+
/**
75+
* @ticket 65099
76+
*/
77+
public function test_non_ai_connector_registers_setting_when_is_active_returns_true(): void {
78+
WP_Connector_Registry::get_instance()->register(
79+
self::CONNECTOR_ID,
80+
array(
81+
'name' => 'Test Non-AI Connector',
82+
'description' => '',
83+
'type' => 'spam_filtering',
84+
'authentication' => array(
85+
'method' => 'api_key',
86+
'setting_name' => self::SETTING_NAME,
87+
),
88+
'plugin' => array(
89+
'file' => 'test/test.php',
90+
'is_active' => static function (): bool {
91+
return true;
92+
},
93+
),
94+
)
95+
);
96+
97+
_wp_register_default_connector_settings();
98+
99+
$this->assertArrayHasKey( self::SETTING_NAME, get_registered_settings() );
100+
}
101+
}

0 commit comments

Comments
 (0)