Changeset 7083 for trunk/src/includes/common/formatting.php
- Timestamp:
- 05/21/2020 01:59:29 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/src/includes/common/formatting.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/common/formatting.php
r7006 r7083 463 463 */ 464 464 function bbp_make_mentions_clickable( $text = '' ) { 465 return preg_replace_callback( '# @([0-9a-zA-Z-_]+)#i', 'bbp_make_mentions_clickable_callback', $text );465 return preg_replace_callback( '#([\s>])@([0-9a-zA-Z-_]+)#i', 'bbp_make_mentions_clickable_callback', $text ); 466 466 } 467 467 … … 477 477 function bbp_make_mentions_clickable_callback( $matches = array() ) { 478 478 479 // Bail if the match is empty malformed 480 if ( empty( $matches[2] ) || ! is_string( $matches[2] ) ) { 481 return $matches[0]; 482 } 483 479 484 // Get user; bail if not found 480 $user = get_user_by( 'slug', $matches[ 1] );485 $user = get_user_by( 'slug', $matches[2] ); 481 486 if ( empty( $user ) || bbp_is_user_inactive( $user->ID ) ) { 482 487 return $matches[0]; 483 488 } 484 489 490 // Default anchor classes 491 $classes = array( 492 'bbp-user-mention', 493 'bbp-user-id-' . absint( $user->ID ) 494 ); 495 485 496 // Filter classes 486 $classes = (array) apply_filters( 'bbp_make_mentions_clickable_classes', array( 487 'bbp-user-id-' . $user->ID, 488 'bbp-user-mention' 489 ) ); 497 $classes = (array) apply_filters( 'bbp_make_mentions_clickable_classes', $classes, $user ); 490 498 491 499 // Escape & implode if not empty, otherwise an empty string … … 494 502 : ''; 495 503 504 // Setup as a variable to avoid a potentially empty class attribute 505 $class = ! empty( $class_str ) 506 ? ' class="' . esc_attr( $class_str ) . '"' 507 : ''; 508 496 509 // Create the link to the user's profile 510 $html = '<a href="%1$s"' . $class . '">%2$s</a>'; 497 511 $url = bbp_get_user_profile_url( $user->ID ); 498 $clicky = '<a href="%1$s" class="' . esc_attr( $class_str ) . '">%2$s</a>'; 499 $anchor = sprintf( $clicky, esc_url( $url ), esc_html( $matches[0] ) ); 512 $anchor = sprintf( $html, esc_url( $url ), esc_html( $matches[0] ) ); 513 514 // Prevent this link from being followed by bots 500 515 $link = bbp_rel_nofollow( $anchor ); 501 516 502 return $link; 517 // Concatenate the matches into the return value 518 $retval = $matches[1] . $link; 519 520 // Return the link 521 return $retval; 503 522 } 504 523
Note: See TracChangeset
for help on using the changeset viewer.