How liking works

Liking

A like is a comment of type like on the post, by the member who liked it. Adding one also adds a BuddyPress activity item; removing one deletes both. Like comments are left out of the post’s comment count and never trigger comment notification emails. A post can be liked when it is publicly viewable, in any public status such as published or archived.

Logged-in members get a Like or Unlike button, a small form that posts back to the same page and then redirects, so reloading never likes twice. Nothing is ever liked by following a link.

Liking before logging in

Logged-out visitors get a Like link to the login page that returns them to the post. The link is the same for every visitor, so cached pages stay correct.

  1. Tapping it saves the pending like in the browser (IndexedDB database lh-pending-actions, store intents, key current: one pending action at a time, newest wins), then goes to the login page. It expires after 15 minutes.
  2. After logging in, on that post only, the like is sent to the REST API, the pending like is cleared and the button shows Liked with a brief Undo.
  3. Without JavaScript, or on another device, the return URL’s lh_bp_pls-intent=like shows a highlighted Confirm your like button instead. The parameter only changes the button; the member still has to press it.

REST API

Both routes take a post_id, need a logged-in user (with the wp_rest nonce for cookie authentication) and return post_id, liked and the post’s like count.

Hooks

Requirements

BuddyPress and WordPress 6.7 or later. The front end uses the idb-keyval library: the shared copy from LH idb-keyval when that is active, otherwise the plugin’s own bundled copy.