Skip to content

Commit a1611fa

Browse files
committed
ci: resolve Plugin Check error
1 parent 98dd8a3 commit a1611fa

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

includes/index.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,45 @@ function ajax_wto_options(): void {
564564
add_action( 'wp_ajax_wto_options', 'ajax_wto_options' );
565565
add_action( 'wp_ajax_nopriv_wto_options', 'ajax_wto_options' );
566566

567+
/**
568+
* Sanitizes the enabled taxonomies setting.
569+
*
570+
* @param mixed $value The value to sanitize.
571+
* @return array<string> Sanitized array of taxonomy names.
572+
*/
573+
function wpto_sanitize_enabled_taxonomies( $value ): array {
574+
if ( ! is_array( $value ) ) {
575+
return array();
576+
}
577+
578+
$sanitized = array();
579+
foreach ( $value as $taxonomy ) {
580+
$taxonomy = wpto_cast_mixed_to_string( $taxonomy );
581+
// Ensure the taxonomy exists and is registered.
582+
if ( taxonomy_exists( sanitize_key( $taxonomy ) ) ) {
583+
$sanitized[] = sanitize_key( $taxonomy );
584+
}
585+
}
586+
587+
return $sanitized;
588+
}
589+
567590
/**
568591
* Registers the plugin settings.
569592
* This function registers settings that can be configured from the plugin's options page.
570593
*
571594
* @return void
572595
*/
573596
function register_wpto_settings(): void {
574-
register_setting( 'wpto-settings-group', 'wpto_enabled_taxonomies' );
597+
register_setting(
598+
'wpto-settings-group',
599+
'wpto_enabled_taxonomies',
600+
array(
601+
'type' => 'array',
602+
'sanitize_callback' => 'wpto_sanitize_enabled_taxonomies',
603+
'default' => array(),
604+
)
605+
);
575606
}
576607

577608
/**

0 commit comments

Comments
 (0)