Skip to content
CoverKit CoverKit v0.1.13

PHP backend

Core PHP classes under CoverKit\ in includes/. Registration helpers live in includes/functions.php.

coverkit.php defines COVERKIT_PLUGIN_DIR, COVERKIT_PLUGIN_URL, PSR-4-style autoloading (CoverKit\includes/class-coverkit-*.php; CoverKit\Use_Cases\*includes/use-cases/class-coverkit-*.php), and init() on plugins_loaded.

File: includes/class-coverkit-post-type.php

  • Registers coverkit CPT and template meta (width, height, background, gradient, _coverkit_use_cases, _coverkit_active_use_cases).
  • Registers blocks from build/blocks/*; restricts allowed blocks to coverkit/* in the template editor.
  • Renders coverkit/canvas on the front end via Renderer::generate_from_content().
  • List-table preview column, per-template cache clear, duplicate/reload row actions.
  • Imports starter templates from assets/templates/ on activation.

File: includes/class-coverkit-rest.php

Registers coverkit/v1 routes and handles coverkit_generate_image async queue. See rest-api.md.

File: includes/class-coverkit-renderer.php

  • generate( string $generation_key, $template_id, ?int $post_id = null, array $options = array() ) — use-case generation; honors coverkit_pre_generate / coverkit_after_generate.
  • generate_from_content( $content, ?int $post_id = null, array $meta = array(), array $options = array() ) — editor preview and canvas rendering.

Default options include format (png), width, quality, force.

CoverKit\Use_Case / Use_Case_Registry / Use_Case_Storage

Section titled “CoverKit\Use_Case / Use_Case_Registry / Use_Case_Storage”

Files:

  • includes/class-coverkit-use-case.php
  • includes/class-coverkit-use-case-registry.php
  • includes/class-coverkit-use-case-storage.php

Registrycoverkit_register_use_case( $slug, $args ) on coverkit_init (priority < 10); boot() at priority 10 reads coverkit_usecases (list of active slugs) and instantiates each registered use case class once.

Storage — canonical assignments in post meta _coverkit_use_cases; rebuilds loader manifest when meta changes.

See use-cases-and-output-profiles.md.

File: includes/class-coverkit-template.php

  • Parses coverkit posts or block content into canvas + elements.
  • apply_data( ?int $post_id = null, string $use_case_id = '' ) — resolves {field_key} tokens, applies native block bindings (Block_Bindings_Applicator), then apply_use_case_mappings() when a use case slug is provided (mappings override bindings on the same layer attribute).
  • apply_use_case_mappings() loads mappings from _coverkit_use_cases and delegates to Mapping_Applicator::apply().
ClassFileRole
Field_Resolverclass-coverkit-field-resolver.phpcollect_raw( $field_name, $post_id ) — built-ins, post_meta:*, acf:*; filter coverkit_collect_field_raw
Field_Formatterclass-coverkit-field-formatter.phpApplies formatter names (date, image, …) after use-case-specific filters
Mapping_Applicatorclass-coverkit-mapping-applicator.phpWrites mapped values onto shape element attributes

Use_Case::format_field_value() collects via Field_Resolver, then Field_Formatter and filters coverkit_use_case_{$slug}_format_field_value / coverkit_format_field_value.

Built-in resolver keys include: post_title, post_excerpt, post_content, post_date, post_url, author, site_name, site_description, site_url, site_logo, featured_image, categories, tags, post_meta:{key}, acf:{name} when ACF is available.

File: includes/class-coverkit-generator.php plus traits in includes/generator/.

Imagick-based rendering with two cache layers:

  • Root directoryget_coverkit_path() resolves to WP_CONTENT_DIR/cache/coverkit-{id}/, where {id} is six lowercase hex characters from coverkit_get_cache_unique_id() (default: first six chars of hash_hmac( 'sha256', 'coverkit-cache-directory', AUTH_KEY ), or wp_salt( 'coverkit_cache' ) when AUTH_KEY is empty). Filter: coverkit_cache_unique_id. Rotating AUTH_KEY changes {id} and therefore the folder name.
  • Composition — PNG hashes under get_coverkit_path( '_cache/generator/' ) and …/elements/ (per-layer reuse between full composes).
  • Final output — use-case REST and template previews write once to canonical paths via coverkit_resolve_output_cache_path() (e.g. post/{post_id}/{template_id}-{use_case}.jpg, coverkit/{template_id}.png); mandatory crop and format conversion stay in memory and do not use _cache/generator/derived/.

Helpers: coverkit_get_use_case_output_cache_path(), coverkit_get_template_preview_cache_path(), coverkit_normalize_image_format(). Filter: coverkit_generation_options, coverkit_max_canvas_dimension.

  • Open_Graph_Image_Use_Casewp_head meta; image URL via /use-case/opengraph/... REST route ('public' => true).
  • Featured_Image_Use_Case — front-end thumbnail HTML/URL via /use-case/featured_image/...; block editor preview via /featured-image/preview/....
  • Sandbox_Use_Case — editor-only profile for testing templates, mappings, and live preview; no front-end hooks.

File: includes/class-coverkit-settings.php

Settings → CoverKit admin page; registers coverkit_options and coverkit_presets; enqueues build/settings/.

  • Patterns — block patterns from patterns/.
  • Examples — dev admin page for examples/ PHP scripts (see examples.md).

Notable helpers in includes/functions.php:

  • coverkit_register_use_case( string $slug, array $args ): bool
  • coverkit_get_cache_unique_id(), coverkit_get_cache_unique_id_default(), coverkit_get_cache_directory_basename(), get_coverkit_path(), clear_cache(), coverkit_collect_cache_clear_targets(), coverkit_resolve_output_cache_path(), get_coverkit_rest_url(), get_coverkit_resize()
  • get_coverkit_responsive_sizes(), is_coverkit_allowed_width()
  • get_screenshot(), save_image_to_media_library()
  • get_templates(), get_template_by_context()
add_action(
'coverkit_init',
static function (): void {
\CoverKit\coverkit_register_use_case(
'my_packaging',
array(
'label' => __( 'Packaging shot', 'my-plugin' ),
'class' => \MyPlugin\Packaging_Use_Case::class,
)
);
},
5
);