wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_get_note_mentioned_user_ids › WordPress Function

Seit7.1.0
Veraltetn/v
wp_get_note_mentioned_user_ids ( $content )
Parameter:
  • (string) $content Note (comment) content, as stored.
    Erforderlich: Ja
Gibt zurück:
  • (int[]) Unique, positive mentioned user IDs.
Definiert in:
Codex:

Extracts the mentioned user IDs from note content.

Mentions are stored as chips carrying the wp-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.


Quellcode

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 ) );
}