Contents
Favorites — Plugixa Recipe
A lightweight heart / “save for later” system for logged-in users. Each user has a single favorites list backed by wp_plugixarecipe_favorites.
Frontend UX
Every recipe card and the single recipe page shows a ❤️ icon. Clicking it:
- For a logged-in user: toggles the favorite (insert / delete in
favorites). - For a guest: opens a sign-in prompt (configurable in Settings → Display).
Browsing favorites
A user can view their favorites by visiting a page with this shortcode:
[plugixarecipe collection="favorites-{user_id}"]
Or, more commonly, through the automatic Favorites collection on their account page (the plugin auto-creates one when the user first hearts a recipe — see Collections).
Data model
wp_plugixarecipe_favorites
id | user_id | recipe_id | created_at
Indexes: UNIQUE(user_id, recipe_id), recipe_id.
Why not use post meta?
Keeping favorites in a dedicated table means:
- Fast per-user counts (
WHERE user_id = … COUNT(*)) — useful on the dashboard. - Per-recipe counts show “145 people saved this”.
- Clean removal on user deletion.
Cached count
Each recipe stores a like_count (cached total favorites). This avoids a JOIN + COUNT on every card render. The counter is incremented/decremented transactionally with the insert/delete on favorites.
Frontend JavaScript
The favorite button uses a single REST endpoint:
POST /wp-json/plugixarecipe/v1/favorites
{ "recipe_id": 42 }
Returns the new favorite state and updated count. See assets/frontend/js/recipes.js.
Disabling favorites
Turn off Settings → Display → Show favorites button to hide all heart icons globally.