Skip to:
Content
Pages
Categories
Search
Top
Bottom

Restrict links only for registered users.


  • Md Sadiqur Rahman
    Participant

    @sadiq20161

    Hi there,
    I was looking for an option restrict link only for registered users. Say someone put a link in the comment, normal user will see it as it is (e.g https://bbpress.org/forums/new-topic/) But unregistered one will see “please register to see the link”. Is there a way to add this functionality?

    Thank you
    Md Sadiqur Rahman

Viewing 4 replies - 1 through 4 (of 4 total)

  • virusek89
    Participant

    @virusek89

    I also need something like that.
    Is there any plugin or code?


    Robin W
    Moderator

    @robin-w

    nothing I know of would do that


    Samuel Elh
    Participant

    @elhardoum

    You can use bbp_get_reply_content filter, but this can be a disaster when you take off all the links that other plugins or the theme could have in the reply content. A good example is the mentions being added by BuddyPress, but after using this, they turn into the restriction notice..

    add_filter('bbp_get_reply_content', 'restricted_links', 20, 2);
    
    function restricted_links($content, $post_id) {
      if ( is_user_logged_in() )
        return $content;
    
      return preg_replace_callback( '/<a(.*?)href(.*?)>(.*?)<\/a>/si', function($m){
        return sprintf(
          '<span class="protected-link" style="background:#f3f3f3;padding: 2px 5px;display:inline-block;border-radius:3px">[Restricted Link] Please <a href="%s">register</a> to view this link</span>',
          home_url('/wp-login.php?action=register')
        );
      }, $content );
    }

    You may pass-in the link text after the notice or something, it is all up to you so play around with the code or ping me if you needed help.


    virusek89
    Participant

    @virusek89

    Thank you, the code works properly 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar