diff --git bp-activity/bp-activity-filters.php bp-activity/bp-activity-filters.php
index 603924f..f84873f 100644
|
|
function bp_activity_at_name_filter( $content, $activity_id = 0 ) { |
220 | 220 | if ( empty( $usernames ) ) |
221 | 221 | return $content; |
222 | 222 | |
| 223 | // hide username content inside tags |
| 224 | $replace_count = 0; |
| 225 | $replacements = array(); |
| 226 | foreach ( $usernames as $username ) { |
| 227 | // prevent @ name linking in opening a tags |
| 228 | preg_match_all( '/(<a[^>]+' . $username . '[^>]+>)/', $content, $tag_matches ); |
| 229 | if ( !empty( $tag_matches[1] ) ) { |
| 230 | foreach ( $tag_matches[1] as $replacement ) { |
| 231 | $replacements[ '#BPAN' . $replace_count ] = $replacement; |
| 232 | $content = str_replace( $replacement, '#BPAN' . $replace_count, $content ); |
| 233 | $replace_count++; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | // prevent @ name linking inside a tags |
| 238 | preg_match_all( '/(<a[^>]+>.*?(?!<\/a>)@' . $username . '.*?<\/a>)/', $content, $content_matches ); |
| 239 | if ( !empty( $content_matches[1] ) ) { |
| 240 | foreach ( $content_matches[1] as $replacement ) { |
| 241 | $replacements[ '#BPAN' . $replace_count ] = $replacement; |
| 242 | $content = str_replace( $replacement, '#BPAN' . $replace_count, $content ); |
| 243 | $replace_count++; |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
223 | 248 | // Linkify the mentions with the username |
224 | 249 | foreach( (array) $usernames as $user_id => $username ) { |
225 | 250 | $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content ); |
226 | 251 | } |
227 | 252 | |
| 253 | // put everything back |
| 254 | if ( ! empty( $replacements ) ) { |
| 255 | foreach ( $replacements as $placeholder => $original ) { |
| 256 | $content = str_replace( $placeholder, $original, $content ); |
| 257 | } |
| 258 | } |
| 259 | |
228 | 260 | // Return the content |
229 | 261 | return $content; |
230 | 262 | } |