functions = $functions; } /** * @param array $options * @param array $postData * @return string Empty string; kept for the section-updater message contract. */ public function apply(array &$options, array $postData): string { if (isset($postData['folders_files_ignore'])) { $foldersFilesVal = is_string($postData['folders_files_ignore']) ? $postData['folders_files_ignore'] : ''; $options['folders_files_ignore'] = wp_unslash(wp_kses_post($foldersFilesVal)); $options['folders_files_ignore_usable'] = $this->patternsFromLines( $this->functions->explodeNewline($options['folders_files_ignore']), true ); } if (isset($postData['suggest_regex_exclusions'])) { $suggestRegexRaw = is_string($postData['suggest_regex_exclusions']) ? $postData['suggest_regex_exclusions'] : ''; $sanitizedExclusions = sanitize_textarea_field(wp_unslash($suggestRegexRaw)); $options['suggest_regex_exclusions'] = $sanitizedExclusions; $options['suggest_regex_exclusions_usable'] = $this->patternsFromLines( $this->functions->explodeNewline($sanitizedExclusions), false ); } return ""; } /** * @param array $lines * @param bool $includeEmpty Existing folders_files_ignore behavior stores * the anchored empty pattern when the splitter * returns one; suggest exclusions skip empties. * @return array */ private function patternsFromLines(array $lines, bool $includeEmpty): array { $usablePatterns = array(); foreach ($lines as $line) { $trimmedPattern = trim($line); if (!$includeEmpty && empty($trimmedPattern)) { continue; } $newPattern = '^' . preg_quote($trimmedPattern, '/') . '$'; $newPattern = str_replace('\*', '.*', $newPattern); $usablePatterns[] = $newPattern; } return $usablePatterns; } }