From 22d76ad9f6f2585ea2f7963620ce0f5e4648a4cc Mon Sep 17 00:00:00 2001 From: Zankaria Date: Mon, 14 Oct 2024 10:14:14 +0200 Subject: [PATCH] functions.php: fix re-definition of get_or_default --- inc/functions.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index b215023e..06d1e015 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2786,6 +2786,10 @@ function diceRoller($post) { } } +function get_or_default_int(array $arr, int $index, int $default) { + return (isset($arr[$index]) && is_numeric($arr[$index])) ? (int)$arr[$index] : $default; +} + /** * Rolls a dice and generates the appropiate html from the markup. * @param array $matches The array of the matches according to the default configuration. @@ -2796,14 +2800,11 @@ function diceRoller($post) { * @return string The html to replace the original markup with. */ function handle_dice_roll_markup(array $matches, ?string $img_path): string { - function get_or_default(array $arr, int $index, int $default) { - return (isset($arr[$index]) && is_numeric($arr[$index])) ? (int)$arr[$index] : $default; - } global $config; - $dice_count = get_or_default($matches, 1, 1); - $dice_faces = get_or_default($matches, 3, 6); - $dice_offset = get_or_default($matches, 4, 0); + $dice_count = get_or_default_int($matches, 1, 1); + $dice_faces = get_or_default_int($matches, 3, 6); + $dice_offset = get_or_default_int($matches, 4, 0); // Clamp between 1 and max_roll_count. $dice_count = max(min($dice_count, $config['max_roll_count']), 1);