Reduces span classes in comment content to the note mention tokens.
Description
_wp_kses_allow_note_mention_span() lets class through kses on span so the mention chip survives, but class is an open-ended styling and scripting hook, so this companion pass - running right after wp_filter_kses at priority 10 - strips every class token except the two the mention markup uses: wp-note-mention and user-N. span is the only comment tag allowed to carry class at all, so walking span tags covers the entire allowance. The pass only applies while the restrictive comment allowlist is active: users with unfiltered_html are filtered through wp_filter_post_kses (or not at all), where arbitrary classes are already permitted, and narrowing their markup here would restrict what core allows them to post.
Parameters
$contentstring
Slashed comment content, already filtered by kses.
Return
string
Slashed comment content with span classes reduced.
Uses · 4
has_filter()Checks if any filter has been registered for a hook.
wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
wp_slash()Adds slashes to a string or recursively adds slashes to strings within an array.
1196function_wp_kses_sanitize_note_mention_classes($content):string{1197if(!is_string($content)){1198$content='';1199}1200if(false===has_filter('pre_comment_content','wp_filter_kses')){1201return$content;1202}12031204$processor=newWP_HTML_Tag_Processor(wp_unslash($content));12051206while($processor->next_tag('SPAN')){1207foreach($processor->class_list()as$token){1208if('wp-note-mention'!==$token&&!preg_match('/^user-[1-9][0-9]*$/',$token)){1209// Removing the last class also removes the attribute itself.1210$processor->remove_class($token);1211}1212}1213}12141215returnwp_slash($processor->get_updated_html());1216}
History
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
About this page
Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/kses.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.