Skip to content

Commit

Permalink
Fixed handling of {ifprofile shortname ...} tags when logged out.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-milette committed Jul 22, 2024
1 parent fe74ded commit 00621cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 00621cf

Please sign in to comment.