CoverKit codebase reference
Developer documentation aligned with the current plugin source. For architecture of use cases and output profiles, start with use-cases-and-output-profiles.md. For site-owner workflows, see the plugin README on GitHub and the user guide.
What the plugin does
Section titled “What the plugin does”CoverKit is a WordPress plugin for designing template-based images in the block editor and rendering them to image files on the server (Imagick). Primary outputs are Open Graph / social preview images and editor sidebar previews, driven by use cases configured per coverkit template.
The codebase splits into:
- PHP —
includes/, bootstrapped bycoverkit.php - Editor —
src/, compiled tobuild/via webpack (npm run build)
Boot sequence
Section titled “Boot sequence”coverkit.phploads autoloaders andincludes/functions.php.CoverKit\init()runs onplugins_loadedpriority1and constructs:SettingsRESTPost_TypeUse_Case_RegistryUse_Case_StoragePost_List_Preview_ColumnsPatternsExamples(unlessCOVERKIT_LOAD_EXAMPLESisfalse)
initpriority15:fire_coverkit_init()runsdo_action( 'coverkit_init' ).coverkit_initpriority5: built-in and third-party code callcoverkit_register_use_case().coverkit_initpriority10:Use_Case_Registry::boot()loadscoverkit_active_use_case_classesand callsUse_Case::maybe_init()on each active class.- Activation runs
Post_Type::activate()andSettings::activate()(starter templates fromassets/templates/when missing).
Primary entry points
Section titled “Primary entry points”| Area | Source | Role |
|---|---|---|
| Bootstrap | coverkit.php | Constants, autoload, init(), activation |
| Template CPT | includes/class-coverkit-post-type.php | coverkit post type, meta, blocks, list preview, cache actions |
| REST | includes/class-coverkit-rest.php | coverkit/v1 routes (images, preview, use cases) |
| Rendering | includes/class-coverkit-renderer.php | generate(), generate_from_content() |
| Generator | includes/class-coverkit-generator.php, includes/generator/ | Imagick canvas pipeline and cache |
| Template parsing | includes/class-coverkit-template.php | Block → canvas/elements; field placeholders and mappings |
| Field pipeline | includes/class-coverkit-field-resolver.php, class-coverkit-field-formatter.php, class-coverkit-mapping-applicator.php | Collect, format, apply use-case mappings |
| Use cases | includes/class-coverkit-use-case.php, class-coverkit-use-case-registry.php, class-coverkit-use-case-storage.php, includes/use-cases/ | Registration, boot, assignments, Open Graph / sidebar |
| Settings | includes/class-coverkit-settings.php, src/settings/ | Settings → CoverKit (coverkit_options, coverkit_presets) |
| Editor | src/editor/, src/blocks/, src/editor/use-cases/ | Gutenberg UI, mapping sidebar, previews |
Data model
Section titled “Data model”coverkit post type
Section titled “coverkit post type”Private UI post type under Media (show_in_menu → upload.php). Supports title, editor, revisions, page-attributes, custom-fields.
Template post meta
Section titled “Template post meta”| Meta key | Type | Purpose |
|---|---|---|
width | integer | Canvas width (default 500) |
height | integer | Canvas height |
background | string | Canvas background color |
gradient | string | Canvas gradient |
_coverkit_use_cases | object | Per–use-case assignments (active, settings, mappings, optional instances) — Use_Case_Storage::META_KEY |
_coverkit_active_use_cases | array | Derived slug list for editor/debug — Use_Case_Storage::SUMMARY_META_KEY |
Options
Section titled “Options”| Option | Purpose |
|---|---|
coverkit_options | Global settings (e.g. default image_format) — schema in schemas/options.php |
coverkit_presets | Dimension presets for new templates — schemas/templates.php |
coverkit_active_use_case_classes | Loader manifest: slug → FQCN for classes to boot — Use_Case_Registry::LOADER_MANIFEST_OPTION |
When _coverkit_use_cases changes, Use_Case_Storage rebuilds coverkit_active_use_case_classes.
Rendering flow (summary)
Section titled “Rendering flow (summary)”- Edit — User designs
coverkit/canvas+coverkit/shapeblocks; use cases and mappings are saved in_coverkit_use_cases. - Generate —
Renderer::generate( $use_case_slug, $template_id, $post_id, $options )builds aTemplate, runsapply_data()(placeholders +apply_use_case_mappings()), thenGenerator::generate(). - Open Graph —
Open_Graph_Image_Use_Case::init()hookswp_headand pointsog:imageatGET /wp-json/coverkit/v1/opengraph/{template_id}/{post_id}.{ext}. - Serve — Cached files are exposed via
/coverkit/v1/canvas/{filename}or use-case/opengraph routes.
Good first files to read
Section titled “Good first files to read”Backend
coverkit.phpincludes/class-coverkit-post-type.phpincludes/class-coverkit-rest.phpincludes/class-coverkit-template.phpincludes/class-coverkit-renderer.phpincludes/class-coverkit-use-case-registry.php- use-cases-and-output-profiles.md
Frontend
src/blocks/canvas/,src/blocks/shape/src/editor/index.jssrc/editor/use-cases/(UseCasePanel,UseCaseAssignment, mapping components)