File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed
Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -564,14 +564,45 @@ function ajax_wto_options(): void {
564564add_action ( 'wp_ajax_wto_options ' , 'ajax_wto_options ' );
565565add_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 */
573596function 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/**
You can’t perform that action at this time.
0 commit comments