public function bbpen_pre_insert($post_id)
 {
     $data = get_post($post_id);
     $content = $data->post_content;
     $type = $data->post_type;
     $title = $type == 'reply' ? get_the_title($data->post_parent) : $data->post_title;
     $link = $type == 'reply' ? bbp_get_reply_url($post_id) : get_the_permalink($post_id);
     $author = $data->post_author;
     $date = $data->post_date;
     $mentions = bbp_find_mentions($content);
     $post_data = array();
     $post_data[0] = $post_id;
     $post_data[1] = $title;
     $post_data[2] = $link;
     $post_data[3] = $content;
     $post_data[4] = $date;
     $post_data[5] = $type;
     $mentioned_users = array();
     if ($mentions) {
         // we have mentions
         foreach ($mentions as $username) {
             $user_id = get_user_by('slug', $username)->ID;
             $this->notify($user_id, $author, $post_data);
             $mentioned_users[] .= $user_id;
         }
     }
     $this->unnotify($mentioned_users, $post_id);
 }
Example #2
0
/**
 * Finds and links @-mentioned users in the content
 *
 * @since 2.2.0 bbPress (r4323)
 *
 * @uses bbp_find_mentions() To get usernames in content areas
 * @return string $content Content filtered for mentions
 */
function bbp_mention_filter($content = '')
{
    // Get Usernames and bail if none exist
    $usernames = bbp_find_mentions($content);
    if (empty($usernames)) {
        return $content;
    }
    // Loop through usernames and link to profiles
    foreach ((array) $usernames as $username) {
        // Skip if username does not exist or user is not active
        $user = get_user_by('slug', $username);
        if (empty($user->ID) || bbp_is_user_inactive($user->ID)) {
            continue;
        }
        // Replace name in content
        $content = preg_replace('/(@' . $username . '\\b)/', sprintf('<a href="%1$s" rel="nofollow">@%2$s</a>', bbp_get_user_profile_url($user->ID), $username), $content);
    }
    // Return modified content
    return $content;
}
Example #3
0
/**
 * Finds and links @-mentioned users in the content
 *
 * @since bbPress (r4323)
 *
 * @uses bbp_find_mentions() To get usernames in content areas
 * @return string $content Content filtered for mentions
 */
function bbp_mention_filter($content = '')
{
    // Get Usernames and bail if none exist
    $usernames = bbp_find_mentions($content);
    if (empty($usernames)) {
        return $content;
    }
    // Loop through usernames and link to profiles
    foreach ((array) $usernames as $username) {
        // Skip if username does not exist or user is not active
        $user_id = username_exists($username);
        if (empty($user_id) || bbp_is_user_inactive($user_id)) {
            continue;
        }
        // Replace name in content
        $content = preg_replace('/(@' . $username . '\\b)/', "<a href='" . bbp_get_user_profile_url($user_id) . "' rel='nofollow' class='bbp-mention-link {$username}'>@{$username}</a>", $content);
    }
    // Return modified content
    return $content;
}