Skip to:
Content

BuddyPress.org

Ticket #4680: 4680.1.diff

File 4680.1.diff, 1.4 KB (added by ninnypants, 6 years ago)
  • bp-activity/bp-activity-filters.php

    diff --git bp-activity/bp-activity-filters.php bp-activity/bp-activity-filters.php
    index 603924f..678a1e2 100644
    function bp_activity_at_name_filter( $content, $activity_id = 0 ) { 
    220220        if ( empty( $usernames ) )
    221221                return $content;
    222222
     223        // hide username content inside tags
     224        $replace_count = 0;
     225        $replacements = array();
     226        foreach ( $usernames as $username ) {
     227                // prevent @ name linking inside a tags
     228                preg_match_all( '/(<a.*?(?!<\/a>)@' . $username . '.*?<\/a>)/', $content, $content_matches );
     229                if ( !empty( $content_matches[1] ) ) {
     230                        foreach ( $content_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
    223238        // Linkify the mentions with the username
    224239        foreach( (array) $usernames as $user_id => $username ) {
    225240                $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content );
    226241        }
    227242
     243        // put everything back
     244        if ( ! empty( $replacements ) ) {
     245                foreach ( $replacements as $placeholder => $original ) {
     246                        $content = str_replace( $placeholder, $original, $content );
     247                }
     248        }
     249
    228250        // Return the content
    229251        return $content;
    230252}