Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update understrap_kses_title() to not strip WPML flags #1927

Merged
merged 2 commits into from Sep 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
100 changes: 25 additions & 75 deletions inc/extras.php
Expand Up @@ -158,85 +158,35 @@ function understrap_escape_the_archive_description( $description ) {

if ( ! function_exists( 'understrap_kses_title' ) ) {
/**
* Sanitizes data for allowed HTML tags for post title.
* Sanitizes data for allowed HTML tags for titles.
*
* @param string $data Post title to filter.
* @return string Filtered post title with allowed HTML tags and attributes intact.
* @param string $data Title to filter.
* @return string Filtered title with allowed HTML tags and attributes intact.
*/
function understrap_kses_title( $data ) {
// Tags not supported in HTML5 are not allowed.
$allowed_tags = array(
'abbr' => array(),
'aria-describedby' => true,
'aria-details' => true,
'aria-label' => true,
'aria-labelledby' => true,
'aria-hidden' => true,
'b' => array(),
'bdo' => array(
'dir' => true,
),
'blockquote' => array(
'cite' => true,
'lang' => true,
'xml:lang' => true,
),
'cite' => array(
'dir' => true,
'lang' => true,
),
'dfn' => array(),
'em' => array(),
'i' => array(
'aria-describedby' => true,
'aria-details' => true,
'aria-label' => true,
'aria-labelledby' => true,
'aria-hidden' => true,
'class' => true,
),
'code' => array(),
'del' => array(
'datetime' => true,
),
'img' => array(
'src' => true,
'alt' => true,
'width' => true,
'height' => true,
'class' => true,
'style' => true,
),
'ins' => array(
'datetime' => true,
'cite' => true,
),
'kbd' => array(),
'mark' => array(),
'pre' => array(
'width' => true,
),
'q' => array(
'cite' => true,
),
's' => array(),
'samp' => array(),
'span' => array(
'dir' => true,
'align' => true,
'lang' => true,
'xml:lang' => true,
),
'small' => array(),
'strong' => array(),
'sub' => array(),
'sup' => array(),
'u' => array(),
'var' => array(),
);
$allowed_tags = apply_filters( 'understrap_kses_title', $allowed_tags );

return wp_kses( $data, $allowed_tags );
// Get allowed tags and protocols.
$allowed_tags = wp_kses_allowed_html( 'post' );
$allowed_protocols = wp_allowed_protocols();
if (
in_array( 'polylang/polylang.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )
|| in_array( 'polylang-pro/polylang.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )
) {
if ( ! in_array( 'data', $allowed_protocols, true ) ) {
$allowed_protocols[] = 'data';
}
}

if ( has_filter( 'understrap_kses_title' ) ) {
/**
* Filters the allowed HTML tags and attributes in titles.
*
* @param array<string,array<string,bool>> $allowed_tags Allowed HTML tags and attributes in titles.
*/
$allowed_tags = apply_filters_deprecated( 'understrap_kses_title', array( $allowed_tags ), '1.2.0' );
}

return wp_kses( $data, $allowed_tags, $allowed_protocols );
}
} // End of if function_exists( 'understrap_kses_title' ).

Expand Down