Wordpress с грозными формами
Я пытаюсь сделать некоторые расчеты со статистикой огромных записей форм, для этого я получил следующий скрипт:
add_shortcode( 'math', function( $a, $content = '' ) {// change 'math' to whatever you want the shortcode to be named
if ( ! $content ) return "(No equation given)";
// Run Shortcodes to get values
$content = do_shortcode( $content );
// Seperate at spaces (after removing commas space at front and end)
$parts = explode( ' ', trim( str_replace( ',', '', $content ) ) );
// Check for odd number of parts (greater than 1)
$count = count( $parts );
if ( $count === 1 || $count % 2 !== 1 ) return "(Malformed equation)";
// Set subtotal as the first number
$total = (float) $parts[0];
// Process additional numbers using the correct operator
for ( $i = 1; $i < $count; ) {
switch ( $parts[$i++] ) {
case '+':
$total += $parts[$i++];
break;
case '-':
$total -= $parts[$i++];
break;
case '/':
if ( $parts[$i] == 0 ) return '0';// if dividing by zero, abort and return 0 to avoid php warnings
$total /= $parts[$i++];
break;
case '*':
case 'x':
case 'X':
$total *= $parts[$i++];
break;
}
}
// Handle format, defaults: decimal=2 dec_point='.' thousands_sep=','
$decimal = 2;
$dec_point = '.';
$thousands_sep = ',';
if ( isset( $a['decimal'] ) ) {
$decimal = (int) $a['decimal'];
}// Seems like formidable allows decimal or round
elseif ( isset( $a['round'] ) ) {
$decimal = (int) $a['round'];
}
if ( isset( $a['dec_point'] ) ) {
$dec_point = $a['dec_point'];
}
if ( isset( $a['thousands_sep'] ) ) {
$thousands_sep = $a['thousands_sep'];
}
return number_format( $total, $decimal, $dec_point, $thousands_sep );
});
Проблема в том, что его '-', т.е. оператор вычитания не работает. Все остальные операторы работают нормально. Невозможно найти ошибку