Changeset 4323
- Timestamp:
- 11/03/2012 10:14:32 AM (12 years ago)
- Location:
- trunk/includes/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/core/filters.php
r4304 r4323 128 128 add_filter( 'bbp_get_reply_content', 'convert_smilies', 20 ); 129 129 add_filter( 'bbp_get_reply_content', 'wpautop', 30 ); 130 add_filter( 'bbp_get_reply_content', 'bbp_mention_filter', 40 ); 130 131 131 132 // Run filters on topic content … … 137 138 add_filter( 'bbp_get_topic_content', 'convert_smilies', 20 ); 138 139 add_filter( 'bbp_get_topic_content', 'wpautop', 30 ); 140 add_filter( 'bbp_get_topic_content', 'bbp_mention_filter', 40 ); 139 141 140 142 // Add number format filter to functions requiring numeric output -
trunk/includes/core/functions.php
r4321 r4323 282 282 } 283 283 284 /** 285 * Searches through the content to locate usernames, designated by an @ sign. 286 * 287 * @since bbPress (r4323) 288 * 289 * @param string $content The content 290 * @return bool|array $usernames Existing usernames. False if no matches. 291 */ 292 function bbp_find_mentions( $content = '' ) { 293 $pattern = '/[@]+([A-Za-z0-9-_\.@]+)\b/'; 294 preg_match_all( $pattern, $content, $usernames ); 295 $usernames = array_unique( array_filter( $usernames[1] ) ); 296 297 // Bail if no usernames 298 if ( empty( $usernames ) ) 299 return false; 300 301 return $usernames; 302 } 303 304 /** 305 * Finds and links @-mentioned users in the content 306 * 307 * @since bbPress (r4323) 308 * 309 * @uses bbp_find_mentions() To get usernames in content areas 310 * @return string $content Content filtered for mentions 311 */ 312 function bbp_mention_filter( $content = '' ) { 313 314 // Get Usernames and bail if none exist 315 $usernames = bbp_find_mentions( $content ); 316 if ( empty( $usernames ) ) 317 return $content; 318 319 // Loop through usernames and link to profiles 320 foreach( (array) $usernames as $username ) { 321 322 // Skip if username does not exist or user is not active 323 $user_id = username_exists( $username ); 324 if ( empty( $user_id ) || bbp_is_user_inactive( $user_id ) ) 325 continue; 326 327 // Replace name in content 328 $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bbp_get_user_profile_url( $user_id ) . "' rel='nofollow' class='bbp-mention-link $username'>@$username</a>", $content ); 329 } 330 331 // Return modified content 332 return $content; 333 } 334 284 335 /** Post Statuses *************************************************************/ 285 336
Note: See TracChangeset
for help on using the changeset viewer.