Skip to:
Content

bbPress.org

Changeset 4998


Ignore:
Timestamp:
06/24/2013 04:19:41 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Introduce bbp_find_mentions_pattern() function to make it easier to change the pattern to match usernames against. Helpful for non-latin characters. Also add additional filter to bbp_find_mentions() to allow for late filtering of results. Props aliso. Fixes #2226.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/core/functions.php

    r4995 r4998  
    285285
    286286/**
     287 * Set the pattern used for matching usernames for mentions.
     288 *
     289 * Moved into its own function to allow filtering of the regex pattern
     290 * anywhere mentions might be used.
     291 *
     292 * @since bbPress (r4997)
     293 * @return string Pattern to match usernames with
     294 */
     295function bbp_find_mentions_pattern() {
     296    return apply_filters( 'bbp_find_mentions_pattern', '/[@]+([A-Za-z0-9-_\.@]+)\b/' );
     297}
     298
     299/**
    287300 * Searches through the content to locate usernames, designated by an @ sign.
    288301 *
     
    293306 */
    294307function bbp_find_mentions( $content = '' ) {
    295     $pattern   = '/[@]+([A-Za-z0-9-_\.@]+)\b/';
     308    $pattern   = bbp_find_mentions_pattern();
    296309    preg_match_all( $pattern, $content, $usernames );
    297310    $usernames = array_unique( array_filter( $usernames[1] ) );
    298311
    299312    // Bail if no usernames
    300     if ( empty( $usernames ) )
    301         return false;
    302 
    303     return $usernames;
     313    if ( empty( $usernames ) ) {
     314        $usernames = false;
     315    }
     316
     317    return apply_filters( 'bbp_find_mentions', $usernames, $pattern, $content );
    304318}
    305319
Note: See TracChangeset for help on using the changeset viewer.