# Content Ownership

> Decide whether code or editors own a page, adopt existing WordPress content, and handle content removed from code.

# Content Ownership

Every page, post, and template your project defines has an owner: the code, or the site's editors. This page explains how to hand content over to editors, give it back to code, bring existing WordPress pages under code, and what happens to content you remove from code.

These features need Devkit 1.1.0 with etch-builders 2.1.1 in the project. A project created with Devkit 1.0.x gets them after the [migration](/oh-my-idetch/localwp-devkit/install-and-prepare#update-existing-projects).

## Code-Owned Content (the Default)

Every sync, and every live-site deploy, writes the code version of code-owned content. Edits made in wp-admin or the Etch editor are replaced, and WordPress keeps the replaced version as a revision.

The older `overwrite()` call has no effect and is deprecated. Leave it out of new code.

## Hand Content Over to Editors

Mark a page, post, or template with `hand_over_after_create()` when editors should own it after it exists:

```php
return Page::new()
	->slug( 'about' )
	->title( 'About' )
	->block( $blocks )
	->hand_over_after_create();
```

- The first sync creates it. Later syncs and deploys leave its content alone and report it as unchanged, so editor changes stay.
- Code changes to that content are no longer applied. Its class styles and stylesheets stay managed by code.
- `localwp:verify` reports it with status `handed_over` and does not compare its content.
- If an editor renames, trashes, or deletes it, sync reports `ETCH_SITE_PERSISTENCE_HANDED_OVER_MISSING` and does not create it again. Verify reports `handed_over_missing`.

On a live site, mark content `hand_over_after_create()` before you deploy it. Code wins on every deploy for content that is not handed over.

## Give Content Back to Code

Replace `hand_over_after_create()` with `reclaim_from_editors()`. The next sync writes the code version (`ETCH_SITE_PERSISTENCE_RECLAIMED`, with the editor version kept as a revision), or creates the page again if it is gone. After that sync, remove `reclaim_from_editors()`: the page is plain code-owned content again.

Removing `hand_over_after_create()` alone never overwrites an editor's work or brings back a page they deleted. Sync stops with `ETCH_SITE_PERSISTENCE_HANDED_OVER_RECLAIM_REQUIRED` and writes nothing, and verify reports `OMIDE_RUNTIME_HANDED_OVER_RECLAIM_REQUIRED`. Choose one:

- add `reclaim_from_editors()` so the code version wins;
- restore the page in WordPress;
- keep `hand_over_after_create()`.

On a live site the same conflict fails the registration until you fix it. See [Ship a Plugin ZIP](/oh-my-idetch/localwp-devkit/ship-plugin-zip#content-ownership-on-a-live-site).

## Adopt Existing Content

A project page, post, or template whose slug or ID matches content created in wp-admin stops the sync with `ETCH_SITE_PERSISTENCE_CONFLICT`. So do pages that a project created before Devkit 1.0 registered through its older registration path. `localwp:doctor` lists these collisions before the first sync.

Add `adopt_existing()` to take that content over on the next sync:

```php
return Page::new()
	->slug( 'contact' )
	->title( 'Contact' )
	->block( $blocks )
	->adopt_existing();
```

- Sync reports `ETCH_SITE_PERSISTENCE_ADOPTED`. The page keeps its post ID and address.
- Its previous content is saved as a revision, and the code version replaces it.
- With `hand_over_after_create()` as well, the content stays as it is and only the owner changes.

Adoption refuses, and changes nothing, when several pages match (`ETCH_SITE_PERSISTENCE_ADOPTION_AMBIGUOUS`), when the match is a translation (`ETCH_SITE_PERSISTENCE_ADOPTION_TRANSLATION`), or when the post type keeps no revisions and the content differs from the code version (`ETCH_SITE_PERSISTENCE_ADOPTION_NO_REVISIONS`).

Take a Local site export before the first sync that adopts content. On a live site, back up the database before you upload a ZIP that adopts content.

## Content Removed From Code

When you remove a code-owned page or post from the project, it stays online and keeps its styles. Sync and verify list it as a notice instead of leaving it behind silently:

```text
- [warning] ETCH_SITE_PERSISTENCE_ORPHAN page:slug:old-offer: ...
```

Verify still passes. Then decide:

- **Put it back in code.** The next sync manages it again.
- **Retire it on LocalWP.** Move it to draft with sync:

  ```sh
  bun run localwp:sync -- --project <slug> --retire-orphans
  ```

  The bare flag retires every listed orphan. To retire only some, name them separated by commas:

  ```sh
  bun run localwp:sync -- --project <slug> --retire-orphans page:slug:old-offer,post:post:launch-news
  ```

  Sync applies the site first, then prints the selection, what moved to draft, and what was kept and why.
- **Delete it** in wp-admin.

Drafts keep their ID, slug, revisions, and settings. If the content returns to code, the next sync restores its previous status.

### What Retirement Never Drafts

Retirement only ever drafts pages and posts. It keeps, and reports, the front page, the posts page, the privacy policy page, WooCommerce shop pages, parents of published pages, handed-over content, translations, components, patterns, and templates.

### When Retirement Is Refused

- If one of the names you pass is not content removed from code, the whole selection is refused with `OMIDE_SITE_ORPHAN_SELECTION_NOT_ORPHAN` and nothing is retired. The message lists the orphans on the site.
- Separate names with commas, not spaces. Names separated by spaces are refused with a clear message.
- `ETCH_SITE_PERSISTENCE_ORPHANS_PLAN_NOT_APPLIED` or `ETCH_SITE_PERSISTENCE_ORPHANS_PLAN_STALE` means the site no longer matches the last complete sync, for example because an apply failed. Nothing was retired. Fix any failure the sync printed, then run the same `--retire-orphans` sync again.

`--retire-orphans` changes only the LocalWP site. A live site has no retire command: move such pages to draft in wp-admin after the deploy.

## Multilingual Sites (WPML)

The project plugin ships `wpml-config.xml`, which tells WPML not to copy the Builder's ownership details to translations. Translations stay content the site owns, and the Builder never writes to a translation. Code-owned content is single-language.

The WPML configuration has not been tested on a live WPML site yet. After the first deploy to a WPML site, check that the registration is current and that translated pages still show their own content.
