# Reactions

Reactions for anything, owned by Social Kit.

Reaction *types* (emoji, labels, icons, order) already live in `Reaction_Registry`. This class adds the other half: the
things that can be reacted to. Social Kit registers `social_post` and `social_comment`; another extension registers its own
object type (Forums registers `forum_topic` and `forum_reply`) and then gets, for free:

- one PHP entry point, `Reactions::toggle()`, which checks that reactions are on, that the type and reaction exist, that
  the object exists and that the viewer may react, then stores the reaction and fires the shared action;
- one REST route, `POST clanbite-social-kit/v1/reactions/{object_type}/{id}`;
- the same filters for every surface, so a third party hooks in once: `clanbite_social_kit_reaction_types` (what can be used),
  `clanbite_social_kit_can_react` (who may react to what) and the action `clanbite_social_kit_object_reaction_toggled`.

Registering an object type (do it on the `clanbite_social_kit_register_reactables` action, or with
`clanbite_social_kit_register_reactable()`):

```php
clanbite_social_kit_register_reactable(
    'my_thing',
    array(
        'label'     => __( 'My thing', 'my-plugin' ),
        'exists'    => fn( int $id ): bool => (bool) my_thing_get( $id ),
        'can_react' => fn( int $id, int $user_id, string $slug ) => my_thing_viewer_can_see( $id, $user_id ),
        'toggle'    => fn( int $id, int $user_id, string $slug ): array => my_thing_toggle_reaction( $id, $user_id, $slug ),
    )
);
```

`toggle` stores the reaction and returns `active`, `reaction_type`, `reactions_count`, `reactions_by_type` and `user_reactions`.
A Clanbite site without Social Kit has no reactions: extensions must check `function_exists( 'clanbite_social_kit_register_reactable' )`
before registering and simply not show reactions otherwise.

## Changelog

| Version | Description |
| --- | --- |
| 1.6.4 | Updated |
| 1.6.2 | Introduced |
