=== Hosuke for Welcart ===
Contributors: kbsrco
Tags: ec, ecommerce, notification, restock, Welcart
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 0.1.32
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Welcart の売切・在庫切れ商品に「再入荷お知らせ通知」ボタンを追加。在庫が戻った瞬間、入荷待ちのお客様へメールを自動配信します。SKU 単位で在庫を監視。

== Description ==

報助 (ほうすけ / Hosuke) は、Welcart e-Commerce 専用の再入荷お知らせプラグインです。株式会社小林車輌が独立して開発した第三者製プラグインであり、Welcart e-Commerce 開発元 (株式会社Welcart) との公式な提携関係はありません。

商品ページを訪れたお客様が SKU 単位の売切・在庫切れを見つけたとき、Welcart 標準の売切ラベルの隣に「再入荷お知らせ通知」ボタンが自動で挿入されます。お客様がメールアドレスを登録して入荷待ちの状態になると、SKU の在庫が 0 から 1 以上に回復した瞬間に通知メールが自動配信されます。売切による離脱を、再購入への導線に変えるプラグインです。

= 主な機能 =

* SKU 単位の入荷待ち通知登録 (単一 SKU 商品・複数 SKU 商品のいずれにも対応)
* Welcart 標準フィルタ `usces_filters_single_sku_zaiko_message` を利用した通知ボタンの自動挿入
* 商品保存時のリアルタイム在庫変動検知
* 15 分周期の WP-Cron バックグラウンドスキャン (管理画面以外での在庫変更も捕捉)
* カスタマイズ可能な 3 種のメールテンプレート (登録確認・再入荷通知・管理者宛失敗アラート)
* 再入荷商品一覧を表示するショートコード `[hosuke_restock_list]` とサイドバーウィジェット
* ゲスト・Welcart 会員両方の登録フロー (会員はメールアドレス自動入力)
* Google reCAPTCHA v3 統合によるスパム対策 (任意)
* 登録エンドポイントの IP 別レート制限
* 送信キューと指数バックオフによる自動リトライ (最大 3 回)
* 期限切れ通知データの自動クリーンアップ
* WordPress Privacy Tools と統合した GDPR / 個人情報保護法対応
* メール内リンクからの 1 クリック解除、Welcart マイページからの解除
* 管理画面からの CSV エクスポート
* WP-CLI コマンド `wp hosuke send-queue`
* REST API エンドポイント: `POST /wp-json/hosuke/v1/send-queue`, `GET /wp-json/hosuke/v1/restock-list`
* 日本語・英語の翻訳ファイル同梱

= 動作要件 =

* WordPress 6.0 以上
* PHP 7.4 以上
* Welcart e-Commerce 2.9 以上

= 開発元について =

報助は [株式会社小林車輌](https://kbsr.co.jp/?utm_source=hosuke&utm_medium=plugin&utm_campaign=readme) が、Welcart / WordPress 向け kbsr プロダクトラインの一環として開発・提供しています。

kbsr プロダクトのその他のラインナップ:

* **番頭 for Welcart** — Welcart 向け Amazon Pay V2 決済ゲートウェイ + 送り状 5 社連携統合プラグイン (有料)
* **文助** — 日本語特化 AI ライティング支援プラグイン (有料)

詳細は [製品一覧](https://kbsr.co.jp/products/?utm_source=hosuke&utm_medium=plugin&utm_campaign=readme) をご覧ください。

= In English =

Hosuke is an independent restock notification plugin designed specifically for Welcart e-Commerce. It is developed by Kobayashi Sharyo Co., Ltd. and is not officially affiliated with Welcart Inc.

When a shopper visits a product page whose SKU is currently sold out, Hosuke inserts a "Notify me when back in stock" button next to the standard Welcart sold-out label. The shopper enters their email address, and once the SKU's stock transitions from 0 back to 1 or more, Hosuke automatically dispatches a notification email so the shopper can return to buy. Turns sold-out moments into recovered sales opportunities.

Key features: SKU-level registration (single/multi-SKU), automatic notify-button injection via the standard Welcart filter `usces_filters_single_sku_zaiko_message`, real-time stock change detection, 15-minute WP-Cron background scan, three customizable email templates (registration confirmation, restock notification, admin alert), `[hosuke_restock_list]` shortcode and sidebar widget, both guest and Welcart-member registration flows (member email auto-fills), Google reCAPTCHA v3 integration, per-IP rate limiting, send queue with exponential-backoff retry (up to 3 attempts), automatic cleanup of expired notifications, GDPR compliance via WordPress Privacy Tools, one-click unsubscribe, CSV export, WP-CLI command `wp hosuke send-queue`, and REST API endpoints. Japanese and English translation files are bundled.

Requirements: WordPress 6.0+, PHP 7.4+, Welcart e-Commerce 2.9+.

Hosuke is developed and maintained by [Kobayashi Sharyo Co., Ltd.](https://kbsr.co.jp/?utm_source=hosuke&utm_medium=plugin&utm_campaign=readme) as part of the kbsr product line.

### Privacy Policy

Hosuke stores the following personal data:

- Email address of subscribers
- Optionally, Welcart member ID (if the subscriber is logged in at registration time)
- Hashed IP address at registration (SHA-256, salted with WP `nonce_salt`)
- User agent string
- Timestamps: registration, notification sent, unsubscription

This data is used solely for the purpose of delivering the requested restock notification.

Data is automatically deleted after the configured retention period (default: 90 days after notification, 365 days for unfulfilled registrations).

WordPress Privacy Tools integration is provided for GDPR-style data export and deletion requests.

### Third-Party Services

Hosuke can optionally integrate with **Google reCAPTCHA v3** for spam protection.

- When enabled, the reCAPTCHA JavaScript library is loaded on product pages that display the notification button.
- The reCAPTCHA token is sent to Google's servers for verification.
- Google's terms and privacy policy apply: https://policies.google.com/privacy

This integration is off by default and must be explicitly enabled in Settings with your own site key and secret.

== Installation ==

1. Upload the `hosuke-welcart` folder to `/wp-content/plugins/`, or install via the Plugins screen in WordPress admin.
2. Activate the plugin through the "Plugins" menu.
3. Confirm that Welcart e-Commerce is active. A warning will appear if it is not.
4. Go to "Hosuke → Settings" in the WordPress admin to configure reCAPTCHA, email templates, and other options.

== Frequently Asked Questions ==

= Is Welcart required? =
Yes. Hosuke is designed to work in conjunction with the Welcart e-Commerce plugin. If Welcart is inactive, a warning is displayed and Hosuke's own hooks are not registered.

= Can I customize where the notify button appears? =
By default, the button is auto-injected next to the Welcart sold-out label via the standard `usces_filters_single_sku_zaiko_message` filter. You can turn auto-injection off in the settings and place the button anywhere via the `hosuke_button_html` filter or other Welcart hooks.

= Will notifications be sent for products that have never been out of stock? =
No. The notify button only appears on SKUs that are currently sold out and do not have "sellable while out of stock" enabled. Even if a shopper somehow registers on an in-stock SKU, the notification only fires at the moment stock transitions from 0 to 1 or more.

= Does it support multi-SKU products? =
Yes. Notifications are managed at the SKU level, not the product level. Each SKU's stock is monitored independently.

= What happens when an email delivery fails? =
Hosuke retries with exponential backoff, up to 3 times (configurable). If the maximum retry count is exceeded, the notification is marked as failed and an alert email is sent to the site administrator.

= Is Hosuke GDPR / Japanese Personal Information Protection Act compliant? =
Yes. Hosuke integrates with the standard WordPress Privacy Tools:

- Shoppers can request an export of their data via "Tools → Export Personal Data"
- Shoppers can request erasure via "Tools → Erase Personal Data"

Both are keyed by email address. Consent capture at registration time is also configurable (enabled by default).

= How do I test email delivery? =
The "Hosuke → Restock Notifications" admin page has a "Test send" section at the bottom that lets you send any template to any address as a preview.

= Emails are not being delivered / go to the spam folder. What should I do? =
Hosuke sends all notifications through the standard WordPress `wp_mail()` function. Whether messages actually reach the inbox depends on your server's mail configuration and the DNS records (SPF/DKIM/DMARC) of your sending domain. Both are outside of Hosuke's control, so Hosuke cannot guarantee or measure deliverability.

Small operations may work fine with the default configuration, but if you are sending to Gmail / Outlook / other strict providers, or dozens of messages per day, some may be flagged as spam or silently discarded on the receiving side.

**Recommended**: install a major SMTP plugin ([WP Mail SMTP](https://wordpress.org/plugins/wp-mail-smtp/) / [FluentSMTP](https://wordpress.org/plugins/fluent-smtp/) / [Post SMTP](https://wordpress.org/plugins/post-smtp/) etc.) and connect it to an authenticated sending service (Amazon SES / SendGrid / Mailgun / Postmark / Google Workspace / Microsoft 365 etc.). SMTP plugins transparently intercept `wp_mail()` calls and re-send via the authenticated route. No changes to Hosuke are required.

Publishing proper SPF / DKIM / DMARC records for your sending domain is also the single biggest factor determining Gmail deliverability.

= Is there a page where members can see their notification history? =
Yes. Logged-in Welcart members can view and manage their notifications at `/?hosuke_my_notifications=1`. Add a link from the Welcart my-page to this URL (or enable auto-injection in the settings).

= Is data preserved when the plugin is deactivated? =
Yes. Deactivating the plugin does not delete data. Data deletion is opt-in: only when "Delete all data on uninstall" is enabled in the settings and the plugin is uninstalled will custom tables and options be removed.

= Where do I get support? =
For questions and bug reports, please use the [WordPress.org support forum](https://wordpress.org/support/plugin/hosuke-welcart/) or the [Kobayashi Sharyo contact form](https://kbsr.co.jp/contact/?src=hosuke).

== Screenshots ==

1. The "Notify me when back in stock" button auto-injected next to the Welcart sold-out label on the product page. Same size and hover behavior as the Welcart "Add to cart" button, but with an outlined design so shoppers can tell at a glance that this is a notification signup, not a purchase.
2. The registration modal — email address input, consent checkbox, single-click submit. The email address auto-fills for logged-in Welcart members.
3. The admin registration list. Supports status filters (registered / queued / sent / unsubscribed / expired / failed), CSV export, and bulk actions.
4. The email template editor: three templates (registration confirmation / restock notification / admin alert), buttons to insert template variables at the cursor position, and a test send form at the bottom.
5. The basic settings tab: button label, reCAPTCHA v3 site key / secret, Welcart my-page auto-injection toggle, and privacy consent settings in one place.

== Changelog ==

= 0.1.32 =
* **Documentation**: Bilingualized `readme.txt` with a Japanese-first `== Description ==` section (English retained under an `= In English =` heading) and rewrote the short description in Japanese. Improves discoverability on WordPress.org for Japanese-speaking Welcart users searching for terms like 再入荷通知 / 入荷お知らせ / 売切 / 在庫切れ / 入荷待ち. No code changes.

= 0.1.31 =
* **Security hardening for legacy Welcart editor observer**: `Stock\ChangeDetector::onAdminInitDetectLegacyEditor()` now requires `edit_posts` before it does anything, verifies the Welcart `_wpnonce` field is present and valid, and additionally checks `edit_post` for the specific post before scheduling a stock recheck at shutdown. The GET-only fallback for reading `post` has been removed, so the observer will only ever react to properly authenticated POST submissions from the Welcart legacy item editor.

= 0.1.30 =
* **Text Domain aligned with plugin slug**: Renamed the plugin's text domain from `hosuke` to `hosuke-welcart` across all 269 i18n calls, the plugin header, the `load_textdomain()` bootstrap, and the language file names.
* **Description translated to English**: The `readme.txt` `== Description ==`, `== Installation ==`, `== Frequently Asked Questions ==`, and `== Screenshots ==` sections have been rewritten in English.
* **Inline scripts converted to `wp_enqueue_script`**: The three inline `<script>` blocks in the admin templates editor and the frontend member-notifications component have been extracted to dedicated files under `assets/js/`.
* **Sanitization hardening**: `Admin\TemplatesPage::handleSave` now passes the decoded email body through `sanitize_textarea_field( wp_check_invalid_utf8( ... ) )` before saving. `Notification\Registrar` now wraps the `HTTP_USER_AGENT` fallback in `sanitize_text_field( wp_unslash( ... ) )`.
* **Cross-promo admin notice scoped**: The `Admin\CrossPromoNotice` in-admin notice now checks `get_current_screen()->id` and only renders on plugin's own screens (Guideline 11).

= 0.1.29 =
* **Japanese-first documentation** and Japanese author name.

= 0.1.28 =
* **Plugin display name**: Switched to `報助 for Welcart`.

= 0.1.27 =
* **Plugin Check warnings — critical fixes**: input sanitization, `load_plugin_textdomain()` cleanup, plugin name consistency.

= 0.1.26 =
* **Plugin Check compliance**: Resolved all 14 errors flagged by the WordPress.org Plugin Check tool.

= 0.1.25 =
* **Meta**: Updated `Contributors:` field to `kbsrco`.

= 0.1.24 =
* **Docs**: Updated `== Screenshots ==` section descriptions.

= 0.1.23 =
* **Plugin URI** to `https://hosuke.kbsr.co.jp/`.
* **Localization**: Status column values now render with Japanese labels.
* **Sender name / email**: Now optional; blank fields inherit from Welcart / WordPress.

= 0.1.22 =
* **Localization fix**: Japanese "invalid unsubscribe link" error message.

= 0.1.21 =
* **My-page table now matches Welcart cart exactly** with cart-style columns.

= 0.1.20 =
* **Fix: my-page notification list rendered without styles**.
* **Heading now matches Welcart 購入履歴**.

= 0.1.19 =
* **Fix**: button label migration on upgrade from v0.1.11-v0.1.17.
* **Fix**: restock email body corrected to match one-notification-per-registration behavior.

= 0.1.18 =
* Default frontend label: `再入荷お知らせ通知`.
* Admin sidebar: `再入荷通知`.
* Email defaults refreshed to a common Japanese e-commerce format.
* My-page notification list redesigned as a Welcart cart-style table.

= 0.1.17 =
* **Fix: Welcart my-page auto-injection now actually works** via `wp_footer` fallback.
* Frontend stylesheet force-enqueued on Welcart my-page.

= 0.1.16 =
* **Welcart my-page integration**: Members see their active restock notifications on the Welcart my-page.

= 0.1.15 =
* About page: Bunsuke card translated to Japanese; primary CTA renamed.
* Unsubscribe page: Fully localized for Japanese; slug renamed to `notify-off`.

= 0.1.14 =
* About page: Renamed section title; reduced product card size.

= 0.1.13 =
* Docs: Added FAQ on email deliverability.
* Metadata: `Tested up to` 7.0.

= 0.1.12 =
* Notify button visual redesign: cart-button sizing, outline pattern, bell icon.

= 0.1.11 =
* UX: Default button label localized on Japanese sites.
* About page: Fixed dead links; added SVG thumbnails.

= 0.1.10 =
* Bug fixes: variable buttons focus tracking; Japanese template defaults on upgrade.

= 0.1.9 =
* Admin UX: variable buttons at cursor; Basic/Advanced tabs; Japanese defaults for locale=ja.

= 0.1.8 =
* Defensive `admin_init` fallback for pending-notification SKUs.
* Diagnostic logging via `error_log`.

= 0.1.7 =
* Redesigned stock change detection to be transport-agnostic via `updated_post_meta`.

= 0.1.6 =
* Corrected AJAX action name (`wp_ajax_item_sku_ajax` at priority 1).

= 0.1.5 =
* Restock detection from Welcart legacy per-SKU update button (AJAX hooks).

= 0.1.4 =
* Upgrade migrations run on plugin file replacement.
* Unconditional mail log entries.

= 0.1.3 =
* Email deliverability: `List-Unsubscribe` / `List-Unsubscribe-Post` / `Auto-Submitted` headers; reworded defaults to reduce spam signals.

= 0.1.2 =
* Dedicated unsubscribe page (`/hosuke-unsubscribe/`).
* Stock changes from Welcart legacy editor detected.
* Deferred SKU meta checks at `shutdown`.
* Registrations list links to Welcart product editor.

= 0.1.1 =
* Restock notifications sent immediately (was up to 5 min).
* WP-Cron self-heal.
* Notify button uses Welcart Basic orange.
* Unsubscribe page redesigned.

= 0.1.0 =
* Initial release.

== Upgrade Notice ==

= 0.1.32 =
Documentation-only release: readme.txt is now bilingual (Japanese primary + English section) to improve discoverability for Japanese Welcart users. No code changes; safe to skip if you don't need Japanese readme.

= 0.1.31 =
Security hardening for the Welcart legacy editor observer. Adds `edit_posts` capability check, `_wpnonce` verification, and per-post `edit_post` check before scheduling stock rechecks.
