diff --git a/README.md b/README.md index ab32b86..7b7034a 100644 --- a/README.md +++ b/README.md @@ -1467,6 +1467,8 @@ Important: The specified value must be the value that is stored in the database, * For dropdown fields, you may need to view the HTML code to see what the actual values are for a field. * For checkboxes, the checked value is 1, unchecked is 0. +Reminder: When logged out (or in as guest), user profile fields do not exist. Therefore, "not" will always evaluate to true and "is", "contains" and "in" will evaluate to false. + ### What are the supported dateTimeFormat formats? The date and time formats, defined in Moodle (langconfig.php)[https://github.com/moodle/moodle/blob/master/lang/en/langconfig.php], control how dates and times will be displayed. diff --git a/filter.php b/filter.php index 13004ad..2aa2a50 100644 --- a/filter.php +++ b/filter.php @@ -3939,15 +3939,22 @@ function ($matches) use ($USER) { if ($found > 0) { foreach ($matches[1] as $key => $match) { $fieldname = $matches[1][$key]; - // Do not process tag if the specified profile field name does not exist. - if (!array_key_exists($fieldname, $profilefields)) { - continue; - } - $string = $matches[0][$key]; // String found in $text. $operator = $matches[2][$key]; $value = $matches[3][$key]; + // Do not process tag if the specified profile field name does not exist or user is not logged in. + if (!array_key_exists($fieldname, $profilefields) || !isloggedin() || isguestuser()) { + if ($operator == 'not') { + // It will always meet criteria of a "not" if the user doesn't have a profile. + $replace['/' . preg_quote($string, '/') . '/isuU'] = $matches[4][$key]; + } else { + // It will never match the criteria "is", "contains" or "in" if the user doesn't have a profile. + $replace['/' . preg_quote($string, '/') . '/isuU'] = ''; + } + continue; + } + if (!empty($value)) { $value = trim($value, '"'); // Trim quotation marks. } diff --git a/version.php b/version.php index 62d16d8..8d1a04d 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024072200; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2024072201; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2014051200; // Requires Moodle version 2.7 or later. $plugin->component = 'filter_filtercodes'; // Full name of the plugin (used for diagnostics). $plugin->release = '2.5.2';