#1 WordPress forum plugin created by gVectors Team

wpForo – WordPress Forum Plugin
  • Home
  • Forum
  • Migrate to wpForo
  • Addons
  • Addons Demo
  • Documentation

Forum

Home | Forum

wpDiscuz - WordPress Comment Plugin
  • Forums
  • Members
  • Recent Posts
Forums
Main Support Forums
How-to and Troubles...
Hide external links...
 
Share:
Share
Tweet
Share
Notifications
Clear all

Script [Solved] Hide external links from guests

    Last Post
RSS

stevenminix
Posts: 39
 stevenminix
Topic starter
April 11, 2020 5:13 am
(@stevenminix)
Eminent Member
Joined: 2 years ago

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.

This topic was modified 2 years ago 2 times by stevenminix
13 Replies
1 Reply
Robert
 Robert
Admin
(@robert)
Joined: 6 years ago

Support Team
Posts: 8968
Robert - Twitter
March 5, 2021 5:44 am
Reply tostevenminixstevenminix
Posted by: @stevenminix

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.

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.

Update!

Here is a full solution to hide links for guests:

https://wpforo.com/community/general-discussions/hide-links-for-guests/#post-51489

In case you want to say thank you !)
We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.

Robert
Posts: 8968
Robert - Twitter
 Robert
Admin
April 11, 2020 9:19 am
(@robert)
Support Team
Joined: 6 years ago

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.

In case you want to say thank you !)
We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.

9 Replies
stevenminix
 stevenminix
(@stevenminix)
Joined: 2 years ago

Eminent Member
Posts: 39
April 11, 2020 10:40 am
Reply toRobertRobert
Posted by: @robert

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.

Thank you so much for your reply. I am still confused though. Can you explain in more detail how I need to change my code and where exactly to place it, like what PHP file and does it need to be a specific line?

 

Did you mean just paste the code as i showed you only changing the last part where it says "add_filter and just changing it to "wpforo_content" because if so I tried to do that in the wpforo functions.php and it did not work.

 

Thank you for your help again

Robert
 Robert
Admin
(@robert)
Joined: 6 years ago

Support Team
Posts: 8968
Robert - Twitter
April 11, 2020 10:42 am
Reply tostevenminixstevenminix
Robert

@stevenminix,

If the function is in your theme functions.php, then you just need to insert it in wpForo Content hook using this code. Only this line of code should be added under your code:

add_filter( 'wpforo_content', 'bd_hide_external_link' );

In case you want to say thank you !)
We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.

stevenminix
 stevenminix
(@stevenminix)
Joined: 2 years ago

Eminent Member
Posts: 39
April 11, 2020 10:50 am
Reply toRobertRobert
stevenminix
Robert
Posted by: @robert

@stevenminix,

If the function is in your theme functions.php, then you just need to insert it in wpForo Content hook using this code. Only this line of code should be added under your code:

add_filter( 'wpforo_content', 'bd_hide_external_link' );

Do you mean to place it in wpf-hooks.php?

 

so you are saying ad the full code to themes function.php and then add just the last part to wpf-hooks.php?

 

sorry for the confusion...

Robert
 Robert
Admin
(@robert)
Joined: 6 years ago

Support Team
Posts: 8968
Robert - Twitter
April 11, 2020 10:55 am
Reply tostevenminixstevenminix
Robert
stevenminix
Robert

@stevenminix

No, never add any code in wpForo core files.

All custom codes should be added in functions.php of your active theme.

BTW, where have you added your function above?

You should already know where to add that code.

Easily Add Custom Code in WordPress (without Breaking Your Site)

In case you want to say thank you !)
We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.

stevenminix
 stevenminix
(@stevenminix)
Joined: 2 years ago

Eminent Member
Posts: 39
April 11, 2020 10:59 am
Reply toRobertRobert
stevenminix
Robert
stevenminix
Robert
Posted by: @robert

@stevenminix

No, never add any code in wpForo core files.

All custom codes should be added in functions.php of your active theme.

BTW, where have you added your function above?

You should already know where to add that code.

Easily Add Custom Code in WordPress (without Breaking Your Site)

Okay here is all i have done so far, BTW the links are still visible to guests in wpforo so this has not worked...

I added THIS code to my THEMES functions.php file 

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( 'wpforo_content', 'bd_hide_external_link' );

 

That is all I have done. please tell me what else I need to do to make it work because it is not working yet. thanks

Robert
 Robert
Admin
(@robert)
Joined: 6 years ago

Support Team
Posts: 8968
Robert - Twitter
April 11, 2020 11:03 am
Reply tostevenminixstevenminix
Robert
stevenminix
Robert
Robert

@stevenminix,

Ok all is correct.

Above, I asked you to delete your website cache and then delete wpForo cache clicking the [Delete all caches] button in Dashboard > Forums > Dashboard admin page.

In case you want to say thank you !)
We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.

stevenminix
 stevenminix
(@stevenminix)
Joined: 2 years ago

Eminent Member
Posts: 39
April 11, 2020 11:19 am
Reply toRobertRobert
stevenminix
Robert
stevenminix
Robert
Posted by: @robert

@stevenminix,

Ok all is correct.

Above, I asked you to delete your website cache and then delete wpForo cache clicking the [Delete all caches] button in Dashboard > Forums > Dashboard admin page.

so I deleted the forum cache and my websites cache and still not working. Am I doing anything wrong? I am so desperate for this to work. BTW I even checked on my phone browser which i never use to make sure it is not something with my browser cache.

This post was modified 2 years ago by stevenminix
Robert
 Robert
Admin
(@robert)
Joined: 6 years ago

Support Team
Posts: 8968
Robert - Twitter
April 11, 2020 11:24 am
Reply tostevenminixstevenminix
Robert
stevenminix
Robert
Robert

@stevenminix,

I'm sorry but I have no other idea for you. Maybe the function doesn't work well or you still have a cache issue.

In case you want to say thank you !)
We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.

stevenminix
 stevenminix
(@stevenminix)
Joined: 2 years ago

Eminent Member
Posts: 39
April 11, 2020 11:52 am
Reply toRobertRobert
stevenminix
Robert
stevenminix
Robert
Posted by: @robert

@stevenminix,

I'm sorry but I have no other idea for you. Maybe the function doesn't work well or you still have a cache issue.

The function works as it should with

add_filter( 'the_content', 'bd_hide_external_link' );

which hides all external links for guests in wordpress blog posts and pages(but not wpforo external links)

but when swapped with add_filter( 'wpforo_content', 'bd_hide_external_link' );

The function ceases to work at all anywhere,
Martin
Posts: 832
Martin - Facebook Martin - Twitter
 Martin
Moderator
April 11, 2020 8:21 pm
(@martin)
Support Team
Joined: 6 years ago

@stevenminix,

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() ) {

Powered by gVectors Team. our popular plugins:
wpForo, wpDiscuz

1 Reply
stevenminix
 stevenminix
(@stevenminix)
Joined: 2 years ago

Eminent Member
Posts: 39
April 12, 2020 12:16 am
Reply toMartinMartin
Posted by: @martin

@stevenminix,

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() ) {

WOW! thank you so much your changes worked! 

Robert liked
  All forum topics
  Previous Topic
Next Topic  

Forum Search

Join Us!

Download wpForo plugin
on WordPress.org

wpForo Addons

wpforo-private-messages wpforo-advanced-attachments-128x128 wpforo-embeds-128x128 wpForo User Custom Fields addon wpForo – Blog Cross Posting addon wpForo Ads Manager wpForo – WooCommerce Memberships Integration wpForo Emoticons wpForo – Tenor GIFs Integration
View all Addons »

Recent Topics

  • Prevent access to the url "community"

    By totor, 17 hours ago

  • Dark mode

    By Vijiki, 22 hours ago

  • Menu location

    By Vijiki, 1 day ago

  • Setting recent topics on forum frontend

    By Vijiki, 2 days ago

  • Draft draft users post on wpforo

    By Vijiki, 2 days ago

  • How to remove content from email notification

    By Vijiki, 2 days ago

Topic Tags

  • translation49
  • css49
  • plugin conflict48
  • seo45
  • new features44
  • buddypress42
  • ultimate member40
  • avatar40
  • forum40
  • moderation38
  • login38
  • registration36
  • threaded layout35
  • cache33
  • editor32
  • menu32
  • shortcode31
  • spam29
  • forum accesses29
  • phrases28
View all tags (2163)

Recent Posts

  • RE: New wpForo

    @robert So, will this update feature such as changi...

    By gsmdahisi, 8 hours ago

  • RE: Dark mode

    @chris I did switch to dark mode and I have 3 Questions...

    By Vijiki, 9 hours ago

  • Prevent access to the url "community"

    Hello everyone. We use wpforo on a site with a public...

    By totor, 17 hours ago

  • RE: How to make logo appear on the BP photo

    Just like here, the wpDiscuz Image shown above the menu...

    By Chris, 20 hours ago

  • RE: Draft draft users post on wpforo

    @vijiki, You can set the post/topic unapproved, so th...

    By Chris, 22 hours ago

  • RE: Menu location

    Thanks

    By Vijiki, 22 hours ago

  • Answer to: Problem with private forum

    Hi @darkkang, In the Forum Accesses, disable "Can vie...

    By Chris, 23 hours ago

Share:
Share
Tweet
Share
  Forum Statistics
20 Forums
9,765 Topics
49.5 K Posts
5 Online
44.1 K Members

Latest Post: New wpForo Our newest member: shortterm Recent Posts Unread Posts Tags

Forum Icons: Forum contains no unread posts Forum contains unread posts

Topic Icons: Not Replied Replied Active Hot Sticky Unapproved Solved Private Closed

Powered by wpForo | Copyright © 2016-2022 gVectors Team
Copyright Registration Service - Click here for more information or to register work
wpForo is Registered with the IP Rights Office
Copyright Registration Service

Ref: 4477265538
  • Home
  • Forum
  • Migrate to wpForo
  • Addons
  • Addons Demo
  • Documentation