forked from leftypol/leftypol
functions.php: fix re-definition of get_or_default
This commit is contained in:
parent
a90b15d596
commit
22d76ad9f6
1 changed files with 7 additions and 6 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue