XF 2.2 How to make the like button visible to guests?

Ferry

Member
Hi,

How can I make the like button visible to guests? I don't need it to work, guests are not allowed to vote and I'm fine with that. I just want guests to just be able to see the button and if possible to have a notification when they click it: "You need to login to do this".

Best Regards
 
Solution
Thanks for your tip, that should help, but for now it looks like a temporary solution. The file change warning always frustrates me, so I try not to resort to anything that can trigger annoying notifications.

Best Regards
I've improved this code a bit and turned it into a small add-on. I hope it works for you, don't forget to do your own tests.

You can customize its behavior from the add-on's options page.
Here's a simple solution for this, someone can put it in an add-on or do it in a more polished way.

I also haven't tested it extensively, perform your own tests.



Instructions

Go to src\XF\Template\Templater.php, then jump to line 3739.

There should be a code like this:

PHP:
        if (!$content->canReact())
        {
            return '';
        }

Change this code as follows:

PHP:
        /* if (!$content->canReact())
        {
            return '';
        } */

Visitors will probably be redirected to the login screen when they try to react, while registered members without permission will be warned that they do not have permission. As I said, test if it breaks other functions on your site. This will also warn that the files have been modified.

Let me know if there are any problems.
 
Last edited:
Here's a simple solution for this, someone can put it in an add-on or do it in a more polished way.

I also haven't tested it extensively, perform your own tests.



Instructions

Go to src\XF\Template\Templater.php, then jump to line 3739.

There should be a code like this:

PHP:
        if (!$content->canReact())
        {
            return '';
        }

Change this code as follows:

PHP:
        /* if (!$content->canReact())
        {
            return '';
        } */

Visitors will probably be redirected to the login screen when they try to react, while registered members without permission will be warned that they do not have permission. As I said, test if it breaks other functions on your site. This will also warn that the files have been modified.

Let me know if there are any problems.


Thanks for your tip, that should help, but for now it looks like a temporary solution. The file change warning always frustrates me, so I try not to resort to anything that can trigger annoying notifications.

Best Regards
 
Thanks for your tip, that should help, but for now it looks like a temporary solution. The file change warning always frustrates me, so I try not to resort to anything that can trigger annoying notifications.

Best Regards
I've improved this code a bit and turned it into a small add-on. I hope it works for you, don't forget to do your own tests.

You can customize its behavior from the add-on's options page.
 

Attachments

Solution
Back
Top Bottom