Like System Runtime and API

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.phpLikeSystem::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

  1. enqueue assets/js/like-button.js on frontend requests
  2. localize AJAX URL, nonce, login state, and messages
  3. send brm_handle_like on click
  4. toggle between like_post() and unlike_post()
  5. 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 LikeSystem for runtime behavior, storage, or cache invalidation.
  • Start in LikeButtonElement only when the Bricks render layer changes.
  • Start in assets/js/like-button.js for frontend interaction behavior.
Early Bird Deal

Start Building Your Membership Site Today

Create, sell, and manage your content without limits. BricksMembers gives you everything you need to build membership and LMS sites with Bricks Builder.

Lifetime updates & bug fixes • Premium support • 0% transaction fees • 60-day money-back guarantee