Guide

Chart screenshot providers

Chart featured-image PNGs are captured through Screenshot_Service. Callers keep is_configured() and take(). Providers share one capture spec. Administrators set the provider and capture defaults under Charts → Settings → Screenshot Settings. That pane shows a configured / not-configured badge and lists the VIP API key constants as set or not set. Credential values are never returned. Firebase lists PRC_PLATFORM_FIREBASE_KEY, PRC_PLATFORM_FIREBASE_PROJECT_ID, and whether the service-account file from PRC_PLATFORM_FIREBASE_SERVICE_ACCOUNT is present.

Pipeline

  1. Save or regenerate

    PNG_Export enqueues an Action Scheduler job. The featured-image path calls take() with the saved chart layout and the site screenshot defaults (scale, padding, selector, delay).

  2. Resolve a provider

    The registry uses PRC_PLATFORM_CHART_SCREENSHOT_PROVIDER when that constant is set. Otherwise it uses the provider saved in Charts → Settings. If both are empty it auto-detects the first configured provider in order: ScreenshotOne, Cloudflare, Firebase, signed endpoint.

  3. Capture /export/

    The provider screenshots {permalink}/export/. That page renders only the chart. It always uses desktop attributes. Explicit take_spec() calls add screenshot_width and screenshot_height so the chart reflows first. Successful captures store the provider slug on the attachment.

PNG_Export does not generate extra sizes on save. Extra frames are later callers of take_spec().

Capture spec

Screenshot_Capture_Spec is the input every provider must honor.

Reference

Screenshot_Capture_Spec

Typed options, defaults, and constraints in one scannable reference.
6 fields
viewport_width number required
Browser CSS viewport width in pixels, including side padding when built from layout.
viewport_height number required
Browser CSS viewport height in pixels, including side padding when built from layout.
device_scale_factor number required
Positive integer. Default featured-image capture uses 2.
selector string
CSS selector captured by the provider.
delay_seconds number
Wait before capture so the charting library can render.
viewport_side_padding number
Padding added on each side when building from layout or an alias. Default featured-image padding is 48. Export reflow uses the unpadded layout size.

take( $url, $width, $height ) builds from_layout() using Charts → Settings capture defaults and does not add export query args. take_spec( $url, $spec ) appends screenshot_width and screenshot_height from get_layout_width() / get_layout_height().

php take-spec.php
$spec = new \PRC\Platform\Chart_Builder\Screenshot_Providers\Screenshot_Capture_Spec(	1200,	400,	3);$png = ( new \PRC\Platform\Chart_Builder\Screenshot_Service() )	->take_spec( $export_url, $spec );
Capture a 1200 by 400 CSS layout at scale 3. Padding is 0, so /export/ reflows to 1200 by 400.

Export page

URL pattern: /chart/{slug}/export/.

Query args screenshot_width and screenshot_height must both be present, must be positive integers, and are capped at 2000 to match the Firebase screenshotElement viewport limit. Incomplete or invalid values keep the saved layout. The page body class is wp-chart-builder-export. Chart view JS locks that document to the desktop attribute set so a 640px chart is not treated as tablet.

Named aliases

Screenshot_Capture_Spec::from_alias( $slug, $chart_width, $chart_height ) resolves default to from_layout(). Any other slug comes from prc_chart_builder_screenshot_variants. The plugin registers no extra aliases.

Each filtered variant must include integer width, height, scale, and padding. Unknown slugs return screenshot_variant_not_found. Malformed variants return screenshot_variant_invalid.

php screenshot-variants.php
add_filter(	'prc_chart_builder_screenshot_variants',	static function ( $variants ) {		$variants['wide'] = array(			'width'   => 1200,			'height'  => 400,			'scale'   => 2,			'padding' => 48,		);		return $variants;	});
Register a caller-defined alias. Product owns the sizes.

Provider setup

Pin a slug with PRC_PLATFORM_CHART_SCREENSHOT_PROVIDER (screenshotone, cloudflare, firebase, or endpoint). That constant locks the settings UI. When the constant is empty, the site option from Charts → Settings → Screenshot Settings is used. Leave both empty to auto-detect. Filter prc_chart_builder_screenshot_provider runs after the constant and the setting. Filter prc_chart_builder_screenshot_providers can replace the registry.

Successful featured-image captures write _prc_chart_screenshot_provider on the attachment. The media modal shows that field.

Reference

VIP constants

Typed options, defaults, and constraints in one scannable reference.
7 fields
PRC_PLATFORM_CHART_SCREENSHOT_PROVIDER string
Optional provider slug. Empty string selects auto-detect.
PRC_PLATFORM_SCREENSHOTONE_ACCESS_KEY string
ScreenshotOne access key. Required with the secret for the screenshotone provider.
PRC_PLATFORM_SCREENSHOTONE_SECRET_KEY string
ScreenshotOne secret key.
PRC_PLATFORM_CLOUDFLARE_ACCOUNT_ID string
Cloudflare account id for Browser Rendering.
PRC_PLATFORM_CLOUDFLARE_BROWSER_RENDERING_API_TOKEN string
Cloudflare API token with Browser Rendering screenshot permission.
PRC_PLATFORM_CHART_SCREENSHOT_ENDPOINT_URL url
Signed HTTP screenshot endpoint URL.
PRC_PLATFORM_CHART_SCREENSHOT_ENDPOINT_KEY string
API key sent to the signed HTTP endpoint.

ScreenshotOne

Default auto-detect provider. Uses the ScreenshotOne PHP SDK. Configured when both access and secret keys are non-empty. Maps selector, delay, viewport, format PNG, and deviceScaleFactor.

Cloudflare Browser Rendering

REST wp_remote_post to Cloudflare’s screenshot API. Configured when account id and Browser Rendering token are non-empty. Timeout is 60 seconds. Success bodies are PNG. JSON error envelopes become WP_Error.

Firebase screenshotElement

Uses the existing Print Engine render function, not a second Puppeteer service. Configured when PRC\Platform\Firebase exists and prc_platform_firebase_render_endpoints includes screenshot_element (URL from PRC_PLATFORM_FIREBASE_PROJECT_ID). Auth is an OIDC ID token minted from the service-account file (PRC_PLATFORM_FIREBASE_SERVICE_ACCOUNT). The Firebase constructor also requires PRC_PLATFORM_FIREBASE_KEY. The function must honor viewportWidth, viewportHeight, and deviceScaleFactor.

Signed HTTP endpoint

Generic image/png backend for Cloud Run or Lambda. Configured when URL and API key constants are set.

Errors

Screenshot_Service::take() / take_spec() return screenshot_service_not_configured when no provider resolves. REST POST /chart/{id}/regenerate-png maps that to HTTP 503 with the same code. Provider-specific codes stay on that provider.

Source:

  • includes/class-screenshot-service.php
  • includes/screenshot-providers/
  • includes/settings/class-screenshot-settings.php
  • includes/class-chart-export-endpoint.php
  • includes/class-png-export.php

Was this helpful?