Skip to content

Commit

Permalink
fix: allow anchor target attribute in setting fields description
Browse files Browse the repository at this point in the history
  • Loading branch information
Dartui committed Aug 27, 2024
1 parent aca3bae commit ed8281a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
9 changes: 8 additions & 1 deletion resources/templates/form/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@
?>
<?php $description = $field->getDescription(); ?>
<?php if (!empty($description)) : ?>
<p class="description"><?php echo wp_kses_data($description); ?></p>
<p class="description">
<?php
echo wp_kses(
$description,
wp_kses_allowed_html('notification/field_description')
);
?>
</p>
<?php endif ?>
<?php
do_action_deprecated(
Expand Down
5 changes: 3 additions & 2 deletions resources/templates/settings/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ class="field-<?php echo esc_attr($field->slug()); ?>"
<?php if (!empty($fieldDescription)) : ?>
<small class="description">
<?php
echo wp_kses_data(
$fieldDescription
echo wp_kses(
$fieldDescription,
wp_kses_allowed_html('notification/field_description')
);
?>
</small>
Expand Down
20 changes: 20 additions & 0 deletions src/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,24 @@ public function filterPostTypes($postTypes)

return $postTypes;
}

/**
* Filters list of allowed HTML tags and attributes for field description.
*
* @filter wp_kses_allowed_html
*
* @param array<string, array<string, bool>> $tags List of allowed tags.
* @param string $context Current context.
* @return array<mixed>
*/
public function filterAllowedDescriptionHtml(array $tags, string $context): array
{
if ($context !== 'notification/field_description') {
return $tags;
}

$tags['a']['target'] = true;

return $tags;
}
}
2 changes: 1 addition & 1 deletion src/Repository/Field/BaseField.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function __construct($params = [])
if (isset($params['description'])) {
$this->description = wp_kses(
$params['description'],
wp_kses_allowed_html('data')
wp_kses_allowed_html('notification/field_description')
);
}

Expand Down

0 comments on commit ed8281a

Please sign in to comment.