Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: @ Group

a simple example that will auto link a group slug mention in an activity update

this a proof == i’m lazy. so it only matches the group slug and NOT the true name (someone would have to build a function for that)

…and this uses a caret but anything can be used

function bp_activity_at_groupname_filter( $content ) {

//define your catch hook, i'm partial to the bang but lets eat a caret
$pattern = '/[\\^]+([A-Za-z0-9-_]+)/';
preg_match_all( $pattern, $content, $groupnames );

/* Make sure there's only one instance of each groupname */
if ( !$groupnames = array_unique( $groupnames[1] ) )
return $content;

foreach( (array)$groupnames as $groupname ) {

//note this is the group slug as for a proof - need to build a group "name" lookup function
if ( !$group_id = BP_Groups_Group::group_exists( $groupname ) )
continue;

//too much work to get a link
$thisgroup = new BP_Groups_Group( $group_id );

$content = str_replace( "^$groupname", "<a href='" . bp_get_group_permalink( $thisgroup ) . "' rel='nofollow'>^$groupname</a>", $content );
}

return $content;
}
add_filter( 'bp_activity_new_update_content', 'bp_activity_at_groupname_filter' );
add_filter( 'groups_activity_new_update_content', 'bp_activity_at_groupname_filter' );
add_filter( 'pre_comment_content', 'bp_activity_at_groupname_filter' );
add_filter( 'group_forum_topic_text_before_save', 'bp_activity_at_groupname_filter' );
add_filter( 'group_forum_post_text_before_save', 'bp_activity_at_groupname_filter' );
add_filter( 'bp_activity_comment_content', 'bp_activity_at_groupname_filter' );

Skip to toolbar