@@ -265,54 +265,88 @@ public function update_settings( $request ) {
265
265
$ validation = apply_filters (
266
266
'hyve_settings_validation ' ,
267
267
[
268
- 'api_key ' => function ( $ value ) {
269
- return is_string ( $ value );
270
- },
271
- 'qdrant_api_key ' => function ( $ value ) {
272
- return is_string ( $ value );
273
- },
274
- 'qdrant_endpoint ' => function ( $ value ) {
275
- return is_string ( $ value );
276
- },
277
- 'chat_enabled ' => function ( $ value ) {
278
- return is_bool ( $ value );
279
- },
280
- 'welcome_message ' => function ( $ value ) {
281
- return is_string ( $ value );
282
- },
283
- 'default_message ' => function ( $ value ) {
284
- return is_string ( $ value );
285
- },
286
- 'chat_model ' => function ( $ value ) {
287
- return is_string ( $ value );
288
- },
289
- 'temperature ' => function ( $ value ) {
290
- return is_numeric ( $ value );
291
- },
292
- 'top_p ' => function ( $ value ) {
293
- return is_numeric ( $ value );
294
- },
295
- 'moderation_threshold ' => function ( $ value ) {
296
- return is_array ( $ value ) && array_reduce (
297
- $ value ,
298
- function ( $ carry , $ item ) {
299
- return $ carry && is_int ( $ item );
300
- },
301
- true
302
- );
303
- },
268
+ 'api_key ' => [
269
+ 'validate ' => function ( $ value ) {
270
+ return is_string ( $ value );
271
+ },
272
+ 'sanitize ' => 'sanitize_text_field ' ,
273
+ ],
274
+ 'qdrant_api_key ' => [
275
+ 'validate ' => function ( $ value ) {
276
+ return is_string ( $ value );
277
+ },
278
+ 'sanitize ' => 'sanitize_text_field ' ,
279
+ ],
280
+ 'qdrant_endpoint ' => [
281
+ 'validate ' => function ( $ value ) {
282
+ return is_string ( $ value );
283
+ },
284
+ 'sanitize ' => 'sanitize_url ' ,
285
+ ],
286
+ 'chat_enabled ' => [
287
+ 'validate ' => function ( $ value ) {
288
+ return is_bool ( $ value );
289
+ },
290
+ 'sanitize ' => 'rest_sanitize_boolean ' ,
291
+ ],
292
+ 'welcome_message ' => [
293
+ 'validate ' => function ( $ value ) {
294
+ return is_string ( $ value );
295
+ },
296
+ 'sanitize ' => 'sanitize_text_field ' ,
297
+ ],
298
+ 'default_message ' => [
299
+ 'validate ' => function ( $ value ) {
300
+ return is_string ( $ value );
301
+ },
302
+ 'sanitize ' => 'sanitize_text_field ' ,
303
+ ],
304
+ 'chat_model ' => [
305
+ 'validate ' => function ( $ value ) {
306
+ return is_string ( $ value );
307
+ },
308
+ 'sanitize ' => 'sanitize_text_field ' ,
309
+ ],
310
+ 'temperature ' => [
311
+ 'validate ' => function ( $ value ) {
312
+ return is_numeric ( $ value );
313
+ },
314
+ 'sanitize ' => 'floatval ' ,
315
+ ],
316
+ 'top_p ' => [
317
+ 'validate ' => function ( $ value ) {
318
+ return is_numeric ( $ value );
319
+ },
320
+ 'sanitize ' => 'floatval ' ,
321
+ ],
322
+ 'moderation_threshold ' => [
323
+ 'validate ' => function ( $ value ) {
324
+ return is_array ( $ value ) && array_reduce (
325
+ $ value ,
326
+ function ( $ carry , $ item ) {
327
+ return $ carry && is_int ( $ item );
328
+ },
329
+ true
330
+ );
331
+ },
332
+ 'sanitize ' => function ( $ value ) {
333
+ return array_map ( 'intval ' , $ value );
334
+ },
335
+ ],
304
336
]
305
337
);
306
338
307
339
foreach ( $ updated as $ key => $ value ) {
308
- if ( ! $ validation [ $ key ]( $ value ) ) {
340
+ if ( ! $ validation [ $ key ][ ' validate ' ] ( $ value ) ) {
309
341
return rest_ensure_response (
310
342
[
311
343
// translators: %s: option key.
312
344
'error ' => sprintf ( __ ( 'Invalid value: %s ' , 'hyve-lite ' ), $ key ),
313
345
]
314
346
);
315
347
}
348
+
349
+ $ updated [ $ key ] = $ validation [ $ key ]['sanitize ' ]( $ value );
316
350
}
317
351
318
352
foreach ( $ updated as $ key => $ value ) {
@@ -662,7 +696,7 @@ function ( $message ) use ( $run_id ) {
662
696
663
697
$ settings = Main::get_settings ();
664
698
665
- $ response = ( isset ( $ message ['success ' ] ) && true === $ message ['success ' ] && isset ( $ message ['response ' ] ) ) ? $ message ['response ' ] : $ settings ['default_message ' ];
699
+ $ response = ( isset ( $ message ['success ' ] ) && true === $ message ['success ' ] && isset ( $ message ['response ' ] ) ) ? $ message ['response ' ] : esc_html ( $ settings ['default_message ' ] ) ;
666
700
667
701
do_action ( 'hyve_chat_response ' , $ run_id , $ thread_id , $ query , $ record_id , $ message , $ response );
668
702
0 commit comments