=== Init Manga Clone ===
Contributors: brokensmile.2103
Tags: manga, clone, duplicate, chapters, admin
Requires at least: 5.5
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Adds a one-click "Clone" action to duplicate a Manga story together with all of its chapters.

== Description ==

**Init Manga Clone** is a single-purpose plugin: it adds a **Clone** row action to the Manga list screen (`edit.php?post_type=manga`) so you can instantly duplicate a story — including every chapter — without leaving the admin list.

There is no settings page and no configuration. Install it, activate it, and a **Clone** link appears under each story's title on the Manga list screen.

> **Init Manga theme required** — This plugin relies on the `manga` post type and the chapter database table provided by the **Init Manga** theme. The Clone link is hidden automatically if these are not detected.

== Features ==

- **One click, no forms** — a "Clone" row action next to Edit / Trash / View on the Manga list screen.
- **Full story duplication** — post content, excerpt, author, all whitelisted meta fields (type, status, age rating, alternative title, cover options, original author, illustrator/designer/country, publish schedule, etc.), every taxonomy currently assigned to the story (genre, and author/team/publisher taxonomies if your site has them enabled), and the featured image.
- **Full chapter duplication** — every chapter row is duplicated into a brand-new chapter, each with its own new "ghost" post so permalinks and future comments work independently from the original.
- **Smart, ever-increasing numbering** — the clone title becomes `Original Title (Copy 1)`, `(Copy 2)`, `(Copy 3)`... The number always increases, even if you clone a clone, and even if an in-between clone was later deleted.
- **Created as Draft** — the clone is created with `draft` status so nothing goes live until you review it. Overridable with a filter.
- **Nothing you don't want** — view counts, comments, and crowdfunding contributions already received are intentionally never copied (see "What is intentionally excluded" below).
- **Safe by design** — nonce-protected, capability-checked, and it never silently overwrites or deletes existing content.
- **Full i18n support** — English default, Vietnamese translation included.

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/`, or drop the plugin ZIP through **Plugins → Add New → Upload Plugin**.
2. Activate **Init Manga Clone** through **Plugins → Installed Plugins**.
3. Make sure the **Init Manga** theme is active.
4. Go to **Manga** (post list). Hover any story's title and click **Clone**.

No further setup is required — there is no settings page.

== Frequently Asked Questions ==

= Does it require the Init Manga theme? =
Yes. The plugin checks that the `manga` post type and the chapter database table exist before showing the Clone link. If they're missing, the link simply won't appear.

= What exactly gets cloned? =
- **The story (CPT `manga`)**: title (with an auto-incrementing "(Copy N)" suffix), content, excerpt, author, and a whitelisted set of meta fields (`type`, `webtoon_support`, `is_oneshot`, `status`, `age_rating`, `alt_title`, `cover_blur`, `original_author`, `illustrator`, `designer`, `country`, `publish_schedule`, `weekly_publish_day`).
- **Taxonomies**: every taxonomy registered for the `manga` post type (e.g. genre) is copied term-for-term.
- **Featured image**: the clone reuses the exact same image attachment as the source — no file duplication.
- **Chapters**: every chapter row (number, title, slug, content, lock type/value, schedule) is copied into brand-new chapter rows attached to the clone, each with its own new hidden "ghost" post.

= What is intentionally excluded? =
- View counts, reading history, and any other engagement statistics.
- Comments — cloned chapters get a brand-new "ghost" post, so comments on the original never appear on the clone.
- Crowdfunding contributions already received (`crowdfund_raised` is reset to `0`); the crowdfunding *goal* itself is kept.
- Contest entry (`_contest_id`) — a clone is never automatically entered into whatever contest the original was submitted to.

= Why is the clone created as a draft? =
So a duplicate story never appears live on your site by accident. Review it, adjust the title/content if needed, and publish it yourself when ready. Developers can change this with the `init_manga_clone_new_status` filter.

= What happens if I clone a story that is itself a clone? =
The numbering keeps counting from the very first (root) story, so you'll never see the suffix stack up like "(Copy 2) (Copy 2)". Clone a clone and you correctly get the next number in the sequence, e.g. "(Copy 3)".

= Does cloning notify followers of a "new chapter"? =
No. Cloned chapters are inserted directly and never trigger the theme's "new chapter" notification system.

= What if a story has hundreds of chapters? =
Cloning happens synchronously when you click the link, so very large stories may take a little longer to process. The plugin raises the PHP time limit for the request when the server allows it. If a small number of chapters fail to insert (e.g. a database hiccup), the rest of the story still clones successfully and the result notice tells you how many chapters were skipped.

== Permissions & Security ==

- The Clone link only appears for users who can edit the source story **and** create new stories (standard WordPress capability checks for the `manga` post type — typically Author/Editor/Administrator).
- Every clone request is protected by a WordPress nonce, verified before anything is written to the database.
- All output (including notices) is escaped; no raw request data is ever echoed back to the browser.
- No new database tables, no cron jobs, no external requests, no options page — the plugin only reads/writes the story and chapter data the Init Manga theme already defines.

== Developer Notes ==

**Available filters:**

1. `init_manga_clone_meta_keys` — filter the array of post meta keys copied from the source story to the clone.
2. `init_manga_clone_new_status` — filter the post status assigned to the cloned story (default `'draft'`).

**Meta added to a cloned story (for tracking/debugging):**

- `_imc_clone_of` — post ID of the original (root) story.
- `_imc_clone_number` — the sequential clone number used in the title.
- `_imc_cloned_from` — post ID of the story this specific clone was made from (may be another clone).
- `_imc_cloned_at` — timestamp of the clone operation.

== Changelog ==

= 1.0.0 – July 14, 2026 =
- Initial release.
- Clone row action on the Manga list screen.
- Full story + chapter duplication with ever-increasing "(Copy N)" numbering.
- Views, comments, crowdfunding progress, and contest entry intentionally excluded from cloning.
- Full i18n support (English default, Vietnamese translation included).
