-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
public function sanitize_settings(array $settings): array
{
// If the restore default settings checkbox is checked, restore the default settings.
if (isset($settings['restore_default_settings']['restore_default_settings'])) {
return array();
}
// Sanitize the general settings.
$settings['general_settings']['disable_wp_frontend'] = isset($settings['general_settings']['disable_wp_frontend']);
// Sanitize the path whitelist. Take in the string from the textarea and split it into an array by new line. Make sure the array items are sanitized.
// $settings['exception_settings']['path_whitelist'] = array_map('sanitize_text_field', explode("\n", $settings['exception_settings']['path_whitelist']));
// Sanitize the path whitelist: allow either a string (from textarea) or an array (already exploded).
$raw = $settings['exception_settings']['path_whitelist'] ?? '';
// If it’s a string, explode on newline; if it’s already an array, leave it.
if (is_array($raw)) {
$lines = $raw;
} else {
// normalize CRLF to LF then split
$lines = preg_split("/\r\n|\n|\r/", (string) $raw);
}
// Trim out any empty lines and sanitize each entry
$settings['exception_settings']['path_whitelist'] = array_values(array_filter(
array_map('sanitize_text_field', $lines),
// remove blank entries
fn($line) => (string) $line !== ''
));
return $settings;
}
Metadata
Metadata
Assignees
Labels
No labels