I know that wpforo on it's face does not provide the ability to hide external links from guests even though this feature is a well known popular feature used in forums all over the internet.
However FOR ME it is a game changing feature that I absolutely require. I just need a developer to give me the proper coding and where to place it in the plugins files.
Here is the code I used to use but I have not been able to get it to work with wpforo function.php files.
function bd_hide_external_link( $content ) {
if ( is_user_logged_in() ) {
return $content;
}
$content = preg_replace_callback('/<a\s[^>]*?href=([\'"])(.+?)\1\s?[^>]*>([^<]+)<\/a>/im', function ($matches){
// replace the domain name with your domain
if ( strpos( $matches[2], 'facebook.com' ) !== false ){
return $matches[0];
}
// for external url
return '<a href="#">Login Please to see the link</a>';
}, $content );
return $content;
}
add_filter( 'the_content', 'bd_hide_external_link' );
So PLEASE I beg you to give me the info on what code to write and where to place it. I know this is possible.
So PLEASE I beg you to give me the info on what code to write and where to place it. I know this is possible.
Hi @stevenminix,
Your function may affect some content processes in wpForo posts content, for example, shortocdes, URLs controlling, image displaying. wpForo has dozens of processes on posts content. So if in future you got some problem with wpForo, first remove your function and test it again.
You can add your function to wpForo post content using wpForo posts content 'wpforo_content' hook:
add_filter( 'wpforo_content', 'bd_hide_external_link' );
Don't forget delete wpForo cache in Dashboard > Forums > Dashboard admin page before checking it.
Please leave a direct link to the post where I can see an external link. Also, leave some screenshot of the code you've instead in current active WordPress theme functions.php .
I also recommend change this hooks:
add_filter( 'wpforo_content', 'bd_hide_external_link' );
to this:
add_filter( 'wpforo_content_after', 'bd_hide_external_link', 10, 2 );
And please change your function first line from this:
function bd_hide_external_link( $content ) {
to this:
function bd_hide_external_link( $content, $post = array() ) {