Title: _wp_kses_sanitize_note_mention_classes
Published: August 20, 2026

---

# _wp_kses_sanitize_note_mention_classes( string $content ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Reduces `span` classes in comment content to the note mention tokens.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#description)󠁿

[_wp_kses_allow_note_mention_span()](https://developer.wordpress.org/reference/functions/_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](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#parameters)󠁿

 `$content`stringrequired

Slashed comment content, already filtered by kses.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#return)󠁿

 string Slashed comment content with span classes reduced.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#source)󠁿

    ```php
    function _wp_kses_sanitize_note_mention_classes( $content ): string {
    	if ( ! is_string( $content ) ) {
    		$content = '';
    	}
    	if ( false === has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
    		return $content;
    	}

    	$processor = new WP_HTML_Tag_Processor( wp_unslash( $content ) );

    	while ( $processor->next_tag( 'SPAN' ) ) {
    		foreach ( $processor->class_list() as $token ) {
    			if ( 'wp-note-mention' !== $token && ! preg_match( '/^user-[1-9][0-9]*$/', $token ) ) {
    				// Removing the last class also removes the attribute itself.
    				$processor->remove_class( $token );
    			}
    		}
    	}

    	return wp_slash( $processor->get_updated_html() );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/kses.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/kses.php#L1196)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/kses.php#L1196-L1216)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_HTML_Tag_Processor::__construct()](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/__construct/)`wp-includes/html-api/class-wp-html-tag-processor.php` |

Constructor.

  | 
| [has_filter()](https://developer.wordpress.org/reference/functions/has_filter/)`wp-includes/plugin.php` |

Checks if any filter has been registered for a hook.

  | 
| [wp_unslash()](https://developer.wordpress.org/reference/functions/wp_unslash/)`wp-includes/formatting.php` |

Removes slashes from a string or recursively removes slashes from strings within an array.

  | 
| [wp_slash()](https://developer.wordpress.org/reference/functions/wp_slash/)`wp-includes/formatting.php` |

Adds slashes to a string or recursively adds slashes to strings within an array.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_wp_kses_sanitize_note_mention_classes/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.1.0](https://developer.wordpress.org/reference/since/7.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_wp_kses_sanitize_note_mention_classes%2F)
before being able to contribute a note or feedback.