=== HiveNest — Conditional Attributes for HivePress ===
Contributors: practicalstack
Tags: hivepress, listings, conditional fields, conditional logic, marketplace
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 0.5.5
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Show or hide HivePress listing fields based on a trigger value — and never let a hidden required field block submission.

== Description ==

HiveNest adds conditional attributes to HivePress listing submit and edit forms.
You build simple rules in wp-admin:

> When **Manufacturer** equals **BMW**, show **Mileage, Transmission, Fuel Type, and Doors**.

When the visitor picks a matching value the child fields appear; otherwise they
are hidden. Crucially, a hidden field that HivePress marks *required* will **not**
block the submission, while a *visible* required field still validates normally.

Everything runs in **Safe Mode**: HiveNest only hides and shows the fields
HivePress already renders. It never moves fields or edits your theme templates.

**Key features**

* Rule builder in WP Admin → HiveNest → Rules (no code, no JSON required).
* Works on both the front-end Add Listing (submit) and Edit Listing forms.
* Robust value matching — handles term IDs, slugs, and labels, so Select2
  attributes work even when the submitted value is a numeric term ID.
* Server-side enforcement: hidden required fields are relaxed during validation
  and save, so submissions and edits are not blocked.
* Hidden values are preserved by default — nothing a visitor typed is lost when
  a field hides and later re-appears.
* Operators: equals, does not equal, is empty, is not empty, contains any.
* Global on/off switch, Debug Mode, and a Compatibility Check screen.

This plugin does not add payments, licensing, or database tables.

== Requirements ==

* WordPress 6.0 or newer.
* PHP 7.4 or newer.
* HivePress 1.7 or newer (with a listing form that renders attributes, e.g. the
  ListingHive theme). HiveNest requires HivePress to be installed and active.

== Installation ==

1. Upload the `hivenest` folder to `/wp-content/plugins/`, or install the ZIP via
   Plugins → Add New → Upload Plugin.
2. Activate HiveNest through the Plugins screen.
3. Make sure HivePress is active and you have created listing attributes.
4. Go to WP Admin → HiveNest → Rules and add your first rule.

== Frequently Asked Questions ==

= Basic usage =

Open WP Admin → HiveNest → Rules → Add New Rule and fill in the sections:

1. **Rule Basics** — name and status.
2. **Where This Rule Applies** — Listing submit and/or Listing edit.
3. **When This Happens** — trigger attribute, operator, and trigger value.
4. **Show These Fields** — the child attributes to reveal when the condition matches.

A live preview shows the rule in plain English as you edit. Save, then open your
Add Listing form and pick the trigger value to see the child fields appear.

= What is Safe Mode? =

Safe Mode hides and shows existing HivePress fields without moving fields or
editing theme templates. It is the only supported mode: HiveNest layers on top of
HivePress rather than replacing any of its rendering.

= How are conditional required fields handled? =

If a child field is HivePress-required but hidden by a rule, HiveNest removes the
requirement for that submission so it cannot block the form — on the front end,
during server validation, and during the listing save/progression steps. When the
same field is visible it stays required and validates normally. Hidden values are
preserved by default, so switching a trigger away and back keeps earlier input.

= Troubleshooting =

Use WP Admin → HiveNest → Compatibility Check to analyse each rule. Common causes
when a rule does not behave as expected:

* The attribute is not assigned to the category the visitor is submitting under,
  so HivePress never renders it.
* The attribute is not enabled for editing, so it does not appear on the form.
* The trigger value does not match any option (a term ID vs slug vs label
  mismatch). The Compatibility Check flags this.
* The field renders on a different form or step than the rule targets.
* Another plugin or theme customization alters HivePress form markup.
* HivePress is inactive — nothing runs until it is active.

For detailed logs, enable **Debug Mode** in HiveNest → Settings (or add
`?hivenest_debug=1` to the form URL, or turn on `WP_DEBUG`). In the browser
console you can also call `HiveNestApplyRules()` and `HiveNestDebugState()`.

= Does uninstalling delete my rules? =

No. Deactivating or deleting HiveNest leaves your saved rules in the database, so
reactivating restores everything.

== Changelog ==

= 0.5.5 =
* Updated the default license server to https://practicalstack.dev (the
  PracticalStack production domain). A `HIVENEST_LICENSE_API_URL` override in
  wp-config.php still takes precedence, so local testing against
  http://localhost:3000 is unchanged.

= 0.5.4 =
* License API base resolution hardened so a `HIVENEST_LICENSE_API_URL` override
  in wp-config.php always wins over the packaged default (e.g. pointing at
  `http://localhost:3000` or `http://127.0.0.1:3000` for local testing). The
  default is no longer applied ahead of the override, an empty override value
  falls back to the default, and trailing slashes are trimmed consistently. The
  License screen footer shows the actually resolved server URL.
* Refreshed License screen copy for the current product model (1 active rule
  without a license; unlimited with a paid license) and removed any remaining
  free-license wording. Buy License links point at the pricing page; activation
  docs and support links open in a new tab.

= 0.5.3 =
* Live license API compatibility: the plugin now understands the production
  API's stable error codes (invalid_license, expired, inactive, wrong_product)
  alongside the legacy ones, and treats an "unlimited" rule_limit or
  site_limit value correctly (unlimited active rules / display).

= 0.5.2 =
* New product model. HiveNest now includes 1 active rule with no license
  required. Paid licenses unlock unlimited active rules: Single Site
  ($10/year, 1 site) and Unlimited Sites ($60/year, unlimited sites).
  Free license generation is no longer part of the product model, though
  previously issued free keys keep working with their stored limits.
  Existing rules are never deleted or auto-disabled — sites over the new
  free limit keep running all active rules; the limit only applies when
  activating additional rules. The License screen now shows the plans and
  links to purchase, docs, and support.

= 0.5.1 =
* License-based active-rule limits. Free licenses (and unlicensed sites) allow
  3 active rules; unlimited plans are honored. Activating a rule beyond the
  limit is blocked with a clear notice — the rule is kept as an inactive draft
  so no work is lost. Editing, disabling, deleting, and inactive drafts are
  always allowed, existing rules are never modified automatically, and the
  frontend continues to run all currently active rules. The Rules screen shows
  a small license summary (e.g. "License: Free · 2 of 3 active rules used")
  and a warning when over the limit.

= 0.5.0 =
* New WP Admin → HiveNest → License screen: activate, check, and deactivate a
  PracticalStack license key for the current site. Shows status, plan, rule
  limit, site limit, and last-checked time; saved keys are displayed masked.
  A failed activation never removes a working license, and connection problems
  keep the last known status. HiveNest continues to work without a license and
  rule limits are not enforced yet. The license server URL can be overridden
  with HIVENEST_LICENSE_API_URL in wp-config.php.

= 0.4.0 =
* Beta packaging: version consistency, dependency-safe no-op when HivePress is
  inactive, security review (capabilities, nonces, escaping), readme.txt, and a
  QA checklist. Debug logging remains gated behind Debug Mode / `?hivenest_debug=1`
  / `WP_DEBUG`. No data changes; existing rules are preserved.

= 0.3.5 =
* Hardened listing edit: the frontend now respects each rule's form scope
  (submit vs edit), matching the server. Verified hidden-value preservation
  across edit cycles.

= 0.3.4 =
* Compatibility Check screen rebuilt into a per-rule safety analysis with
  Looks safe / Warning / Broken badges and troubleshooting hints.

= 0.3.3 =
* Settings page (enable/disable, debug mode, preserve-by-default, script loading,
  Safe Mode) and unified, gated debug logging. Admin notices for inactive
  HivePress and global disable.

= 0.3.2 =
* Guided rule editor with sections, live preview, and guardrails; no JSON needed.

= 0.3.0 – 0.3.1 =
* Rules dashboard: full table, status badges, row actions, stat cards, empty
  state, and a global enable/disable switch.

= 0.1.11 =
* Relaxation now applies across every listing model validation phase (submit,
  save, and the submit wizard progression step).

= 0.1.8 =
* Added model-layer required relaxation so `$listing->save()` no longer blocks on
  hidden required fields.

= 0.1.6 =
* Added server-side required relaxation for the listing form.

= 0.1.5 =
* Reliable front-end show/hide engine with robust Select2 / term-ID matching.

== Upgrade Notice ==

= 0.5.5 =
Updates the default license server to https://practicalstack.dev. Safe to update;
wp-config overrides and existing license state are preserved.

= 0.5.4 =
Fixes the wp-config license API override (HIVENEST_LICENSE_API_URL) and refreshes
License screen copy. Safe to update; existing rules and license state are preserved.

= 0.4.0 =
Beta packaging and cleanup. Safe to update; existing rules are preserved.
