bbp_mention_filter

Finds and links @-mentioned users in the content.

Description

(string) bbp_mention_filter( (string) $content = '' ); 

Returns (string)

$content Content filtered for mentions

Parameters (1)

0. $content — Optional. (string) => ''
The content.

Usage

  1. if ( !function_exists( 'bbp_mention_filter' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/core/functions.php'; 
  3.  
  4. // The content. 
  5. $content = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_mention_filter($content); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/core/functions.php  
  1. function bbp_mention_filter( $content = '' ) { 
  2.  
  3. // Get Usernames and bail if none exist 
  4. $usernames = bbp_find_mentions( $content ); 
  5. if ( empty( $usernames ) ) 
  6. return $content; 
  7.  
  8. // Loop through usernames and link to profiles 
  9. foreach ( (array) $usernames as $username ) { 
  10.  
  11. // Skip if username does not exist or user is not active 
  12. $user = get_user_by( 'slug', $username ); 
  13. if ( empty( $user->ID ) || bbp_is_user_inactive( $user->ID ) ) 
  14. continue; 
  15.  
  16. // Replace name in content 
  17. $content = preg_replace( '/(@' . $username . '\b)/', sprintf( '<a href="%1$s" rel="nofollow">@%2$s</a>', bbp_get_user_profile_url( $user->ID ), $username ), $content ); 
  18.  
  19. // Return modified content 
  20. return $content;