1 | <?php |
||
2 | /** |
||
3 | * Elgg delete like action |
||
4 | * |
||
5 | */ |
||
6 | |||
7 | // Support deleting by id in case we're deleting another user's likes |
||
8 | $id = (int) get_input('id'); |
||
9 | |||
10 | $like = null; |
||
11 | if ($id) { |
||
12 | $like = elgg_get_annotation_from_id($id); |
||
13 | } |
||
14 | |||
15 | if (!$like) { |
||
0 ignored issues
–
show
|
|||
16 | $likes = elgg_get_annotations([ |
||
17 | 'guid' => (int) get_input('guid'), |
||
18 | 'annotation_owner_guid' => elgg_get_logged_in_user_guid(), |
||
19 | 'annotation_name' => 'likes', |
||
20 | ]); |
||
21 | $like = $likes[0]; |
||
22 | } |
||
23 | |||
24 | if (!$like || !$like->delete()) { |
||
25 | return elgg_error_response(elgg_echo('likes:notdeleted')); |
||
26 | } |
||
27 | |||
28 | return elgg_ok_response('', elgg_echo('likes:deleted')); |
||
29 |
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.