Clanbite Social Kit Since 1.6.2 Updated in 1.6.4
class ReactionsReactions 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 actionclanbite_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.
class final
- Full name
Kernowdev\ClanbiteSocialKit\Social\Reactions
Constants
| Name | Value | Description |
|---|---|---|
REST_NAMESPACE | 'clanbite-social-kit/v1' | REST namespace shared with the other Social Kit routes. |
TOOLTIP_REACTORS | 10 | How many reactors a reaction tooltip lists before it offers "See all". |
Methods
default_author()A reactor as the browser needs it, when an object type supplies no author callback.display_rows()The reaction chips for one object: every registered reaction with a count or the viewer's mark, then unknown slugs with counts.enqueue_client()Load the shared reactions client (window.clanbite.reactions) for a surface that shows reactions.get_object_type()One object type definition.get_object_types()All registered object types (runs the registration action once).icon_fields()Icon fields shared by every reaction row: emoji, optional image and the hide_* flags the Interactivity bindings read.my_reaction()The viewer's own reaction for the React button ("React" until they react, then their emoji and its name).register_object_type()Register a reactable object type.register_rest_routes()Register the shared REST route.register()Hook the REST route.rest_reactors()REST: everyone who reacted to an object with one reaction (the "See all" list), newest first.rest_toggle()REST: toggle a reaction ({ "reaction_type": "like" }).toggle()Toggle a reaction on any registered object.ui_state()Everything the reaction UI shows for one object: the chips with counts and reactors, the viewer's own reaction and flags.
Defined in inc/Social/Reactions.php
Changelog
| Version | Description |
|---|---|
| 1.6.4 | Updated. |
| 1.6.2 | Introduced. |