Skip to content

Commit 226ac98

Browse files
committed
Eliminate null value for wp_ai_client_default_request_timeout filter
1 parent 49ea5bb commit 226ac98

2 files changed

Lines changed: 4 additions & 23 deletions

File tree

src/wp-includes/ai-client/class-wp-ai-client-prompt-builder.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,17 @@ public function __construct( ProviderRegistry $registry, $prompt = null ) {
197197
*
198198
* @since 7.0.0
199199
*
200-
* @param float|null $default_timeout The default timeout in seconds, or null to disable the timeout.
201-
* If not null, must be greater than or equal to zero.
200+
* @param float $default_timeout The default timeout in seconds.
202201
*/
203202
$timeout = apply_filters( 'wp_ai_client_default_request_timeout', $default_timeout );
204203
if ( is_numeric( $timeout ) && (float) $timeout >= 0.0 ) {
205204
$default_timeout = (float) $timeout;
206-
} elseif ( null === $timeout ) {
207-
$default_timeout = null;
208205
} else {
209206
_doing_it_wrong(
210207
__METHOD__,
211208
sprintf(
212209
/* translators: %s: wp_ai_client_default_request_timeout */
213-
__( 'The %s filter must return a non-negative number or null.' ),
210+
__( 'The %s filter must return a non-negative number.' ),
214211
'<code>wp_ai_client_default_request_timeout</code>'
215212
),
216213
'7.0.0'

tests/phpunit/tests/ai-client/wpAiClientPromptBuilder.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,6 @@ static function () {
214214
$this->assertSame( 45.5, $request_options->getTimeout() );
215215
}
216216

217-
/**
218-
* Test that the constructor allows overriding the default request timeout with null.
219-
*
220-
* @ticket 65094
221-
*/
222-
public function test_constructor_allows_overriding_request_timeout_with_null() {
223-
add_filter( 'wp_ai_client_default_request_timeout', '__return_null' );
224-
225-
$builder = new WP_AI_Client_Prompt_Builder( AiClient::defaultRegistry() );
226-
227-
/** @var RequestOptions $request_options */
228-
$request_options = $this->get_wrapped_prompt_builder_property_value( $builder, 'requestOptions' );
229-
230-
$this->assertInstanceOf( RequestOptions::class, $request_options );
231-
$this->assertNull( $request_options->getTimeout() );
232-
}
233-
234217
/**
235218
* Test that the constructor disallows overriding the default request timeout with an invalid value.
236219
*
@@ -256,7 +239,7 @@ static function () use ( $timeout ) {
256239
$request_options = $this->get_wrapped_prompt_builder_property_value( $builder, 'requestOptions' );
257240

258241
$this->assertInstanceOf( RequestOptions::class, $request_options );
259-
$this->assertSame( 30, $request_options->getTimeout() );
242+
$this->assertSame( 30.0, $request_options->getTimeout() );
260243
}
261244

262245
/**
@@ -268,6 +251,7 @@ public function data_invalid_request_timeouts(): array {
268251
return array(
269252
'negative number' => array( -1 ),
270253
'array' => array( array() ),
254+
'null' => array( null ),
271255
);
272256
}
273257

0 commit comments

Comments
 (0)