I think this is the right approach, but it’s not working…
In bp-custom –
function add_target_func_callback($matches){
if ( (parse_url($matches[1], PHP_URL_HOST) != 'my.com') && (parse_url($matches[1], PHP_URL_HOST) != 'www.my.com') ){
$matches[0] = 'target="_blank" ' . $matches[0];
}
return $matches[0];
}
function add_target_blank($content) {
$content = preg_replace_callback('#href=['"]([^'"]*)['"]#i', 'add_target_func_callback', $content);
return $content;
}
add_filter('bp_get_activity_content_body', 'add_target_blank', 1, 1 );
I’m not sure that $content is being passed to add_target_blank
Got this to work by setting add_filter priority to 12
Remember to also filter on bp_get_activity_latest_update to handle links in member-header
@shanebp nice function, Shane, will use it.
if you digged into all these activity things, maybe you know how could I limit (e.g., one per activity) these external links in activity updates?
thank you.
So any update can only have one link in it?
I don’t have a function for you, but I’d say you need to count the number of hrefs.
For anything over 1, remove everything between and including the href open and close tags.
Of course, the resulting update may not make sense, english-wise.