added validation
user_8649498
plain_text
a year ago
2.2 kB
2
Indexable
Never
function my_plugin_sanitize_api_key($input) { // Validate the API Key (e.g., check for length, format, etc.) if (empty($input) || !preg_match('/^[A-Za-z0-9\-_]+$/', $input)) { add_settings_error('my_plugin_api_key', 'invalid_api_key', 'API Key cannot be empty or invalid.'); return get_option('my_plugin_api_key'); // Reset to previous value } // Sanitize the API Key $sanitized_input = sanitize_text_field($input); return $sanitized_input; } function my_plugin_sanitize_api_link($input) { // Validate the API Link (e.g., check for a valid URL format) if (empty($input) || !filter_var($input, FILTER_VALIDATE_URL)) { add_settings_error('my_plugin_api_link', 'invalid_api_link', 'API Link cannot be empty or invalid.'); return get_option('my_plugin_api_link'); // Reset to previous value } // Sanitize the API Link $sanitized_input = esc_url_raw($input); return $sanitized_input; } function my_plugin_sanitize_full_description_prompt($input) { // Validate the Full Description Prompt (e.g., check for length, format, etc.) if (empty($input) || strlen($input) < 160) { // Adjust the minimum length as needed add_settings_error('my_plugin_full_description_prompt', 'invalid_full_description_prompt', 'Full Description Prompt cannot be empty or too short.'); return get_option('my_plugin_full_description_prompt'); // Reset to previous value } // Sanitize the Full Description Prompt $sanitized_input = sanitize_text_field($input); return $sanitized_input; } function my_plugin_sanitize_short_description_prompt($input) { // Validate the Short Description Prompt (e.g., check for length, format, etc.) if (empty($input) || strlen($input) < 150) { // Adjust the minimum length as needed add_settings_error('my_plugin_short_description_prompt', 'invalid_short_description_prompt', 'Short Description Prompt cannot be empty or too short.'); return get_option('my_plugin_short_description_prompt'); // Reset to previous value } // Sanitize the Short Description Prompt $sanitized_input = sanitize_text_field($input); return $sanitized_input; }