disable "unlike" option / hook for "liked" and "unliked"

Started by danielrichter, February 24, 2023, 12:42:17 PM

Previous topic - Next topic

danielrichter

Dear smf dev community,

what's the best way to disable the "unlike" function? I'm working on a mod to assign special permissions to a user outside the main SMF application, but for this I would need to make sure users can not "unlike" a previous liked post.

I already found the hook for integrate_issue_like, is there another hook for "unlike" too?
If yes, this would make the search obsolete on how to disable "unlike".

Is there a bit more regarding the $this parameter?
See here.

thanks in advance.

Sesquipedalian

The integrate_issue_like hook is called for both the like and unlike actions.

As is always the case for PHP objects, the special variable $this refers to the current object—in this case, the current instance of the Likes class.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Arantor

I'm not sure what value this would have, it feels to me like it's trying to replace something else but less efficiently.

It's good user experience to let people undo actions that may have been made in error - e.g. scrolling through and hitting like by accident on a touch device.

Sesquipedalian

There are probably better ways of doing whatever @danielrichter is trying to accomplish, yes.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

danielrichter

Using the hook to detect either a like was assigned or "deleted".
-Think this is the best way to handle this  8) .

hook

        if($like->get('alreadyLiked')){

            //unlike...
        }
        else
            //like

Sesquipedalian

I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Advertisement: