WordPress / WordPress/create-block-theme

Refactor: Extract CBT_Theme_Export service from rest_export_theme

Open
#831 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement wp-cli
Dominant language
JavaScript
Stars
417
Forks
66
PR merge metrics
No merged PRs in 30d

Description

Part of #828 (which fulfills #688).

Goal

Same shape as the CBT_Theme_Save extraction, applied to the export flow. Move the orchestration out of rest_export_theme() into a new service class so it can be invoked from REST or CLI without duplication.

Scope

New file: includes/create-theme/theme-export.php

New class: CBT_Theme_Export with one public static method:

public static function to_zip( string $output_path, array $options ): true|WP_Error;

The current REST handler streams the zip back as the HTTP response body. The service writes to a path on disk; the REST wrapper writes to a temp file, streams it, then cleans up. This keeps both REST and CLI consumers symmetric.

REST endpoint update: rest_export_theme() becomes a thin wrapper. URL, permissions, and response semantics do not change.

Tests (PHPUnit, in this PR)

  • Each export option (include images, export-ready, translate-ready) produces the expected zip contents
  • Output path is honored
  • Permission errors / disk failures propagate as WP_Error
  • Test fixtures: a small block theme to round-trip

Out of scope

  • Any CLI work — separate issue tracked in #828
  • Format options other than zip
  • Changing the REST endpoint's semantics for existing callers

Acceptance

  • Existing REST export behavior is byte-for-byte preserved (compare zip output before/after)
  • lint:php, test:php, test:unit all green

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with rest_export_theme() and the CBT_Theme_Save extraction, then add the service in includes/create-theme/theme-export.php. Use the stated PHPUnit tests and small block-theme fixture to check each export option, output paths, and WP_Error failures. Done means REST output remains byte-for-byte compatible and lint:php, test:php, and test:unit pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
api, backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.