/** * Validate and sanitize player settings * * @since 1.0.0 * @param array $input The raw input array from the settings form. * @return array The sanitized and validated settings array. */ public function validate_player_settings($input) { // Initialize sanitized array $sanitized_input = array(); // Validate and sanitize boolean options $boolean_options = array( 'mementor_tts_show_time', 'mementor_tts_show_volume', 'mementor_tts_speed_control', 'mementor_tts_show_download', 'mementor_tts_show_info', 'mementor_tts_show_player_label' ); foreach ($boolean_options as $option) { $sanitized_input[$option] = isset($input[$option]) ? absint($input[$option]) : 0; } // Validate and sanitize text options if (isset($input['mementor_tts_player_label'])) { $sanitized_input['mementor_tts_player_label'] = sanitize_text_field($input['mementor_tts_player_label']); } // Validate and sanitize select options $position_options = array('before_title', 'after_title_before_excerpt', 'after_title_after_excerpt', 'after_content'); if (isset($input['mementor_tts_player_position']) && in_array($input['mementor_tts_player_position'], $position_options, true)) { $sanitized_input['mementor_tts_player_position'] = $input['mementor_tts_player_position']; } $width_options = array('full_width', 'content_width'); if (isset($input['mementor_tts_player_width']) && in_array($input['mementor_tts_player_width'], $width_options, true)) { $sanitized_input['mementor_tts_player_width'] = $input['mementor_tts_player_width']; } // Validate and sanitize numeric inputs if (isset($input['mementor_tts_player_max_width'])) { $max_width = absint($input['mementor_tts_player_max_width']); $sanitized_input['mementor_tts_player_max_width'] = min(max($max_width, 10), 2000); } if (isset($input['mementor_tts_player_label_size'])) { $label_size = absint($input['mementor_tts_player_label_size']); $sanitized_input['mementor_tts_player_label_size'] = min(max($label_size, 10), 32); } // Validate and sanitize unit options $unit_options = array('%', 'px'); if (isset($input['mementor_tts_player_max_width_unit']) && in_array($input['mementor_tts_player_max_width_unit'], $unit_options, true)) { $sanitized_input['mementor_tts_player_max_width_unit'] = $input['mementor_tts_player_max_width_unit']; } // Validate and sanitize alignment options $alignment_options = array('left', 'center', 'right'); if (isset($input['mementor_tts_player_alignment']) && in_array($input['mementor_tts_player_alignment'], $alignment_options, true)) { $sanitized_input['mementor_tts_player_alignment'] = $input['mementor_tts_player_alignment']; } if (isset($input['mementor_tts_player_label_position']) && in_array($input['mementor_tts_player_label_position'], $alignment_options, true)) { $sanitized_input['mementor_tts_player_label_position'] = $input['mementor_tts_player_label_position']; } // Validate and sanitize weight options $weight_options = array('400', '500', '700'); if (isset($input['mementor_tts_player_label_weight']) && in_array($input['mementor_tts_player_label_weight'], $weight_options, true)) { $sanitized_input['mementor_tts_player_label_weight'] = $input['mementor_tts_player_label_weight']; } // Validate and sanitize color inputs if (isset($input['mementor_tts_player_label_color'])) { $sanitized_input['mementor_tts_player_label_color'] = sanitize_hex_color($input['mementor_tts_player_label_color']); } // Allow filtering of sanitized options return apply_filters('mementor_tts_sanitized_player_settings', $sanitized_input, $input); }