# 9. `wp jikji` command reference

`wp jikji` is a thin WP-CLI front to the same services the REST API uses: the same validation, permissions and error codes. `wp help jikji <command>` has every argument and example.

## 9.1 Common contract

| | |
|---|---|
| Who runs it | Without `--user`, the administrator with the lowest ID who has `jikji_compile` (shown as `Running as …` and `runAs` in JSON, and recorded as the revision author). `--user=<login>` narrows the rights; `jikji_no_admin` when no such administrator exists |
| Input | `--html` and `--styles` take a file path or `-` (stdin); one stdin argument per command. Style files are the REST format `[{name, type, css, baseCss?}]` |
| JSON output | `--format=json` prints **one JSON object** on stdout, success or failure. A single result is `{…, runAs}`, a list `{items, count, runAs}`, a failure `{code, message, data}` (`data.runAs` included) |
| Exit codes | 0 on success, **1 on every failure**. Branch on `code` (`message` may be in the site language) |
| One value | `--field=<name>` prints only that value — `content get <id> --field=html > page.html`; with `--format=json` the value's JSON |
| Placeholders | `--placeholders` replaces `id="{name}"` (`[a-z][a-z0-9_]*`), the reference attributes `for`, `aria-labelledby`, `aria-describedby`, `aria-controls`, `href="#{name}"` and style rows' `name: "{name}"` with server IDs — the same name gets the same ID; the mapping comes back as `placeholders`. `{…}` inside expressions, JSON and CSS is left alone |
| Locking | A save locks on the document version at the start of the command; another save in between fails with `jikji_conflict`. When a person may have the document open in the builder, pass `content get --field=hash` as `--base-hash` |
| Site-wide changes | Publishing, unpublishing or releasing a hierarchy template or a theme part, saving or restoring such a document while it is published, and `recompile --all` ask for confirmation. Outside a terminal (scripts, agents, stdin input) they fail with `jikji_confirmation_required` unless `--yes` is given — nothing is skipped silently |
| Shell quoting | Keep `$post` in single quotes (`'jikji_post("title", $post)'`) or escape it in double quotes (`\$post`); write HTML in a quoted heredoc (`<<'HTML'`) |

## 9.2 Documents

| Command | Does |
|---|---|
| `wp jikji content get <id> [--field=<field>] [--classes=used\|all\|none] [--format=table\|yaml\|json]` | The source `html`, the version `hash`, `postStatus`, `compileError`, `idStyles`, `classStyles` (by default only the classes the document uses) |
| `wp jikji content save <id> --html=<file\|-> [--styles=<file\|->] [--placeholders] [--base-hash=<hash>] [--update-classes] [--strict-css] [--dry-run] [--yes] [--format=json]` | Save; compiles when the document is published. Result `{hash, compiled, warnings, cssDropped, revision, placeholders?}`. An existing class sent without `baseCss` is refused (`jikji_class_exists`) unless `--update-classes` |
| `wp jikji content validate --html=<file\|-> [--styles=<file>] [--placeholders] [--strict-css] [--format=json]` | The save's checks without writing: structure, SVG sanitizing, PHP syntax of the compiled result, style names and type conflicts, CSS that would be dropped (`cssDropped`), block-island warnings (`blockWarnings`) |
| `wp jikji content import <id> [--dry-run] [--save] [--yes] [--format=json]` | Convert the post's **block content** to a Jikji document ([Blocks 3.7](03-blocks.md#37-wordpress-blocks-block-islands)). Reports by default; `--save` stores it (a published post asks). `post_content` is unchanged |
| `wp jikji blocks list [--search=<s>] [--attrs-only=yes\|no\|unknown] [--fields=…] [--format=…]` | Registered Gutenberg blocks — name, title, category, `dynamic`, `attrsOnly`, attribute names |
| `wp jikji ids [--count=<n>] [--format=list\|json]` | Unused element IDs (1–50) |
| `wp jikji styles list [--type=class\|id] [--post=<id>] [--fields=…] [--format=…]` | Global class styles, or `--type=id --post=<id>` for a document's ID styles |
| `wp jikji status <id> [--field=…] [--format=json]` | Kind (`post`, `template`, `template-part`, `pattern`), publish state, URL, `compileError`, `runtimeError`, live version, `siteWide`, `previewUrl` |
| `wp jikji eval <id> [<expr>] [--mode=text\|html\|attr\|each\|if] [--attr=<name>] [--scope=<json>] [--items=<json\|file>] [--format=json]` | Evaluate expressions in the document's context ([Dynamic data 5.10](05-dynamic-data.md#510-checking-expressions-before-publishing)) |
| `wp jikji revisions list <id>` · `wp jikji revisions restore <id> <rev> [--base-hash=…] [--yes]` | The revision list; restore (a new save) |
| `wp jikji recompile [<id>…] [--all --yes] [--format=json]` | Regenerate compiled output and report per document; `--all` needs `manage_options` |

## 9.3 Templates, parts and patterns (block theme)

| Command | Does |
|---|---|
| `wp jikji templates list [--type=template\|part] [--managed] [--fields=…] [--format=…]` | The active theme's templates and parts with Jikji state, `source` (`theme` file or `custom` post; `wpId` 0 means no post yet), `siteWide`, `themeFileChanged` |
| `wp jikji template adopt <slug\|theme//slug> [--part] [--import]` | Start managing a theme template or part (idempotent). A theme file becomes a customized post with its blocks as the fallback; the Jikji copy is a **draft** with a starting skeleton, or with `--import` the current blocks converted |
| `wp jikji template prepare <slug> [--from=<slug>] [--title=<t>] [--dry-run] [--yes]` | Create a hierarchy template the theme lacks (`single-case`, `archive-video`, `404`…) from the blocks of the template those requests use now, then adopt it; adopt only if it exists ([Templates 6.5](06-templates.md#65-which-template-to-use)) |
| `wp jikji template create <slug> --title=<t> [--assign=<ids>]` | A custom (page) template: create, manage, assign to posts. Hierarchy names are refused (`jikji_hierarchy_slug`) |
| `wp jikji template assign <template> <post-id>…` | Assign a custom template to posts (idempotent) |
| `wp jikji part create --title=<t> [--slug=<s>] [--area=header\|footer\|uncategorized]` | A new template part; the slug is suggested from the title (`-2`, `-3` on collision) |
| `wp jikji template publish\|unpublish\|release <template> [--part] [--yes]` | Publish the Jikji version (only when it compiles), unpublish (back to the blocks), release (Jikji data removed, the post and its blocks stay) — also for patterns by post ID |
| `wp jikji template sample <template> [--vars=<json>]` | Read or set the sample query used for editing and evaluation |
| `wp jikji pattern list [--managed]` | The site's patterns (`wp_block`) with their sync flag and Jikji state |
| `wp jikji pattern adopt <id> [--skeleton]` | Start managing a synced pattern (idempotent); by default from its blocks, `--skeleton` for an empty start. Publish and release with `template publish\|unpublish\|release <id>` |

`<template>` is a post ID, `<theme>//<slug>`, or a slug of the active theme; patterns are addressed by post ID only.

## 9.4 Summary

```text
wp jikji content get|save|validate      wp jikji templates list
wp jikji content import                 wp jikji template create|adopt|assign
wp jikji ids                            wp jikji template publish|unpublish|release
wp jikji styles list                    wp jikji template prepare|sample
wp jikji eval                           wp jikji part create
wp jikji status                         wp jikji pattern list|adopt
wp jikji revisions list|restore         wp jikji recompile
                                        wp jikji blocks list
```

Error codes and what to do about them: [Troubleshooting](12-troubleshooting.md).
