The Like System adds lightweight post engagement tracking with a dedicated likes table, a frontend AJAX toggle, and a Bricks element for rendering the current state. The current runtime owner is src/Modules/Like/LikeSystem.php.
Module Gate and Entry Points
- Module flag:
brm_enable_like_system - Bootstrap path:
src/Bootstrap/BootstrapCoordinator.php→LikeSystem::boot() - AJAX action:
brm_handle_like - Bricks element:
src/Elements/LikeButtonElement.php - Admin page:
admin.php?page=brm_like_system
Storage Model
The module persists likes in the {prefix}brm_post_likes table and keeps a cached post-level count in the _brm_like_count post meta key.
Frontend Flow
- enqueue
assets/js/like-button.json frontend requests - localize AJAX URL, nonce, login state, and messages
- send
brm_handle_likeon click - toggle between
like_post()andunlike_post() - recompute cached count and invalidate request-local caches
Key Methods
like_post( $user_id, $post_id )unlike_post( $user_id, $post_id )is_post_liked_by_user( $user_id, $post_id )get_post_like_count( $post_id )get_user_liked_posts( $user_id, $limit, $offset )get_post_likers( $post_id, $limit, $offset )
Cache and Mutation Notes
On each like or unlike, the module refreshes the cached count, clears request-registry like maps, and calls MutationContract::post_data_updated() so other readers do not continue using stale state.
Edit Guidance
- Start in
LikeSystemfor runtime behavior, storage, or cache invalidation. - Start in
LikeButtonElementonly when the Bricks render layer changes. - Start in
assets/js/like-button.jsfor frontend interaction behavior.