=== WRT Reading Tools ===
Contributors: sonofgod
Donate link: https://www.paypal.com/donate?hosted_button_id=U4J5DYNJ4ZBEQ
Tags: reading time, word count, accessibility, font size, post meta, views, counter, text size, estimated reading time, post info, content tools, ajax counter, post views, print content, contrast mode, accessibility tools, toolbar, color palettes, shortcode
Requires at least: 5.0
Tested up to: 6.9.4
Requires PHP: 7.4
Stable tag: 1.1.2
License: GPL v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Adds a clean, feature-rich, and highly customizable bar with word count, estimated reading time, post views, font resizing, contrast mode, and clean print options to your WordPress content. Includes backend view stats and an admin live preview.

== Description ==

WRT Reading Tools enhances your content by adding a professional and informative bar, providing valuable metadata and accessibility tools directly within your posts and pages.

**Core Features:**

*   **Word Count:** Automatically calculates and displays the total word count based on the main filtered content block (`the_content`). Provides the most relevant count for the displayed text. Note: Accuracy might be slightly affected by complex shortcode outputs within the content.
*   **Estimated Reading Time:** Shows reading time in minutes, calculated using a configurable WPM setting (Default: 200 WPM) based on the filtered content word count.
*   **Post View Counter:**
    *   Reliably tracks and displays post/page views via AJAX with secure nonces and cookie tracking.
    *   Configurable Cookie Expiry (Default: 6 hours).
    *   Global & Per-Post Start Value options to set an initial count.
    *   View Reset button in the post editor metabox.
    *   (Note: Disabled by default, must be enabled in settings).
*   **Text Font Resizer:** Includes +/- buttons and an optional Reset button. Remembers user preference via LocalStorage.
*   **Accessibility & Utility Buttons:**
    *   Optional Contrast/Night Mode toggle with multiple icon choices. Remembers user preference.
    *   Optional Clean Print button using a configurable selector to print only the main content area.

**Extensive Customization & Compatibility:**

*   **Display Control:**
    *   Show bar on: Only Posts (Default), Only Pages, Both, or **Manual Placement Only** (disables automatic insertion).
    *   Automatically excluded from the homepage.
    *   Position: Above (Default) or Below content.
    *   Mobile Visibility: Option to show (Default) or hide on mobile.
*   **Component Toggle:** Individually enable/disable Word Count, Reading Time, View Counter, Font Resizer (+/-), Font Reset Button, Contrast Button, and Print Button.
*   **Theme Compatibility:** Settings for **CSS selectors** for Font Resizer target and Clean Print area ensure maximum compatibility. Detailed instructions provided. Includes basic validation for selectors.
*   **Visual Styling:**
    *   Choose from **30+ built-in Color Palettes** with **live admin preview**!
    *   Select your preferred icon for the Contrast Mode button (with preview).
    *   Add your own rules via the **Custom CSS** field.
*   **Shortcode:** `[wrt_only_tools]` available to manually display only the action buttons group.
*   **Troubleshooting:** Includes tips for using Custom CSS to hide the bar from unwanted areas.
*   **User Experience:** Added a second "Save Changes" button at the top of the admin settings page.
*   **Professional & Lightweight:** Clean design, uses WordPress Dashicons, CSS Variables.
*   **Localization Ready:** Fully translatable.

Provide richer insights, better accessibility, and more control using WRT Reading Tools!

== Installation ==

1.  **WordPress Admin:** `Plugins > Add New Plugin` > `Upload Plugin` > Choose `wrt-reading-tools.zip` > `Install Now` > `Activate`.
2.  **FTP:** Upload `wrt-reading-tools` folder to `/wp-content/plugins/` > Activate in `Plugins` menu.
3.  **Configuration:** Go to **Settings > Reading Tools**. Configure all options, especially "Target Selectors". Enable desired components & buttons (View Counter is off by default).

== Frequently Asked Questions ==

= The Font Resizer (+/- buttons) doesn't work. =
Go to `Settings > Reading Tools > Target Selectors`. Ensure the "Font Resizer Target" field contains the correct CSS selector for your theme's main text container (e.g., `.entry-content`). Follow the instructions there.

= The Print button prints the wrong content or the whole page. =
Go to `Settings > Reading Tools > Target Selectors`. Ensure the "Clean Print Target" field contains the correct CSS selector for the *specific* content block you want to print.

= The bar appears in unwanted places (widgets, etc.). =
Use the "Custom CSS Rules" field under `Settings > Reading Tools`. The "Tips & Tricks" section provides instructions (e.g., `#sidebar .widget .wrt-reading-tools-bar { display: none; }`).

= View Counter shows 0 or doesn't update? =
1.  **Enable It:** Check "View Count" under `Settings > Reading Tools > Components & Options`.
2.  **Clear Caches:** Crucial! Clear all caches (plugin, server, CDN, browser) and test in an Incognito window.
3.  **Admins Ignored:** Logged-in admins are not counted. Test logged out.
4.  **Cookie Expiry:** Wait for the cookie (check setting) or use Incognito.
5.  **Check Console:** Look for JS errors or failed AJAX requests (F12 > Console / Network).

= How do I reset the View Count? =
Edit the post/page, find the "WRT View Stats" metabox, click "Reset". The count updates after refresh.

= How does the "Start Value" for views work? =
Sets the base number *before* the first view is counted. Example: Start Value 100 -> first visitor makes count 101. A per-post override (set via metabox *before* first view) takes precedence.

= Can I change the Reading Speed (WPM) / View Count Cookie Duration? =
Yes, under `Settings > Reading Tools > Components & Options`.

= Why might the Word Count/Read Time seem slightly off compared to other tools? =
The calculation is based on the text content after WordPress filters (like shortcodes) have run, but *before* removing HTML tags. Complex structures (like page builders) might leave non-visible text remnants after tag removal, slightly affecting the count compared to manually counting only visible words. This method provides the most accurate count based on the content block processed by WordPress filters.

= What shortcodes are available? =
*   `[wrt_only_tools]`: Displays only the interactive buttons (Resizer, Reset, Contrast, Print) based on enabled settings. Useful for manual placement. Requires plugin assets (JS/CSS) to be loaded on the page.

= Where are the settings? =
Main settings: **Settings > Reading Tools**. Per-post view settings/reset: **"WRT View Stats" metabox** in the post/page editor sidebar.

== Screenshots ==

1.  The reading tools bar displayed on a sample post.
2.  Admin Settings: Display and Target Settings.
3.  Admin Settings: Components & Options (showing WPM, View Count options, Cookie Expiry).
4.  Admin Settings: Toolbar Buttons section (showing button toggles and Contrast Icon select).
5.  Admin Settings: Color Palette selection with Live Preview area above.
6.  Admin Settings: Custom CSS input area.
7.  Admin Settings: Shortcodes (Showing available ones) and Tips & Tricks sections.
8.  The "WRT View Stats" metabox in the post editor with Reset button.

== Changelog ==

= 1.1.2 =
*   Feature: Added many new Color Palettes (Total 30+).
*   Feature: Added Contrast Button Icon selection with more options (including accessibility icon).
*   Feature: Added Live Preview for Color Palette and Contrast Icon in Admin Settings.
*   Feature: Added optional specific CSS Selector setting for Word Count calculation (uses DOM/XPath with fallback).
*   Feature: Added second "Save Changes" button at the top of the Admin Settings page.
*   Refinement: Improved Word Count and Read Time accuracy for the main bar by using filtered content with a new DOM/XPath selector and fallback system[cite: 132, 136].
*   Refinement: Shortcodes now use raw content and minimal cleaning to ensure maximum stability and prevent conflicts[cite: 134, 137].
*   Refinement: Removed unstable shortcodes ([wrt_reading_tools], [wrt_views], [wrt_read_time], [wrt_word_count]); only [wrt_only_tools] is now supported.
*   Fix: Resolved final JavaScript localization errors (`wrt_frontend_params` vs `wrt_admin_data`).
*   Fix: Corrected logic causing View Counter AJAX to fail silently or `ERR_INCOMPLETE_CHUNKED_ENCODING` errors by ensuring correct calculation method consistency.
*   Fix: Addressed PHP Deprecated notice for `mb_convert_encoding`.
*   Fix: Corrected CSS button background issue for dark palettes using `--wrt-button-bg` variable.
*   Fix: Implemented targeted content printing using IFrame to print only selected area.

= 1.1.1 =
*   Fix: Corrected CSS variable usage for button backgrounds with dark palettes.
*   Fix: Ensured JS initializes correctly regardless of enabled components.
*   Fix: Resolved PHP warnings/notices (duplicate constants, deprecated functions) and potential fatal errors.
*   Refinement: Centralized constant definitions.
*   Refinement: Updated settings descriptions and layout.

= 1.1.0 =
*   Feature: Added Font Size Reset button.
*   Feature: Added Contrast/Night Mode toggle button.
*   Feature: Added Clean Print button.
*   Feature: Added Configurable Print Area CSS Selector setting.
*   Feature: Added Configurable Words Per Minute (WPM) setting.
*   Feature: Added Configurable Cookie Expiry setting for view counter.
*   Feature: Added View Count Reset button in Post Editor Metabox.
*   Feature: Added Global and Per-Post Start Value options for View Counter.
*   Feature: Added several Shortcodes (later revised/removed).
*   Update: View Counter calculation now respects start values.
*   Fix: Improved context checking to prevent bar display in widgets.
*   Fix: Resolved View Counter AJAX/Nonce reliability issues.

= 1.0.0 =
*   Initial release.

== Upgrade Notice ==

= 1.1.2 =
Adds many new palettes, contrast icon options, live admin previews, an optional word count selector, and several important bug fixes related to AJAX, JavaScript initialization, and PHP errors. Shortcodes for individual data points (word count, read time, views, full bar) have been removed due to instability/inconsistency; only `[wrt_only_tools]` remains.

= 1.1.1 =
Minor fixes and refinements for styles and JS.

= 1.1.0 =
Major feature update! Adds Reset/Contrast/Print buttons, advanced View Counter options, and configurable WPM/Cookie settings. **Note:** Several shortcodes were removed in v1.1.2. Review new settings under Settings > Reading Tools.

= 1.0.0 =
Initial release. Configure options under Settings > Reading Tools. Ensure "Target Selectors" are set correctly.