Make WordPress Core


Ignore:
Timestamp:
04/22/2026 06:13:47 PM (2 months ago)
Author:
westonruter
Message:

AI: Validate filtered default request timeout in WP_AI_Client_Prompt_Builder.

This checks that the return value of the wp_ai_client_default_request_timeout filter is a non-negative number before passing it to RequestOptions. If the filtered value is invalid, it is discarded in favor of the original default of 30.0 and a _doing_it_wrong() notice is issued. Without this check, a fatal error would ensue from the exception thrown in \WordPress\AiClient\Providers\Http\DTO\RequestOptions::validateTimeout().

The following static analysis issues are addressed:

  • Use float instead of int for the wp_ai_client_default_request_timeout filter parameter.
  • Add missing PHP imports for Message and MessagePart in the PHPDoc for wp_ai_client_prompt().
  • Add PHP return type hints for wp_ai_client_prompt() and WP_AI_Client_Cache::getMultiple().
  • Use native property type hints in WP_AI_Client_HTTP_Client.

Developed in https://github.com/WordPress/wordpress-develop/pull/11596

Props westonruter, justlevine, flixos90, khushdoms, darshitrajyaguru97, adrmf25, jarodortegaaraya, tusharaddweb, gaurangsondagar.
Fixes #65094.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ai-client.php

    r62239 r62255  
    99
    1010use WordPress\AiClient\AiClient;
     11use WordPress\AiClient\Messages\DTO\Message;
     12use WordPress\AiClient\Messages\DTO\MessagePart;
    1113
    1214/**
     
    5658 * @return WP_AI_Client_Prompt_Builder The prompt builder instance.
    5759 */
    58 function wp_ai_client_prompt( $prompt = null ) {
     60function wp_ai_client_prompt( $prompt = null ): WP_AI_Client_Prompt_Builder {
    5961    return new WP_AI_Client_Prompt_Builder( AiClient::defaultRegistry(), $prompt );
    6062}
Note: See TracChangeset for help on using the changeset viewer.