=== AddonLogic Points Rewards Counter ===
Contributors: snehalpancholi
Tags: points, rewards, gamification, loyalty, leaderboard
Requires at least: 6.0
Tested up to: 6.7
Requires PHP: 8.1
Stable tag: 1.0.0
License: GPL-2.0+
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Award configurable points to logged-in users for actions (login, comment, post view, new post) and display their balance via shortcodes. Includes an admin leaderboard.

== Description ==

**AddonLogic Points Rewards Counter** is a lightweight gamification plugin that rewards your community for engaging with your WordPress site.

**Key Features:**

* Award points for four configurable actions: daily login, approved comment, unique post view (24-hour window), and new post published.
* Per-action enable/disable toggle and configurable point values.
* Persistent running balance stored in user meta — survives plugin deactivation/reactivation.
* Full activity log stored in a custom database table with indexed queries.
* Server-side daily-dedupe for login and view actions — no duplicate awards.
* `[pwr_balance]` shortcode with optional inline history table.
* `[pwr_leaderboard top="10"]` shortcode with medal icons for the top three.
* Admin leaderboard (Tools > Points Leaderboard): search, sort, view per-user log in a modal, and manually adjust balances.
* Admin Settings page (Settings > Points Rewards) with a live configuration summary.
* Auto-update support from the AddonLogic update server.
* No jQuery dependency — vanilla JS with the Fetch API throughout.

== Installation ==

1. Upload the `points-rewards-counter` folder to `/wp-content/plugins/`.
2. Activate the plugin through the **Plugins** menu in WordPress.
3. Go to **Settings > Points Rewards** and configure your point values.
4. Place `[pwr_balance]` in any page or widget to show users their balance.
5. Place `[pwr_leaderboard top="10"]` wherever you want to display the ranking table.

== Shortcodes ==

= [pwr_balance] =

Displays the current logged-in user's point balance. Guests see a configurable prompt.

Attributes:
* `label` — Label before the count. Default: "Your Points:"
* `show_history` — 1 to show collapsible activity table. Default: 0
* `history_limit` — Rows in the history table. Default: 10
* `guest_text` — Text shown to guests. Default: "Log in to see your points."
* `show_login_link` — 1 to append a login link for guests. Default: 1

= [pwr_leaderboard] =

Displays the top N users ranked by current balance.

Attributes:
* `top` — Number of users to display. Default: 10
* `title` — Optional heading. Default: "" (none)

== Frequently Asked Questions ==

= Does this work for guest users? =
Points are only awarded to logged-in users. Guests see the `guest_text` in the balance shortcode.

= Can I manually adjust a user's balance? =
Yes. Go to **Tools > Points Leaderboard**, find the user, and click **Adjust** to add or deduct points with an optional note.

= What happens to data when I uninstall? =
The plugin drops the `{prefix}addlc_pwr_log` table, deletes the `addlc_pwr_balance` user meta from all users, and removes the plugin options. Deactivation alone does not delete any data.

= Are points lost on deactivation? =
No. Balances are stored in user meta and the custom log table, both of which persist across deactivation/reactivation cycles.

= Can post view points be gamed by refreshing? =
No. Each unique post view is tracked server-side (one per user per post per UTC day) and the JS also sets a 24-hour browser cookie as an additional guard before even sending the AJAX request.

= Will this slow down my site? =
No. The view-tracker script loads only on singular post pages for logged-in users. All AJAX endpoints check nonces. Log queries are indexed. Leaderboard results are cached in a 10-minute transient.

== Screenshots ==

1. Settings page — configure points per action with enable/disable toggles.
2. Admin leaderboard — sortable table with search, per-user log modal, and manual balance adjustment.
3. `[pwr_balance]` widget with expanded activity history.
4. `[pwr_leaderboard]` shortcode output with medal icons.

== Changelog ==

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 1.0.0 =
Initial release. No upgrade steps required.
