=== Devira SEOCommerce ===
Contributors: mohammadissagowhari
Tags: internal linking, woocommerce, seo, search console, schema guard
Requires at least: 6.3
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.10.18
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Increase WooCommerce sales through SEO: smart internal linking with revenue attribution, Search Console revenue ledger & action queue, call/WhatsApp intent tracker, schema/Torob/Emalls guard, internal search analytics, filter page SEO, out-of-stock sales saver, and category SEO audit.

== Description ==

Devira SEOCommerce places products, related articles and services inside your content with custom commercial anchor text, tracks viewport impressions, clicks, call/WhatsApp intents and attributed WooCommerce revenue, and joins Search Console data with store orders into a prioritized SEO Action Queue.

* Unified Dashboard (`Devira SEOCommerce > Dashboard`): dynamic date filter bar (7d, 30d, 90d, This month, Last month, 1 year, Custom + Jalali/Gregorian calendar) with live KPIs and one-click module switches.
* SEO Revenue Ledger & Action Queue (v1.8.1):
  * Search Console CSV/ZIP importer (supports English & Persian headers, Persian/Arabic digits, UTF-8/UTF-16/Windows-1256, automatic date range detection from Dates.csv, and fast batch slug resolution).
  * Calibrated CTR curve (isotonic decreasing regression on non-brand query data + Wilson score upper bound for small samples) and probabilistic Keyword Cannibalization detection.
  * Native WooCommerce Order Attribution (`_wc_order_attribution_*`) reader with store-wide channel breakdown (Organic, Paid/Ads with `gclid` detection, Social, Referral, Direct) and unified refund reconciliation.
  * Cookie-less Call & WhatsApp intent tracker (`tel:` and `wa.me` / WhatsApp links) across products, categories, tags and articles with 4-layer bot protection and GTM `dataLayer` events.
  * Schema & Marketplace (Torob / Emalls / Google) Guard: checks JSON-LD and meta tags against live WooCommerce prices and stock, detecting 10x Rial/Toman mismatches, non-ASCII digits, conflicting duplicate meta tags, and stale page caches.
  * Automatic & manual SEO Change Log (annotations).

== Privacy ==

* Order attribution: when a visitor clicks a Devira link, a first-party cookie `dvl_ref` (signed, no personal data) stores that link for the attribution window (Settings, default 7 days). On sites with a Persian locale the default mode is "always"; elsewhere it is "WP Consent API". Sites that must ask for consent (for example under the GDPR) should choose "WP Consent API" or "off".
* Internal search: a 5-minute cookie `dvl_sq` holding a hash of the last search term prevents double counting when no Redis/APCu is present (not set in "WP Consent API" mode).
* Visitor IP addresses are never stored. Rate limiting uses a short keyed hash of the IP only.
* Call/WhatsApp intents: for logged-in customers the user ID of the last click is stored, and administrators see that customer's name and phone in the report. Mention this in your privacy policy if you enable intents.
* Admin screens load fonts from the plugin folder only; no request is sent to third-party font services.
* License: after you enter a key, this site contacts devira.org on activation, deactivation and once a day. It sends the license key, the site address, a random install ID, and the plugin, WordPress and PHP versions. Nothing else is sent, and nothing is sent before you enter a key.

== Changelog ==

= 1.10.18 =
* Admin: Devira Panel 1.0.3. A plugin's own WordPress menu entry is hidden only when every page under it is in the panel, so no page can go out of reach; each hidden entry and hidden tab bar is its own CSS rule; without JavaScript the panel stays off and the screen looks as before; the coral count sits in the top-end corner of its icon in both directions; the collapsed submenu scrolls on short windows; a theme or collapse change that fails to save is retried once with a fresh nonce and otherwise undone.

= 1.10.17 =
* Admin: Devira Panel 1.0.2. «Devira Panel» is now highlighted as the current entry in the WordPress menu; WordPress's own collapse button is hidden on Devira screens and the menu folds again when the window is widened, so it never covers the panel; the panel is now off up to 960px wide (was 782px), where the plugin's own tabs come back.

= 1.10.16 =
* Admin: Devira Panel 1.0.1. The plugin's own light/dark button is gone (the theme is set only in the panel's rail), and its own section tabs are hidden on desktop, where the panel's submenu lists the same pages; on phones (below 782px) the panel is off and the tabs stay.

= 1.10.15 =
* Admin: the plugin now opens inside the shared Devira Panel (one admin shell for all Devira plugins): a product rail and a collapsible submenu beside the screen, one menu entry «پنل دویرا», the WordPress menu folded on Devira screens, and one light/dark theme saved per administrator. Screens themselves are unchanged; below 782px everything looks as before. Shell: includes/devira-panel/ (Devira Panel 1.0.0).

= 1.10.14 =
* Fix: after an update the schema guard kept showing results from the old version (for example the false "10x Rial/Toman" errors fixed in 1.10.13) for up to 6 hours, because products checked recently are skipped. Results now carry the plugin version; results from another version are hidden and those products are checked again on the next click.

= 1.10.13 =
* Fix: the schema guard flagged every product of a toman store as a "10x Rial/Toman" price error when the schema correctly used IRR (Rank Math and Persian WooCommerce convert toman to rial because IRT is not an ISO code). Schema and price-meta prices are now converted between IRR, IRT, IRHR and IRHT before comparing, so only real errors are reported, such as a toman number labelled IRR.
* Fix: "ago" stayed in English in the search and filter reports ("2 weeks ago"); it now uses the plugin's own translation.

= 1.10.12 =
* Fix: the schema guard's "Check the next pages" button checked 0 pages on shared hosting. It paused whenever the server load average was above 4, and on shared hosting that figure covers the whole server. A click by an administrator now always runs; the load limit (now relative to the CPU count) is kept only for future background checks.
* The guard now says why nothing was checked: heavy server load, no published products, everything checked in the last 6 hours, or products that could not be loaded.

= 1.10.11 =
* Design: admin screens follow the Devira design system — one hover rule (bordered controls take the brand border #149B9E, borderless items a light teal background, the primary button only brightens), one focus ring, Ravi's own named weights (325/400/500/625/775/950), and one set of status colours (danger, warning, success) in light and dark.
* Design: front widgets follow it too — default button colour is #D4421F (hover only brightens), badges are brand-deep teal, product and CTA cards take the brand border and lift 4px on hover, slider arrows are bordered controls. Existing button colour settings are kept.

= 1.10.10 =
* Security: the license public key can no longer be replaced from wp-config.php (DEVIRA_COMMERCE_SEO_LICENSE_PUBKEY is ignored, also on "local" sites).
* Security: an update is installed only if devira.org signed its sha256 for this plugin, version and site. Needs License Server 1.3.8 on devira.org.
* Fix: if the old folder devira-commerce-seo is active next to this one, the site no longer stops with a fatal error; activating this plugin switches the old folder off.
* Docs: Tested up to 7.1; misplaced code comment fixed.

= 1.10.9 =
* Change: a license request waits at most 8 seconds (was 15), so the License page does not hang when devira.org is slow to reach.
* Fix: the 1.10.8 package said "Version 9.9.9" in its plugin header (left over from an update test). The header and the version constant now agree.

= 1.10.8 =
* Security: license answers are checked only against the public key shipped in the plugin (new key); a key stored in the site's own database is no longer trusted.
* Security: removed the built-in fallback to a temporary staging server for licenses and updates. A test site sets DEVIRA_COMMERCE_SEO_LICENSE_SERVER in wp-config.php instead.

= 1.10.7 =
* Change: Problem KPI cards keep a white background; the red top bar and red number are enough.

= 1.10.6 =
* Change: One colour rule across the admin: green means present / fine, red means missing / a problem. Badges, KPI cards, notices, report insights, result boxes and license cards that report a problem are now red (some were coral, amber or teal). Problem KPI cards also show their number in red.
* Fix: KPI cards in the "fine" state had a red top border (for example "No-result rate 0%"); they are now green.
* Change: "Missing landing page" and "Missing buying guide article" in the keyword gap view are red; covered pages stay green. The "found nothing" bars in the search chart and falling numbers in the link report use the same red.
* Change: The sales SEO readiness score card turns red below 80%.

= 1.10.5 =
* Fix: Search analytics → Keyword & content gap only looked at product categories, so a searched brand (for example "wuben") was marked "Missing category page" even when the brand had its own page. A term now counts as covered when a category, brand, tag or attribute value has that name, its slug, or one part of a name like "Wuben | ووبن"; when that archive has it as its Rank Math or Yoast focus keyword; or when a search redirect is set for it.
* Change: Covered terms show which page covers them (for example "Brand: Wuben"), linked to that page. "Missing category page" is now "Missing landing page".
* Change: A blog post whose Rank Math or Yoast focus keyword is the searched term counts as its buying-guide article, not only posts with the term in the title.

= 1.10.4 =
* Change: Every list in the plugin shows 20 rows per page with page links underneath: the report table, articles and products without links, out-of-stock products, the category audit, internal search terms, the filter decision log, the action queue, the ledger, cannibalization, imports, call/WhatsApp clicks, Schema Guard results and notes.
* Speed: The report table is paged, sorted and searched on the server; only the 20 rows on screen get names and links looked up.
* Change: CSV exports always contain every row of the period, whatever page you are on (the report table and search terms exports had a 200 / 5,000 row limit).
* New: An "Impressions" column in the report table: rows with impressions but no clicks are links that were shown and not clicked yet.

= 1.10.3 =
* Fix: New versions published on devira.org could stay invisible for up to a day: the plugin kept its own 12-hour copy of the answer on top of WordPress's 12-hour check. It now asks devira.org every time WordPress checks for updates.
* Fix: On hosts that cannot reach WordPress.org (common in Iran), WordPress stops its update check before asking devira.org, so updates never appeared. The plugin now checks devira.org on its own twice a day and adds its update to WordPress's list, without slowing any page.
* New: License page › Updates: installed and latest version, "Check for updates" and a one-click "Update to version …" button. The plugin's pages also show a notice when a new version is out.
* Change: Activating, moving or deactivating the license refreshes the update list right away (only licensed sites get the download).

= 1.10.2 =
* Fix: On sites with a Persian calendar plugin (Persian WooCommerce, Parsi Date…), dates in the plugin's pages showed a wrong year such as "14 Mordad 784": the date was converted to Jalali twice. Dates are now converted exactly once.
* Fix: On such sites, the day of attributed orders could be stored in the Jalali calendar, so those orders could fall outside the report's date range. Stored dates are now always Gregorian.
* New: Settings › Calendar for dates: Automatic (Jalali on Persian sites), Jalali or Gregorian. It applies to the plugin's pages and is the default calendar of the reports; each user can still switch it in the reports' date bar.

= 1.10.1 =
* New: Moving a site to a new address no longer leaves you stuck. The License page offers "Move the license to this address", which frees the old address on devira.org at the same time (only the same install can move it, so nobody can take a key off another site).
* Change: A license answer from devira.org is trusted for 30 days. Checks run twice a day, so working sites never notice; if a site cannot reach devira.org for over 30 days, the advanced modules lock until a check succeeds. A warning shows from day 7. This closes the "refund, then block devira.org" loophole.
* Security: Updates are checked against the checksum published on devira.org before they are installed.
* Fix: The update system only handles this plugin's own downloads, so it can never interfere with another Devira plugin's update.
* Fix: Deleting the plugin with "Delete data" switched on now frees the site on devira.org first.
* Fix: With "X-Forwarded-For" chosen as the visitor IP header, the address added by your proxy is used, not the first one, which visitors can fake.
* Fix: A locked module's switch on the dashboard no longer shows a checkbox behind it.
* Change: Clearer messages when devira.org is busy or under maintenance.

= 1.10.0 =
* New: Automatic updates from devira.org. Sites with an active license see new versions in Dashboard › Updates with their changelog and install them in one click; each download uses a fresh one-hour link. When the update period has ended, the update is still listed with a renewal link.
* New: Dates in the admin show in the Persian (Jalali) calendar with Persian digits when the site language is Persian.
* New: Declares compatibility with WooCommerce High-Performance Order Storage (HPOS) and the block cart/checkout.
* Speed: The link report runs about 60 queries instead of 460 on large stores (pages and products load in one query, rows are built once per request).
* Speed: The SEO revenue ledger rebuild runs about 20 queries per 500 URLs instead of about 3,000, and frees memory between chunks.
* Accessibility: Every form field has a label, contrast meets WCAG AA (including locked cards and the bar-style link box), and screen readers announce why a locked module's switch is off.
* Change: On the dashboard, a locked module's switch shows as off and cannot be changed; the saved choice comes back after activation.
* Fix: Product cards in the link slider no longer push their button outside the card in some themes, and the filter SEO page no longer scrolls sideways on phones.

= 1.9.1 =
* Fix: A site freed or revoked on devira.org now locks soon: the License page checks live (at most once a minute), the plugin's other screens queue a background check (at most every 15 minutes), and the automatic check runs twice a day instead of once.
* Change: Redesigned License page: status card with badge, key, site and days left; larger activation field with a buy link; module list showing what is open and what needs a license.
* Change: On the dashboard, cards of modules that are off or locked show "Off", fade slightly and link to the License page; locked module cards fade too.

= 1.9.0 =
* New: License page (Devira SEOCommerce › License). Activating a key from devira.org unlocks search analytics, the SEO revenue ledger, filter SEO, out-of-stock SEO and the category audit. The internal linker, dashboard and sales SEO checklist always work.
* License model: modules stay unlocked after the update and support period ends; they lock again only if devira.org answers, with a valid signature, that the license was revoked or this site was deactivated. An unreachable server never locks anything.
* Every license answer is verified with devira.org's Ed25519 public key and bound to this site and install.
* Daily background check (WP-Cron); deactivation frees the site so the key can move to another site.
* Locked modules keep their saved on/off choice and show a "Locked" badge with an activation link on the dashboard.
* Fix: Admin notices from WordPress and other plugins no longer appear inside the page header.
* Change: KPI numbers are always black (the card's top border keeps the colour), card links sit in the bottom corner, and the first card says "Orders".

= 1.8.2 =
* Change: The plugin folder, main file and text domain are now `devira-seocommerce` (previously `devira-linker`), and every "Devira Linker" label now reads "Devira SEOCommerce". Settings, statistics tables, shortcodes, blocks and REST routes keep their existing identifiers, so content and data carry over. Updating from an older build: deactivate the old `devira-linker` plugin, then install and activate this one.
* Fix: Product cache invalidations that arrive during the 30-second throttle are no longer dropped; they are applied on the first read after the lock expires (stale sliders after bulk stock changes).
* Fix: Rate limits now work on hosts without Redis/APCu through a small `dvl_rl` table (one atomic upsert per request), so replayed link signatures can no longer inflate clicks, impressions or call/WhatsApp intents.
* Fix: Internal search log is capped at 3,000 new terms per day and 20 searches per visitor per minute without Redis/APCu.
* Fix: "Rebuild index" runs in batches through WP-Cron and clears meta through the metadata API (safe with persistent object caches, no timeouts on large blogs).
* Fix: The order re-sync after a database upgrade runs in WP-Cron batches instead of blocking the first visitor request.
* Change: Admin screens use a bundled copy of the Vazirmatn v33.0.3 variable font (SIL OFL 1.1) instead of loading it from Google Fonts (no external requests from wp-admin).
* Change: Persian name of the plugin is now «سئوکامرس دویرا»; the block category, Elementor widget and classic editor button are translatable and show it on Persian sites.
* Fix: Removed a no-op Reflection write to the order object in the refund status handler.
* Fix: The stale-nonce fallback only applies when the request path or `rest_route` ends with the click/intent route (a query string can no longer opt other routes in).
* Fix: Saving settings no longer writes the CDN header option or flushes the cache from inside the sanitize callback (WordPress may run it twice); both now happen once per save.
* Fix: Uninstall with "Delete data" now cleans every site of a multisite network.
* Docs: Added a Privacy section. Corrected the 1.8.1 note about an SQL pre-filter in `referring_article_ids()`: related articles come from the saved article index, not a content scan.

= 1.8.1 =
* Unified M0 & Ledger synthesis release combining all architectural improvements:
* Fix (H1): Added atomic in-SQL daily ceilings (`IF(col < cap, col + 1, col)`) to click, impression and intent counters so shared hosts without Redis/APCu are protected against row inflation; exposed Trusted CDN IP Header setting in main Settings as well as Ledger Settings.
* Fix (H4): Unified refund calculation (`Devira_Linker_Stats::effective_refund()`) across both Internal Linker (`dvl_orders`) and SEO Revenue Ledger (`dvl_order_src`), with automatic `_dvl_refund_override` tracking when an order transitions from `refunded` back to an active status and an explicit rule selector in Settings.
* Fix (H7): Added raw decoded Persian slug matching (`rawurldecode`) to the SQL pre-filter in `referring_article_ids()` so blog posts linking to products with unencoded Persian URLs are discovered.
* Fix (H8): Guarded `Devira_Linker_Cache` against autosaves/revisions and stopped flushing the global product query cache when blog posts or static pages are saved (using targeted per-product cache invalidation instead).
* Fix (H9): Dynamic date range labels on Dashboard KPI cards and pagination on the Out-of-Stock SEO audit table.
* Enhancement: Added `devira-linker-ledger` to `Devira_Linker_UI::PAGES` so admin styles and Vazirmatn font load on the Ledger screen.
* Enhancement: Batch URL slug pre-resolver (`Devira_Linker_Urls::preload_urls()`) and automatic `Dates.csv` range extraction for Search Console ZIP imports.
* Enhancement: Category, tag and attribute archive support (`TERM_OFFSET`) for Call & WhatsApp intents plus GTM `dvl_contact_click` event and `navigator.webdriver` guard.
* Enhancement: Wilson score upper bound (`wilson_upper()`) for low-CTR detection and probabilistic Keyword Cannibalization detector (`detect_cannibalization()`).
* Enhancement: 10x Rial/Toman unit mismatch detection, duplicate conflicting meta tag detection, non-ASCII price digit warning, stale page cache re-check, and server load guard in Schema Guard.

= 1.8.0 =
* New module (off by default): SEO revenue ledger & action queue. Joins Search Console data, organic orders read from WooCommerce Order Attribution, Devira link results and call/WhatsApp intents per URL, and ranks what to fix first.
* Call / WhatsApp intent counter with layered bot protection.
* Schema & marketplace guard and SEO change log.
