Skip to content

import-page-draft: validate site-name arg, clean up temp files on failure, strip HTML comment headers #232

Description

@jasperf

Three small robustness gaps in import-page-draft, found while importing page drafts on Sep 15, 2026 (asset cache 5.23.1, same code on main @ 41b7d96).

Context: the run failed because of a caller-side mistake. Our own docs gave the usage as <draft> <page-id> [local|production|both] and dropped site-name, so local was read as the site name. The script's documented signature is correct. The points below would have made that mistake fail loudly and cleanly, and cover a related leak.

wp-ops import-page-draft on-call-wordpress-developer-service-page.html 4625 local
...
bash: line 1: cd: /srv/www/local/current: No such file or directory

1. No warning when site-name looks like an environment

wp-cli/content-creation/import-page-draft.sh:54-55

SITE_NAME="${3:-example.com}"
ENVIRONMENT="${4:-local}"

If arg 3 is local, production or both, it is almost certainly an environment passed in the wrong position. The script then builds SERVER_PATH=/srv/www/local/current and only fails later, inside trellis vm shell.

Suggestion: exit early with an error like: site-name "local" looks like an environment — usage: <draft> <page-id> [site-name] [environment] [template]. Optionally also check that $SITE_DIR/the VM actually has /srv/www/$SITE_NAME before copying anything.

2. A failed run leaves temp files behind

:39 has set -e and there is no trap. The cleanup rm -f "$SITE_DIR/$TMP_NAME" at :107 only runs on success. After the failure above, four tmp-import-<id>-<ts>.html files were left in the Bedrock site root, next to web/. The same applies to /tmp/$TMP_NAME locally, and presumably to the scp'd copy under $SERVER_PATH (:115) when a production run fails after upload.

Suggestion: trap 'rm -f "$STRIPPED_FILE" "$SITE_DIR/$TMP_NAME"' EXIT, plus a best-effort remote rm for production runs.

3. Header stripping only handles {{-- --}} lines

:82

grep -v '^{{--' "$DRAFT_FILE" > "$STRIPPED_FILE"

Some drafts also carry blog-post-style HTML comment headers:

<!-- SUGGESTED POST SLUG: /services/fse-block-theme-development/ -->
<!-- SUGGESTED META (max 155 chars): ... -->
<!-- SEO FRAMEWORK FIELDS (set manually in editor — not part of block content below) -->
<!-- NOTE: ... -->

These aren't block delimiters, so they get stored in post_content. They're invisible on the page, but they leak internal SEO notes into the page source and show as a stray classic/freeform block in the editor. This happened on a production page on Sep 15 (6 lines, fixed by hand).

Suggestion: strip non-block header comments too, e.g. grep -vE '^(\{\{--|<!-- (SUGGESTED|SEO FRAMEWORK|NOTE)\b)'. Stripping only leading header lines before the first <!-- wp: would be even safer. Related: multi-line {{-- ... --}} blocks only lose their first line; a block-aware strip would cover that as well.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions