=== affilun ===
Contributors: rioriost
Tags: affiliate, product links, product card, amazon, rakuten
Requires at least: 6.6
Tested up to: 7.0
Requires PHP: 8.1
Stable tag: 0.9.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Manage reusable affiliate product links and product cards for Amazon, Rakuten, Yahoo! Shopping, and Mercari.

== Description ==

affilun is a WordPress plugin for managing affiliate product links used by Japanese websites. It stores products from Amazon Associates, Rakuten Ichiba, Yahoo! Shopping, Mercari, and other configured routes, then displays them as reusable product cards in posts.

The local plugin features do not require a license key, trial, paid plan, or usage quota. Product storage, product cards, provider settings, and basic affiliate-link generation run within WordPress.

You can optionally connect affilun Cloud for managed AI assistance, article drafting, link-health checks, campaign suggestions, affiliate-product suggestions, and plan information. These optional features are external SaaS services processed by affilun Cloud.

= Main features =

* Store and manage affiliate product records in WordPress.
* Display product cards with a Gutenberg block or shortcode.
* Configure Amazon, Rakuten Ichiba, Yahoo! Shopping, Mercari, and ASP routing templates.
* Generate a standard Amazon product-detail URL with the configured Partner Tag when an ASIN is stored.
* Fetch discounted Amazon physical products daily and display priority brands before selected categories with a configurable shortcode.
* Store button labels, display templates, link attributes, and provider display settings in WordPress.
* Use optional Cloud features only when an affilun Cloud API key and eligible plan are configured.

= affilun Cloud boundary =

The plugin distributed through WordPress.org is a GPL-licensed WordPress plugin. Local product management, product-card rendering, saved settings, and basic link generation run within WordPress.

affilun Cloud is an optional external SaaS. Cloud features may include paid plans, usage limits, plan checks, Stripe Checkout, Cloud API-key issuance, AI assistance, article drafting, link-health checks, campaign suggestions, and affiliate-product suggestions. Local plugin features remain available without affilun Cloud.

The affilun Cloud server implementation, billing system, hosted processing, and external API relay services are not included in this plugin package. See https://affilun.st/ for Cloud terms, pricing, data retention, and deletion information.

== Installation ==

1. Install affilun from the WordPress Plugins screen, or upload it to `/wp-content/plugins/affilun/`.
2. Activate affilun in WordPress.
3. Open the affilun settings screen.
4. Configure only the affiliate providers and optional services you intend to use.
5. Add an affilun product-card block in the block editor and select a saved product.

== Frequently Asked Questions ==

= Is WooCommerce required? =

No. affilun manages affiliate product links and does not require WooCommerce.

= Is affilun Cloud required? =

No. Product management, product cards, provider settings, and basic link generation run locally in WordPress. Configure affilun Cloud only if you want its optional managed features.

= Is post or product content sent to an AI service? =

Only when affilun Cloud is configured and you explicitly run a Cloud AI feature. The plugin then sends the excerpts or product context needed for the selected operation to affilun Cloud AI endpoints. It does not send post content to those endpoints when Cloud AI features are not configured or used.

AI output is a suggestion. Before publishing, the site operator must review accuracy, affiliate-program rules, and applicable disclosure requirements.

= Can I use Amazon links without Amazon API eligibility? =

Yes. When an Amazon ASIN is already stored, affilun can generate a standard product-detail URL containing the configured Partner Tag. Amazon API eligibility is required for product search and detailed product-data retrieval.

= Does affilun track visitors? =

affilun may store local click events and daily aggregates for saved product cards in the WordPress database. These records are for the site's own administration and reporting.

Local click records may include the provider, button key, target URL hash, product ID, post ID, display variant, user-agent hash, referring host, and timestamp. affilun does not send this local click data to affilun Cloud or an external analytics service.

Product cards may load saved image URLs from external provider or CDN domains. The visitor's browser may therefore send its IP address, user agent, referrer, and other request information to that external service.

= Where are documentation and support available? =

Documentation, support information, terms, and privacy information are available at https://affilun.st/.

== External Services ==

affilun communicates with an external service only when the related feature is configured and used. Review each provider's terms, privacy policy, and affiliate-program rules before enabling it.

= Amazon Creators API / Amazon Associates =

Purpose: Amazon product search, product-data retrieval, daily brand- and category-based discount discovery, and Partner Tag link generation.

Data sent when enabled: search terms and priority-brand filters when applicable, ASINs, discount categories and thresholds, marketplace, Creators API credentials, and Partner Tag.

Terms: https://affiliate-program.amazon.com/help/operating/agreement

Privacy: https://www.amazon.com/gp/help/customer/display.html?nodeId=468496

= Rakuten Ichiba API =

Purpose: Rakuten Ichiba product search, product-data retrieval, and affiliate-link generation.

Data sent when enabled: search terms, item IDs, Application ID, Access Key, Affiliate ID, and the WordPress site's Origin. The Access Key is sent in an HTTP header rather than the URL.

Terms: https://webservice.rakuten.co.jp/guide/rule

Privacy: https://privacy.rakuten.co.jp/

= Yahoo! Shopping API and ValueCommerce routing =

Purpose: Yahoo! Shopping product search, product-data retrieval, and link generation.

Data sent when enabled: search terms, item IDs, Client ID, and related Yahoo! Shopping settings. If a ValueCommerce free-text-link HTML snippet is configured, affilun extracts and stores only the `sid` and `pid` values needed for link generation.

Yahoo! JAPAN Developer Network guidelines: https://developer.yahoo.co.jp/guideline/

LY Corporation terms: https://www.lycorp.co.jp/en/company/terms/

LY Corporation privacy policy: https://www.lycorp.co.jp/en/company/privacypolicy/

ValueCommerce terms: https://www.valuecommerce.ne.jp/st_affiliate/terms.html

ValueCommerce privacy policy: https://www.valuecommerce.co.jp/privacy_policy/

= Mercari =

Purpose: Generate Mercari search or product links containing a configured Mercari Ambassador `afid`.

Data sent when enabled: search terms, Mercari URLs, and `afid`.

Visitor browser requests: when a saved Mercari product has no main image URL, a product card may load a Mercari Ambassador image from `ambassador-system.mercari.com`.

Terms: https://static.jp.mercari.com/tos

Privacy: https://static.jp.mercari.com/privacy

= affilun Cloud =

Purpose: optional managed AI assistance, product-keyword normalization, article drafting, campaign suggestions, revenue-opportunity suggestions, affiliate-product suggestions, Amazon category discount listings, link-health checks, plan checks, Cloud API-key validation, and usage reporting.

Service endpoint: affilun Cloud uses `https://api.affilun.st/api/v1`. Legacy saved endpoints at `https://cbl.rio.st` are normalized to the production affilun Cloud endpoint.

Data sent when configured and used: site URL, site name, administrator email address, Cloud API key, plan context, enabled provider keys, selected Amazon category, post excerpts or content needed for the selected operation, product-link metadata, review-source URLs, and link-health inputs.

The Free state is for connection checks. Managed Cloud features may require a paid plan or Stripe trial because processing occurs on affilun Cloud servers.

Terms: https://affilun.st/cloud-subscription-terms/

Privacy: https://affilun.st/privacy/

= Stripe Checkout =

Purpose: payment flow for affilun Cloud plans.

Data sent when an administrator starts checkout: email address, site information, selected plan, and checkout-session information.

Terms: https://stripe.com/legal/ssa

Privacy: https://stripe.com/privacy

= External product images =

Product cards and administration previews may display product-image URLs saved in WordPress. These URLs may point to provider, marketplace, affiliate-network, or CDN domains. When a page containing an external image is viewed, the visitor's browser sends a request to that domain, which may receive the visitor's IP address, user agent, referrer, and other request information.

= Data stored in WordPress =

affilun may store:

* Provider settings, including Amazon credentials and Partner Tag, Rakuten credentials, Yahoo! credentials, Mercari `afid`, and enabled states.
* Product records, including title, provider item ID, ASIN, price, availability, image URL, product URL, affiliate URL, synchronization state, and timestamps.
* Daily Amazon discount snapshots stored separately from manually managed affiliate products.
* Priority-brand names configured for Amazon discount synchronization and shortcode display.
* Display settings, including templates, button labels, link attributes, and display options.
* ASP routing settings and URL templates.
* affilun Cloud settings, including Cloud API key, site ID, endpoint, selected plan, and connection state.
* Operational data, including logs, sync jobs, audit events, link-health results, opportunity states, cached affiliate suggestions, local click events, and daily click/view aggregates.

API keys and affiliate identifiers are stored in the WordPress database and managed by administrators. They are not rendered on public pages.

== ASP Routing ==

Yahoo! Shopping affiliate tracking is configured with a Yahoo Developer Client ID and a ValueCommerce free-text-link HTML snippet. affilun extracts and stores only the `sid` and `pid` values needed for link generation.

Advanced routing templates can also be configured for custom ASPs or migrations. Templates may use placeholders such as `{url}`, `{encoded_url}`, `{provider}`, and `{product_id}`.

When routing is enabled, a product-button URL may be transformed into the configured intermediary ASP URL. The site operator is responsible for confirming that each template complies with the relevant ASP rules and tracking requirements.

== Uninstall ==

Deleting the plugin through WordPress runs `uninstall.php`.

The current uninstall policy removes secrets and operational options, including provider credentials, the affilun Cloud API key and connection settings, local click aggregate options, cron cursors, worker IDs, and scheduled affilun cron hooks.

Custom tables containing products, logs, audits, synchronization data, link-health data, analytics, and click aggregates are retained unless an explicit data-removal option is introduced in a future release. Back up required data before deleting the plugin.

== Changelog ==

= 0.9.3 =

* Added priority-brand discount discovery using Amazon Creators API brand filters.
* Added a priority-brand field to the Amazon discount shortcode configurator.
* Displayed brand discount groups before category discount groups.

= 0.9.2 =

* Increased Amazon discount discovery from 30 to 100 products per category while retaining the 20% minimum saving threshold.

= 0.9.1 =

* Added a permission- and nonce-protected button for manually starting Amazon discount synchronization in the background.
* Displayed the latest Amazon discount retrieval timestamp in JST.

= 0.9.0 =

* Moved Amazon discount discovery into the WordPress plugin so each site calls Creators API with its own credentials.
* Added daily category-based discount synchronization into a dedicated local table.
* Added `[affilun_amazon_discounts]` with category, sort-order, and per-category count settings.
* Added a shortcode configurator and canonical product-card preview below the affiliate product list.
* Removed the affilun Cloud Amazon discount listing.

= 0.8.2 =

* Accepted long Amazon product URLs containing localized product names and tracking parameters.
* Extracted the ASIN from pasted Amazon product URLs for link-only fallback when Creators API catalog access is unavailable.

= 0.8.1 =

* Added the WordPress site's Origin header to Rakuten API requests so it can be checked against the Rakuten application's allowed websites.
* Added guidance for configuring the Rakuten application's allowed websites.

= 0.8.0 =

* Migrated Rakuten Ichiba search to the current IchibaItem Search API 20260701.
* Added the required Access Key setting and HTTP-header authentication.
* Preserved legacy Rakuten settings while treating the provider as incomplete until an Access Key is entered.
* Added current Rakuten error-envelope handling and prevented credential failures from marking individual products as broken.

= 0.7.9 =

* Added per-post diagnostics for queued Cloud AI scan failures.
* Updated the WordPress.org listing and bundled readme.

= 0.7.8 =

* Moved bulk Cloud AI post scans to WP-Cron background processing.

= 0.7.7 =

* Updated post-usage search SQL to use an identifier placeholder for the posts table.

= 0.7.5 =

* Prevented Mercari search during Cloud AI scans and stopped synthetic search-link results from being saved automatically.

= 0.7.4 =

* Prevented site link-color customization from overriding product-card button text colors.

= 0.7.3 =

* Preserved selected post IDs after request sanitization in bulk Cloud AI scans.
* Added selected, scanned, skipped, and empty-selection counts to scan notices.

= 0.7.2 =

* Restored affilun administrator capabilities on admin load when activation processing was skipped during a manual update.

= 0.7.1 =

* Strengthened administration POST handlers, output escaping, SQL review coverage, and REST permission callbacks.

= 0.7.0 =

* Removed experimental locally gated features from the WordPress.org package.
* Moved remaining administration JavaScript to the WordPress enqueue API.
* Standardized WordPress identifiers on the `affilun` prefix.
* Clarified that local features work without affilun Cloud.

= 0.6.4 =

* Added Cloud-assisted affiliate-scan evaluation and provider candidate ranking.

= 0.6.3 =

* Added Cloud Tools AI scans for posts without affiliate links and improved migration preview and rewrite workflows.

= 0.6.2 =

* Added import guidance for affiliate links detected in existing content and clarified CSV compatibility.

= 0.6.1 =

* Changed Cloud link-health checks to automatic daily batches and simplified product administration.

= 0.6.0 =

* Added optional affilun Cloud affiliate-product suggestions and local suggestion caching.

= 0.5.6 =

* Updated WordPress.org metadata, compatibility information, and external-service disclosures.

= 0.5.5 =

* Improved Cloud opportunity workflows, link-health persistence, plan displays, and administration security.

= 0.5.4 =

* Improved Cloud connections, provider settings, product workflows, packaging, and verification.

= 0.5.3 =

* Added the initial product-card, provider, and release-candidate packaging features.

== Upgrade Notice ==

= 0.9.3 =

Configure up to 10 priority brands, refresh the shortcode preview, then run Amazon discount synchronization to populate brand groups.

= 0.9.2 =

Amazon discount synchronization now checks up to 100 products per category and may take around five minutes to complete in the background.

= 0.9.1 =

Amazon discount data can now be refreshed manually from the shortcode configurator. The retrieval runs in the background.

= 0.9.0 =

Amazon discount discovery now uses the site's configured Creators API credentials and stores daily snapshots locally. Review the shortcode preview on the affiliate product management screen before publishing it.

= 0.8.2 =

Amazon product URLs can now be pasted directly into product search even when they contain long localized names and tracking parameters.

= 0.8.1 =

Register the WordPress site URL in the Rakuten application's allowed websites. Version 0.8.1 sends that site URL as the Origin header.

= 0.8.0 =

To use Rakuten Ichiba, register a current Rakuten Web Service application and enter its Application ID and Access Key in affilun. The existing Affiliate ID is preserved, but Rakuten search and synchronization remain disabled until the Access Key is configured.
