=== Init Manga Migrator ===
Contributors: brokensmile.2103
Tags: manga, import, export, migration, chapters
Requires at least: 5.5
Tested up to: 6.8
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 tool for Init Manga. Export/import manga, chapters, meta, taxonomies, and covers cleanly via JSON.

== Description ==

**Init Manga Migrator** helps you move manga content between WordPress sites using the **Init Manga** theme. It’s built for practical, safe data transfer:
- Export specific manga or the entire library as clean JSON.
- Include **core meta**, **taxonomies**, **featured image**, and **chapters**.
- Import back into another site — automatically updates existing manga by slug or creates new ones.
- Fully respects the Init Manga theme’s schema and meta structure.

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

== Features ==

- **Export Selected** manga with one click
- **Export All** manga (with chapters, meta, and taxonomies)
- **Import** from `.json` file or paste JSON manually
- **Chapter support:** title, number, slug, content, lock type/value
- **Core meta only:** type, status, age rating, alt title, webtoon/oneshot flags, cover blur, and optional sidebar info (illustrator, designer, country, schedule)
- **Taxonomies:** genre, author, and team (auto-detected)
- **Featured image import/export:** preserves alt text, caption, and avoids duplicate downloads
- **Update-safe:** imports match by slug, skipping duplicate chapters
- **Optional cleanup tools:** remove duplicates and orphaned data safely
- **Developer filters:** allow content sanitization and batch tuning for large-scale imports

== 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 → Migrator** to start exporting or importing.

== Frequently Asked Questions ==

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

= What gets exported? =
- **Manga (CPT `manga`)**: title, slug, content, and key meta fields.
- **Chapters**: title, number, slug, content, lock type/value.
- **Taxonomies**: genre, author, and team (if present).
- **Featured image**: full URL, alt, caption (import will auto-restore it).

= What gets imported? =
- Manga are matched by **slug**.
  - If the slug exists → the post is **updated** (meta, taxonomies, featured, etc.).
  - If the slug doesn’t exist → a **new manga** is created (published automatically).
- Chapters are matched by `(manga_id, chapter_slug)`.
  - If the slug exists → it’s **skipped**.
  - If missing → it’s **created** and linked to the manga.

= Why does import sometimes show “updated” but nothing appears? =
WordPress can store hidden auto-drafts with matching slugs. Init Manga Migrator automatically restores or recreates these posts so imported manga always appear correctly.

= What is intentionally excluded? =
Comments, analytics, reading logs, timestamps, or other sensitive datasets.

= Does it include cover images? =
Yes. Featured images are downloaded and re-attached automatically, with alt and caption preserved.

= Can I reset all chapters before import? =
Yes. Use the built-in admin buttons in the **Cleanup tools** section to safely remove duplicates or orphan chapters.

= Can I export XML instead? =
No. JSON is safer and purpose-built for Init Manga’s schema.

== Usage ==

1. Go to **Init Manga → Migrator**.
2. **Export**
   - Select manga → click **Export Selected**, or
   - Click **Export All** for a full export.
3. **Import**
   - Upload a `.json` file or paste JSON directly → click **Import Now**.
4. Review the summary: created, updated, skipped, chapters created/skipped, and any errors.

== Permissions & Security ==

- Only administrators (`manage_options`) can access the Migrator page.
- Requires Init Manga theme to be active and licensed.
- All requests use WordPress nonces for protection.
- Imports are idempotent: safe to repeat without duplication.

== Developer Notes ==

**Available filters:**

1. `init_manga_migrator_export_chapter_content` — modify chapter content before exporting (provides `$content`, `$manga_id`, `$row`).
2. `init_manga_migrator_cleanup_dupe_manga_batch` — adjust batch size for duplicate manga cleanup (default `300`).
3. `init_manga_migrator_cleanup_orphan_chapters_batch` — adjust batch size for orphan chapter cleanup (default `500`).

== Changelog ==

= 1.0 – October 5, 2025 =
- Initial release
- Export selected or all manga to JSON
- Import from JSON with slug-based update logic
- Include chapters, meta, taxonomies, and featured images
- Added cleanup utilities for duplicates and orphan chapters
- Added pagination for large manga libraries
- Added developer filters for extensibility
- Added full i18n (translatable)
