Skip to:
Content

bbPress.org


Ignore:
Timestamp:
03/17/2017 05:55:58 PM (8 years ago)
Author:
johnjamesjacoby
Message:

Mentions: Balance tags before making things clickable.

Then, make mentions clickable without "requiring" prepending whitespace. This allows other types of characters to be immediately before the @ control character.

See #2963.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/common/formatting.php

    r6347 r6380  
    460460 */
    461461function bbp_make_mentions_clickable( $text = '' ) {
    462     return preg_replace_callback( '#([\s>])@([0-9a-zA-Z-_]+)#i', 'bbp_make_mentions_clickable_callback', $text );
     462    return preg_replace_callback( '#@([0-9a-zA-Z-_]+)#i', 'bbp_make_mentions_clickable_callback', $text );
    463463}
    464464
     
    468468 * @since 2.6.0 (r6014)
    469469 *
    470  * @param array $matches Single Regex Match.
    471  *
    472  * @return string HTML A tag with link to user profile.
     470 * @param array $matches Regular expression matches in the current text blob.
     471 *
     472 * @return string Original text if no user exists, or link to user profile.
    473473 */
    474474function bbp_make_mentions_clickable_callback( $matches = array() ) {
    475475
    476476    // Get user; bail if not found
    477     $user = get_user_by( 'slug', $matches[2] );
     477    $user = get_user_by( 'slug', $matches[1] );
    478478    if ( empty( $user ) || bbp_is_user_inactive( $user->ID ) ) {
    479479        return $matches[0];
     
    488488    // Escape & implode if not empty, otherwise an empty string
    489489    $class_str = ! empty( $classes )
    490         ? implode( ' ', array_map( 'esc_attr', $classes ) )
     490        ? implode( ' ', array_map( 'sanitize_html_class', $classes ) )
    491491        : '';
    492492
    493493    // Create the link to the user's profile
    494494    $url    = bbp_get_user_profile_url( $user->ID );
    495     $clicky = '<a href="%1$s" class="' . $class_str . '">@%2$s</a>';
    496     $anchor = sprintf( $clicky, esc_url( $url ), esc_html( $user->user_nicename ) );
     495    $clicky = '<a href="%1$s" class="' . esc_attr( $class_str ) . '">%2$s</a>';
     496    $anchor = sprintf( $clicky, esc_url( $url ), esc_html( $matches[0] ) );
    497497    $link   = bbp_rel_nofollow( $anchor );
    498498
    499     return $matches[1] . $link;
     499    return $link;
    500500}
    501501
Note: See TracChangeset for help on using the changeset viewer.