=== Init Manga Sync ===
Contributors: brokensmile.2103
Tags: manga, sync, synchronization, rest api, chapters
Requires at least: 5.5
Tested up to: 6.9
Requires PHP: 7.4
Stable tag: 1.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

A lightweight synchronization tool for Init Manga. Keep manga and latest chapters up to date between sites via secure REST API endpoints.

== Description ==

**Init Manga Sync** allows you to continuously synchronize manga data between multiple WordPress sites running the **Init Manga** theme.

Unlike one-time migration tools, this plugin is designed for **incremental syncing**:
- Fetch only new or updated manga.
- Pull the latest chapters without re-importing the entire library.
- Keep your destination site up to date with minimal overhead.

It is ideal for setups such as:
- Main site → mirror site
- Editorial site → public reader site
- Old site → new site during gradual migration

> **Theme/License required** — For security and compatibility, this plugin only runs when the **Init Manga** theme is active and properly licensed.

== Features ==

- **Continuous synchronization** via scheduled cron jobs
- **Manual sync actions** for stories and chapters
- **Two protected REST API endpoints**:
  - Manga list
  - Latest chapters
- **API password protection** to prevent unauthorized access
- **Incremental logic**:
  - Manga matched by slug
  - Chapters skipped if already imported
- **Safe updates**:
  - Existing manga are updated, not duplicated
  - New manga and chapters are created automatically
- **Cron-based syncing** every 15 minutes (configurable by developers)
- **Zero impact when disabled** — no endpoints or cron jobs run if settings are incomplete
- **Built specifically for Init Manga’s schema and meta structure**

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/`, or drop the PHP file directly inside.
2. Activate the plugin through **Plugins → Installed Plugins**.
3. Ensure the **Init Manga** theme is active and licensed.
4. Go to **Init Manga → Sync** to configure endpoints and credentials.

== Frequently Asked Questions ==

= Does it require the Init Manga theme? =
Yes. The plugin only runs when the **Init Manga** theme is active and properly licensed.

= What does it sync? =
- **Manga (CPT `manga`)**: title, slug, content, core meta, taxonomies, featured image.
- **Chapters**: title, number, slug, content, lock type/value.

= How does it avoid duplicates? =
- Manga are matched by **slug**.
- Chapters are matched by **(manga_id, chapter_slug)**.
- Existing items are updated or skipped safely.

= Is this a replacement for Init Manga Migrator? =
No.
- **Migrator** is for one-time export/import or backups.
- **Sync** is for continuous, incremental updates between sites.

They are designed to complement each other.

= Does it sync everything every time? =
No. The plugin is optimized to sync **only new or updated data**, keeping operations lightweight.

= Is it safe to run repeatedly? =
Yes. Sync operations are idempotent and safe to run on a schedule or manually.

= What is intentionally excluded? =
Comments, analytics, reading logs, user data, and other sensitive or site-specific datasets.

== Usage ==

1. Go to **Init Manga → Sync**.
2. Enter:
   - Stories endpoint URL
   - Chapters endpoint URL
   - API password
3. Save settings.
4. Use:
   - **Sync Stories Now** to fetch new or updated manga
   - **Sync Chapters Now** to fetch the latest chapters
5. Automatic syncing will run every 15 minutes via WP-Cron.

== Permissions & Security ==

- Only administrators (`manage_options`) can access the Sync page.
- Requires Init Manga theme license validation.
- API access is protected by a shared password.
- All admin actions are secured using WordPress nonces.

== Developer Notes ==

**Cron hooks:**
- `init_manga_sync_stories`
- `init_manga_sync_chapters`

**Custom interval:**
- `ims_15min` (15 minutes)

Developers may hook into standard WordPress filters and actions to customize behavior or logging if needed.

== Changelog ==

= 1.0 – January 1, 2026 =
- Initial release
- Continuous manga synchronization via REST API
- Manual sync actions for stories and chapters
- Secure password-protected endpoints
- Incremental update logic (no full re-imports)
- Cron-based automatic syncing
- Full i18n support
