gebruederheitz / wp-block-video-overlay
The backend helper for the video overlay block.
Package info
github.com/gebruederheitz/wp-block-video-overlay-backend
pkg:composer/gebruederheitz/wp-block-video-overlay
Requires
- php: >=8.2
- gebruederheitz/wp-easy-customizer: ^3.1.7 || ^4.0
- gebruederheitz/wp-gutenberg-blocks: ~1.8|~2.0
- gebruederheitz/wp-simple-rest: ~3.0 || ~4.0
- league/uri: ^7.8
- league/uri-components: ^7.8
- league/uri-interfaces: ^7.8
Requires (Dev)
- johnpbloch/wordpress-core: 7.1.*@stable
- johnpbloch/wordpress-core-installer: ^2.0
- phpstan/phpstan: ^2.3.7
- phpunit/phpunit: ^11.5
- szepeviktor/phpstan-wordpress: ^v2.0.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-24 15:45:58 UTC
README
see @gebruederheitz/wp-block-video-overlay
Supported versions
- PHP: the minimum is
require.phpincomposer.json. CI runs the test suite on every supported PHP minor line from there (thephpmatrix in.github/workflows/test.yml). Entries marked as canaries test newer PHP lines early and are not supported yet. - WordPress: the code is checked statically, not at runtime: PHPStan
analyses it against the WordPress stubs of each line in
WP_VERSIONSinTaskfile.yaml. The list always includes the line of thejohnpbloch/wordpress-coredev dependency.
Usage
Registering the block
Given you have already initialized the gebruederheitz/wp-gutenberg-blocks BlockRegistrar somewhere:
\Gebruederheitz\GutenbergBlocks\BlockRegistrar::getInstance();
You will then simply have to instantiate a VideoOverlayBlock:
new \Gebruederheitz\GutenbergBlocks\VideoOverlay\VideoOverlayBlock();
Using consent management functionality
Managing user consent of third-party platforms is quite simple with this block
and @gebruederheitz/consent-tools.
To provide the editor scripts in
@gebruderheitz/wp-block-video-overlay
with a list of possible embed types, use the filter hook:
use Gebruederheitz\GutenbergBlocks\VideoOverlay\VideoOverlayBlock; add_filter(VideoOverlayBlock::HOOK_EMBED_TYPES, function ($embedTypes) use $services { $embedTypes[''] = ['displayName' => 'internal']; foreach ($services as $serviceId => $service) { $embedTypes[$serviceId] = [ 'displayName' => $service['prettyName'] ?? $serviceId, ]; } return $embedTypes; });
Changing the default embed provider
You can simply pass the default service's identifier to the constructor:
use Gebruederheitz\GutenbergBlocks\VideoOverlay\VideoOverlayBlock; new VideoOverlayBlock(); // Default: 'youtube' service (data-ghct-src and data-ghct-type="youtube") new VideoOverlayBlock(''); // Default: no consent management (src and no data-ghct-src) new VideoOverlayBlock('vimeo') // Default: 'vimeo' service (data-ghct-src and data-ghct-type="vimeo")
Enabling video captions
Use the filter hook HOOK_CC_LANG_PREFS to provide an array of available
languages on your site to allow editors to input a language preset for Youtube
captions:
add_filter(VideoOverlayBlock::HOOK_CC_LANG_PREFS, function ($enabled) { /* ... */ return true; });
Editors may input a string in the Block Editor representing a language or locale slug (like "en", "en-GB", "en-US", "fr", "de-DE" etc.). The input is sanitized to only allow alphanumeric characters, dashes and underscores.
Defining additional attributes
Yes, there's a filter hook for that:
use Gebruederheitz\GutenbergBlocks\VideoOverlay\VideoOverlayBlock; add_filter(VideoOverlayBlock::HOOK_ATTRIBUTES, function ($attributes) { $attributes['myCustomAttribute'] = [ 'type' => 'string', 'default' => 'attribute default value', ]; return $attributes; })
Changing the block markup
You can override the template used by the block by simply putting a file into
wp-content/themes/{your-theme}/template-parts/blocks/video-overlay.php. The
block's attributes are accessible using get_query_var('attributeName'). Take
look at the default template as an example.
Before filters and templates see them, the block sanitises the attributes
editors control: videoUrl, videoEmbedUrl and mediaURL with
sanitize_url() (no quotes, whitespace or javascript: URLs), mediaID to an
integer, className and type to class characters, and providerType to
letters, digits, _, -, . and :. Other attributes, mediaAltText and
videoId among them, arrive as editors entered them.
Sanitised values are still not safe to print everywhere: a URL may contain a
single quote, for example. Escape every value for where you print it, as the
default template does: esc_url() for URLs (including inside an inline
style), esc_attr() for other attribute values. Otherwise any account that
can edit posts, Authors and Contributors included, can inject scripts into the
page. If your template is a copy of the default one from before 5.0.1, add the
escaping there too.
Alternatively you can filter & override the template partial path and gain even more control:
add_filter(VideoOverlayBlock::HOOK_TEMPLATE_PARTIAL, function (string $partial, string $type, array $attributes) { if ($type === 'overlay') { return get_theme_file_path('templates/block/video/video-type-overlay.php'); } return $partial; }, 3);
Development
Tooling: asdf (PHP and Node.js pinned in
.tool-versions), go-task, Composer and npm.
# Prettier check, then PHPStan against the stubs of every WordPress line in WP_VERSIONS task lint # PHPStan against the stubs of one WordPress line only task lint:wp WP=7.0 # Syntax-check every PHP file and run PHPUnit, on the .tool-versions PHP task test
Locally, task test runs on one PHP only. CI runs it on every supported PHP
line using prebuilt PHP binaries, and runs task lint once on the PHP line
in .tool-versions. Deprecations and warnings fail both the syntax check and
PHPUnit.