Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,27 @@ function webmention_extract_urls( $content, $support_media_urls = false ) {
$attributes = array_merge( $attributes, $media_attributes );
}

/**
* Filters the CSS class name used to prevent sending Webmentions for a link.
*
* @param string $nomention_class The CSS class name. Default 'nomention'.
*/
$nomention_class = apply_filters( 'webmention_nomention_class', 'nomention' );

$urls = array();

foreach ( $attributes as $attribute => $elements ) {
foreach ( $elements as $element ) {
foreach ( $xpath->query( sprintf( '//%1$s[@%2$s]', $element, $attribute ) ) as $url ) {
$urls[] = $url->getAttribute( $attribute );
foreach ( $xpath->query( sprintf( '//%1$s[@%2$s]', $element, $attribute ) ) as $node ) {
// Skip elements that have the nomention class.
if ( $nomention_class && $node->hasAttribute( 'class' ) ) {
$classes = preg_split( '/\s+/', $node->getAttribute( 'class' ) );
if ( in_array( $nomention_class, $classes, true ) ) {
continue;
}
}

$urls[] = $node->getAttribute( $attribute );
}
}
}
Expand Down