Skip to content

Commit bdc7290

Browse files
Merge pull request #423 from JLG-WOCFR-DEV/codex/fix-redeclaration-of-blc_sanitize_surveillance_thresholds_op
Prevent duplicate surveillance threshold sanitizers
2 parents 153f142 + e82f998 commit bdc7290

File tree

1 file changed

+5
-212
lines changed

1 file changed

+5
-212
lines changed

liens-morts-detector-jlg/includes/blc-settings-fields.php

Lines changed: 5 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -4756,85 +4756,14 @@ function blc_sanitize_notification_status_filters_option($value) {
47564756
*
47574757
* @return array{global:array<int,array<string,mixed>>,taxonomy:array<int,array<string,mixed>>}
47584758
*/
4759-
function blc_sanitize_surveillance_thresholds_option($value) {
4760-
$structured = array(
4761-
'global' => array(),
4762-
'taxonomy' => array(),
4763-
);
4764-
4765-
if (is_array($value)) {
4766-
if (isset($value['global']) && is_array($value['global'])) {
4767-
foreach ($value['global'] as $definition) {
4768-
if (!is_array($definition)) {
4769-
continue;
4770-
}
4771-
4772-
$structured['global'][] = array(
4773-
'id' => isset($definition['id']) ? (string) $definition['id'] : '',
4774-
'metric' => isset($definition['metric']) ? (string) $definition['metric'] : 'broken_ratio',
4775-
'comparison' => isset($definition['comparison']) ? (string) $definition['comparison'] : 'gte',
4776-
'threshold' => isset($definition['threshold']) ? (float) $definition['threshold'] : 0.0,
4777-
'label' => isset($definition['label']) ? (string) $definition['label'] : '',
4778-
'severity' => isset($definition['severity']) ? (string) $definition['severity'] : 'warning',
4779-
);
4780-
}
4781-
}
4782-
4783-
if (isset($value['taxonomy']) && is_array($value['taxonomy'])) {
4784-
foreach ($value['taxonomy'] as $definition) {
4785-
if (!is_array($definition)) {
4786-
continue;
4787-
}
4788-
4789-
$taxonomy = isset($definition['taxonomy']) ? (string) $definition['taxonomy'] : '';
4790-
$taxonomy = blc_surveillance_sanitize_key($taxonomy);
4791-
if ($taxonomy === '') {
4792-
continue;
4793-
}
4794-
4795-
$apply_to_all = !empty($definition['apply_to_all_terms']);
4796-
$term_ids = array();
4797-
4798-
if (!$apply_to_all && isset($definition['term_ids'])) {
4799-
$raw = $definition['term_ids'];
4800-
if (is_string($raw)) {
4801-
$parts = preg_split('/[,\s]+/', $raw);
4802-
} elseif (is_array($raw)) {
4803-
$parts = $raw;
4804-
} else {
4805-
$parts = array();
4806-
}
4759+
if (!function_exists('blc_sanitize_surveillance_thresholds_option')) {
4760+
function blc_sanitize_surveillance_thresholds_option($value) {
4761+
$normalized = blc_normalize_surveillance_thresholds($value);
48074762

4808-
foreach ($parts as $part) {
4809-
$term_id = (int) $part;
4810-
if ($term_id > 0) {
4811-
$term_ids[] = $term_id;
4812-
}
4813-
}
4814-
}
4763+
blc_save_surveillance_thresholds($normalized);
48154764

4816-
if (!$apply_to_all && $term_ids === array()) {
4817-
continue;
4818-
}
4819-
4820-
$structured['taxonomy'][] = array(
4821-
'id' => isset($definition['id']) ? (string) $definition['id'] : '',
4822-
'taxonomy' => $taxonomy,
4823-
'threshold' => isset($definition['threshold']) ? (float) $definition['threshold'] : 0.0,
4824-
'comparison' => isset($definition['comparison']) ? (string) $definition['comparison'] : 'gte',
4825-
'label' => isset($definition['label']) ? (string) $definition['label'] : '',
4826-
'severity' => isset($definition['severity']) ? (string) $definition['severity'] : 'warning',
4827-
'term_ids' => $term_ids,
4828-
'apply_to_all_terms'=> $apply_to_all,
4829-
);
4830-
}
4831-
}
4765+
return $normalized;
48324766
}
4833-
4834-
$normalized = blc_normalize_surveillance_thresholds($structured);
4835-
blc_save_surveillance_thresholds($normalized);
4836-
4837-
return $normalized;
48384767
}
48394768

48404769
/**
@@ -5139,142 +5068,6 @@ function blc_get_surveillance_severity_options() {
51395068
}
51405069
}
51415070

5142-
/**
5143-
* Sanitize the surveillance thresholds option payload.
5144-
*
5145-
* @param mixed $value Raw value.
5146-
*
5147-
* @return array<string,mixed>
5148-
*/
5149-
function blc_sanitize_surveillance_thresholds_option($value) {
5150-
return blc_normalize_surveillance_thresholds($value);
5151-
}
5152-
5153-
/**
5154-
* Sanitize the list of severity levels enabled for a channel.
5155-
*
5156-
* @param mixed $value Raw value.
5157-
*
5158-
* @return array<int,string>
5159-
*/
5160-
function blc_sanitize_surveillance_escalation_levels_option($value) {
5161-
$options = blc_get_surveillance_severity_options();
5162-
5163-
if (is_string($value)) {
5164-
$value = array($value);
5165-
}
5166-
5167-
if (!is_array($value)) {
5168-
$value = array();
5169-
}
5170-
5171-
$normalized = array();
5172-
5173-
foreach ($value as $candidate) {
5174-
if (!is_scalar($candidate)) {
5175-
continue;
5176-
}
5177-
5178-
$slug = sanitize_key((string) $candidate);
5179-
if ($slug === '' || !isset($options[$slug])) {
5180-
continue;
5181-
}
5182-
5183-
$normalized[$slug] = $slug;
5184-
}
5185-
5186-
return array_values($normalized);
5187-
}
5188-
5189-
/**
5190-
* Sanitize the cooldown (seconds) configured for a severity.
5191-
*
5192-
* @param mixed $value Raw value.
5193-
*
5194-
* @return int
5195-
*/
5196-
function blc_sanitize_surveillance_cooldown_option($value) {
5197-
$value = is_numeric($value) ? (int) $value : 0;
5198-
5199-
if ($value < 60) {
5200-
$value = 60;
5201-
}
5202-
5203-
return $value;
5204-
}
5205-
5206-
/**
5207-
* Retrieve the available taxonomy choices for surveillance thresholds.
5208-
*
5209-
* @return array<string,string>
5210-
*/
5211-
if (!function_exists('blc_get_surveillance_taxonomy_choices')) {
5212-
function blc_get_surveillance_taxonomy_choices() {
5213-
$choices = array();
5214-
5215-
if (function_exists('get_taxonomies')) {
5216-
$taxonomies = get_taxonomies(array('public' => true), 'objects');
5217-
5218-
if (is_array($taxonomies)) {
5219-
foreach ($taxonomies as $taxonomy => $object) {
5220-
$label = isset($object->labels->singular_name) ? (string) $object->labels->singular_name : $taxonomy;
5221-
$choices[$taxonomy] = $label;
5222-
}
5223-
}
5224-
}
5225-
5226-
if ($choices === array()) {
5227-
$choices['category'] = __('Catégories', 'liens-morts-detector-jlg');
5228-
$choices['post_tag'] = __('Étiquettes', 'liens-morts-detector-jlg');
5229-
}
5230-
5231-
return $choices;
5232-
}
5233-
}
5234-
5235-
/**
5236-
* Return the available comparison operators for surveillance thresholds.
5237-
*
5238-
* @return array<string,string>
5239-
*/
5240-
if (!function_exists('blc_get_surveillance_comparison_options')) {
5241-
function blc_get_surveillance_comparison_options() {
5242-
return array(
5243-
'gte' => __('≥ (supérieur ou égal)', 'liens-morts-detector-jlg'),
5244-
'gt' => __('> (strictement supérieur)', 'liens-morts-detector-jlg'),
5245-
'lte' => __('≤ (inférieur ou égal)', 'liens-morts-detector-jlg'),
5246-
'lt' => __('< (strictement inférieur)', 'liens-morts-detector-jlg'),
5247-
'eq' => __('= (égal à)', 'liens-morts-detector-jlg'),
5248-
'neq' => __('≠ (différent de)', 'liens-morts-detector-jlg'),
5249-
);
5250-
}
5251-
}
5252-
5253-
/**
5254-
* Return the severity labels for surveillance alerts.
5255-
*
5256-
* @return array<string,string>
5257-
*/
5258-
if (!function_exists('blc_get_surveillance_severity_options')) {
5259-
function blc_get_surveillance_severity_options() {
5260-
return array(
5261-
'warning' => __('Avertissement', 'liens-morts-detector-jlg'),
5262-
'critical' => __('Critique', 'liens-morts-detector-jlg'),
5263-
);
5264-
}
5265-
}
5266-
5267-
/**
5268-
* Sanitize the surveillance thresholds option payload.
5269-
*
5270-
* @param mixed $value Raw value.
5271-
*
5272-
* @return array<string,mixed>
5273-
*/
5274-
function blc_sanitize_surveillance_thresholds_option($value) {
5275-
return blc_normalize_surveillance_thresholds($value);
5276-
}
5277-
52785071
/**
52795072
* Sanitize the list of severity levels enabled for a channel.
52805073
*

0 commit comments

Comments
 (0)