From ea9ec0dadf4d352b1187eec43d82e7545b336151 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 1 May 2018 08:39:15 -0400 Subject: [PATCH] [advancedcontentfilter] Fix PHP Warning: Invalid argument supplied for foreach --- .../advancedcontentfilter.php | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/advancedcontentfilter/advancedcontentfilter.php b/advancedcontentfilter/advancedcontentfilter.php index e34d5771..993c8b4c 100644 --- a/advancedcontentfilter/advancedcontentfilter.php +++ b/advancedcontentfilter/advancedcontentfilter.php @@ -118,21 +118,23 @@ function advancedcontentfilter_prepare_body_content_filter(App $a, &$hook_data) )); } - foreach($rules as $rule) { - try { - $serializedParsedExpression = new ExpressionLanguage\SerializedParsedExpression( - $rule['expression'], - $rule['serialized'] - ); - - $found = (bool) $expressionLanguage->evaluate($serializedParsedExpression, $vars); - } catch (Exception $e) { - $found = false; - } - - if ($found) { - $hook_data['filter_reasons'][] = L10n::t('Filtered by rule: %s', $rule['name']); - break; + if ($rules) { + foreach($rules as $rule) { + try { + $serializedParsedExpression = new ExpressionLanguage\SerializedParsedExpression( + $rule['expression'], + $rule['serialized'] + ); + + $found = (bool) $expressionLanguage->evaluate($serializedParsedExpression, $vars); + } catch (Exception $e) { + $found = false; + } + + if ($found) { + $hook_data['filter_reasons'][] = L10n::t('Filtered by rule: %s', $rule['name']); + break; + } } } } -- 2.39.5