3232 * handling instead of exceptions, snake_case method naming, and integration
3333 * with the Abilities API.
3434 *
35- * Only the terminate methods will return a WP_Error, to not break the fluent
35+ * Only the generating methods will return a WP_Error, to not break the fluent
3636 * interface. As soon as any exception is caught in a chain of method calls,
3737 * the returned instance will be in an error state, and all subsequent method
3838 * calls will be no-ops that just return the same error state instance. Only
39- * when a terminate method is called, the WP_Error will be returned.
39+ * when a generating method is called, the WP_Error will be returned.
4040 *
4141 * @since 6.8.0
4242 *
@@ -108,14 +108,14 @@ class WP_AI_Client_Prompt_Builder {
108108 private ?WP_Error $ error = null ;
109109
110110 /**
111- * List of methods that terminate the fluent interface and return a result .
111+ * List of methods that generate a result from the prompt .
112112 *
113113 * Structured as a map for faster lookups.
114114 *
115115 * @since 6.8.0
116116 * @var array<string, bool>
117117 */
118- private static array $ terminate_methods = array (
118+ private static array $ generating_methods = array (
119119 'generate_result ' => true ,
120120 'generate_text_result ' => true ,
121121 'generate_image_result ' => true ,
@@ -131,6 +131,25 @@ class WP_AI_Client_Prompt_Builder {
131131 'generate_speeches ' => true ,
132132 );
133133
134+ /**
135+ * List of methods that check whether the prompt is supported.
136+ *
137+ * Structured as a map for faster lookups.
138+ *
139+ * @since 6.8.0
140+ * @var array<string, bool>
141+ */
142+ private static array $ support_check_methods = array (
143+ 'is_supported ' => true ,
144+ 'is_supported_for_text_generation ' => true ,
145+ 'is_supported_for_image_generation ' => true ,
146+ 'is_supported_for_text_to_speech_conversion ' => true ,
147+ 'is_supported_for_video_generation ' => true ,
148+ 'is_supported_for_speech_generation ' => true ,
149+ 'is_supported_for_music_generation ' => true ,
150+ 'is_supported_for_embedding_generation ' => true ,
151+ );
152+
134153 /**
135154 * Constructor.
136155 *
@@ -219,14 +238,17 @@ public function __call( string $name, array $arguments ) {
219238 * or return the same instance for other methods to maintain the fluent interface.
220239 */
221240 if ( null !== $ this ->error ) {
222- if ( self ::is_terminating_method ( $ name ) ) {
241+ if ( self ::is_generating_method ( $ name ) ) {
223242 return $ this ->error ;
224243 }
244+ if ( self ::is_support_check_method ( $ name ) ) {
245+ return false ;
246+ }
225247 return $ this ;
226248 }
227249
228250 // Check if the prompt should be prevented for is_supported* and generate_*/convert_text_to_speech* methods.
229- if ( $ this -> is_support_check_method ( $ name ) || $ this -> is_generating_method ( $ name ) ) {
251+ if ( self :: is_support_check_method ( $ name ) || self :: is_generating_method ( $ name ) ) {
230252 /**
231253 * Filters whether to prevent the prompt from being executed.
232254 *
@@ -239,7 +261,7 @@ public function __call( string $name, array $arguments ) {
239261
240262 if ( $ prevent ) {
241263 // For is_supported* methods, return false.
242- if ( $ this -> is_support_check_method ( $ name ) ) {
264+ if ( self :: is_support_check_method ( $ name ) ) {
243265 return false ;
244266 }
245267
@@ -252,7 +274,7 @@ public function __call( string $name, array $arguments ) {
252274 )
253275 );
254276
255- if ( self ::is_terminating_method ( $ name ) ) {
277+ if ( self ::is_generating_method ( $ name ) ) {
256278 return $ this ->error ;
257279 }
258280 return $ this ;
@@ -278,7 +300,7 @@ public function __call( string $name, array $arguments ) {
278300 )
279301 );
280302
281- if ( self ::is_terminating_method ( $ name ) ) {
303+ if ( self ::is_generating_method ( $ name ) ) {
282304 return $ this ->error ;
283305 }
284306 return $ this ;
@@ -293,8 +315,8 @@ public function __call( string $name, array $arguments ) {
293315 * @param string $name The method name.
294316 * @return bool True if the method is a support check method, false otherwise.
295317 */
296- protected function is_support_check_method ( string $ name ): bool {
297- return str_starts_with ( $ name, ' is_supported ' );
318+ private static function is_support_check_method ( string $ name ): bool {
319+ return isset ( self :: $ support_check_methods [ $ name ] );
298320 }
299321
300322 /**
@@ -305,21 +327,8 @@ protected function is_support_check_method( string $name ): bool {
305327 * @param string $name The method name.
306328 * @return bool True if the method is a generating method, false otherwise.
307329 */
308- protected function is_generating_method ( string $ name ): bool {
309- return str_starts_with ( $ name , 'generate_ ' )
310- || str_starts_with ( $ name , 'convert_text_to_speech ' );
311- }
312-
313- /**
314- * Checks if a method is a terminating method.
315- *
316- * @since 6.8.0
317- *
318- * @param string $name The method name.
319- * @return bool True if the method is a terminating method, false otherwise.
320- */
321- private static function is_terminating_method ( string $ name ): bool {
322- return isset ( self ::$ terminate_methods [ $ name ] );
330+ private static function is_generating_method ( string $ name ): bool {
331+ return isset ( self ::$ generating_methods [ $ name ] );
323332 }
324333
325334 /**
0 commit comments