wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_get_note_mentioned_user_ids › WordPress Function
Since7.1.0
Deprecatedn/a
› wp_get_note_mentioned_user_ids ( $content )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
| Codex: |
Extracts the mentioned user IDs from note content.
Mentions are stored as chips carrying thewp-note-mention class plus a
user-N class token holding the mentioned user's ID:
<span class="wp-note-mention user-N">@Name</span>. Only elements that
carry both classes are treated as mentions.Source
function wp_get_note_mentioned_user_ids( string $content ): array {
if ( ! str_contains( $content, 'wp-note-mention' ) ) {
return array();
}
$user_ids = array();
$processor = new WP_HTML_Tag_Processor( $content );
while (
$processor->next_tag(
array(
'tag_name' => 'SPAN',
'class_name' => 'wp-note-mention',
)
)
) {
foreach ( $processor->class_list() as $class_name ) {
if ( 1 === preg_match( '/^user-(\d+)$/', $class_name, $matches ) ) {
$user_id = (int) $matches[1];
if ( $user_id > 0 ) {
$user_ids[] = $user_id;
}
break;
}
}
}
return array_values( array_unique( $user_ids, SORT_NUMERIC ) );
}