Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

91 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VideoOptimizer for WordPress & WooCommerce

Fast, adaptive video from a European CDN — blocks, shortcode, Elementor widget, media library integration and WooCommerce product videos.

WordPress 6.6+ WooCommerce 8+ PHP 8.1+ License MIT

Sister projects: videooptimizer-shopware · videooptimizer-sulu

Highlights

  • Eight blocks: Video, Video + Text, Background Hero, Spotlight, Video Grid, Video with Chapters, Video List and Video Detail, plus the [videooptimizer] shortcode and an Elementor widget with identical options and output.
  • Poster first: visitors download nothing but a responsive poster until they press play. You can use the themable VideoOptimizer player (iframe) or a native HTML5 player (HLS natively in Safari/Chrome, hls.js on demand elsewhere). Either one can play in place, in a lightbox or directly.
  • Media library integration:
    • "Send to VideoOptimizer" per video or in bulk.
    • Once a video is ready, core/video blocks, [video] shortcodes and Elementor video widgets are delivered via VideoOptimizer automatically. Your content stays unchanged.
    • After you delete a linked media file, the plugin asks whether to delete the video in VideoOptimizer too, and lists every page or product that still uses it. You can also set it to always keep, or to always delete unused videos.
  • WooCommerce:
    • Product videos in the gallery. They work with FlexSlider, zoom and PhotoSwipe, and pause when you swipe away.
    • Videos per variation: the gallery jumps to the video when shoppers select that variation.
    • WooCommerce's own gallery videos (feature "Product gallery videos", classic gallery and the new Product Gallery block): once a media library video has been sent to VideoOptimizer and is ready, it is delivered from VideoOptimizer, with adaptive HLS and the VideoOptimizer poster.
    • A "Video" product tab.
    • Muted hover previews in shop and category grids.
  • Admin:
    • Upload by drag & drop. Presigned multipart uploads go straight to storage, so no PHP limits apply.
    • Import by URL, pick poster frames or upload custom posters, edit player defaults.
    • Subtitles per video (.vtt / .srt) in the organization's subtitle languages, tags and metadata, and the storage and bandwidth savings.
    • Manage libraries and their encoding ladder. When you change the ladder, the plugin offers to re-encode the library's existing videos right away.
  • SEO: schema.org VideoObject JSON-LD.
  • Security:
    • The API token is encrypted at rest (libsodium, key derived from the WP salts) and is never sent to the browser.
    • Every REST route is capability-checked and uses an allowlist.
    • Webhooks are verified with HMAC and replay protection.
  • Performance: assets load only on pages that contain a video, the hosted player is lazily injected, and embed lookups are cached (transients) with a 3-second timeout, so a slow API never slows a page.
  • Translation-ready, with German (formal) bundled. The plugin passes wordpress.org Plugin Check.

Installation

  1. Download videooptimizer.zip from the latest release, or build it yourself (see Development).
  2. In WP-Admin, go to Plugins → Add New → Upload Plugin, upload the ZIP and activate it.
  3. Continue with VideoOptimizer → Settings (see below).

Requirements: PHP 8.1+ with sodium, WordPress 6.6+. WooCommerce 8.0+ and Elementor are optional.

Using the plugin

  1. VideoOptimizer → Settings: paste an organization API token (VideoOptimizer app → Organization → API tokens), then click Save & test. Pick a default library, player and presentation. Alternatively, put define( 'VIDEOOPTIMIZER_API_TOKEN', 'vp_…' ); in wp-config.php.
  2. VideoOptimizer → Videos: upload or import videos, then click one to change its poster, player defaults or copy its embed code.
  3. Editors:
    • Block editor: insert one of the VideoOptimizer blocks. Video + Text and Background Hero use regular inner blocks for their text.
    • Shortcode: [videooptimizer uuid="…"]. Every block attribute works as a shortcode attribute, for example layout="media-split" player="native" presentation="lightbox" autoplay="1" cta_url="/shop".
    • Elementor: use the VideoOptimizer widget.
  4. Media library: Send to VideoOptimizer is available as a row action, bulk action and in the attachment details. On public https sites the server hands over the file URL. Locally or behind a password, the browser uploads the file instead.
  5. WooCommerce: use the Product videos (VideoOptimizer) box on the product edit screen for gallery videos, the tab video and the hover preview. Each variation has an additional Variation video field.
  6. Webhook (optional): in the VideoOptimizer app, create a webhook for video.ready and video.failed that points to https://your-site/wp-json/videooptimizer/v1/webhook, and paste its secret into the plugin settings. Without a webhook, WP-Cron checks processing videos every 5 minutes.

Content elements

Element Block / shortcode layout What it does
Video with chapters video-chapters The video shown directly plus 3–10 scene previews (the video's thumbnails). A click starts the video at that scene. Options: scenes (3–10, default 5), scene_titles (one per line, or separated by | in a shortcode), player.
Video list video-list Cards of the ready videos of a library (library), optionally filtered by tag, per_page per page (1–48), columns. Paged with "First page / Next page" links (?vo_cursor=…; the links keep other query arguments such as WPML's lang, but not utm_*, gclid, fbclid and the other tracking parameters page caches ignore, see the filter videooptimizer_ignored_query_args). A card opens the page set in detail_page (page id) with the video in the URL, or a lightbox without one.
Video detail video-detail Shows the video named in ?vo_video=<uuid> with its title, player and JSON-LD; the page title, a meta description and the canonical URL come from the video. A video named in the URL is shown only if it belongs to your organization (checked with the API token) and, with a library set on the element, to that library; anything else answers 404 without a title. While the video cannot be checked or is not ready (API outage, rate limit, lookup limit, still processing) the page answers 503 with Retry-After: 60, shows "temporarily unavailable", has no video title and no noindex; the same holds on pages and posts with a video list whose vo_cursor cannot be loaded right now (a permanent failure such as a deleted library does not answer 503). With Yoast SEO or Rank Math the title, description and canonical go through their filters. Without the argument it shows the default video (uuid). Switch off the meta description with the videooptimizer_detail_meta filter.

Options for the video (and video + text) element:

  • Format (format): 16:9, 9:16, 1:1, 4:5, 21:9 or original. The video fills the chosen ratio (native: object-fit: cover; hosted player: fit=cover). focal_x / focal_y (0–100) set the focal point of native video and poster; the hosted player always crops from the centre. 9:16 and 4:5 are limited to 420 px width.
  • Play while scrolling (scroll_play="1", direct players): starts muted when the video is half visible, pauses when it leaves, a visitor's pause sticks. Never autoplays with prefers-reduced-motion or Save-Data.
  • Floating mini player (mini_player="1", direct players; video and chapters): once started and scrolled out of view, the player is pinned to the bottom right (screens from 600 px) with a close button. Only CSS changes, the player is never moved, so playback continues. It pins only after the visitor started the video (not for autoplay or play-while-scrolling); Escape closes it, with a hosted player use the close button (keys inside the iframe do not reach the page).

The scene previews load https://api.videooptimizer.eu/api/v1/videos/{uuid}/thumbnails/{n} (public, redirects to the CDN): allow it in a strict img-src Content-Security-Policy. Video lists use the list endpoint (cached for five minutes, cleared when a video changes) and pages that contain a list are purged from page caches whenever any video changes.

Configuration reference

Setting Default Notes
Library for new uploads first media-managed library used for media library transfers
Default player VideoOptimizer player hosted (iframe) or native
Default presentation Poster, plays in place facade, lightbox, direct
Deliver optimized media library videos on core/video, [video], Elementor video
Send new uploads automatically off server-side on public sites, otherwise queued for the browser
Transfer method automatic force browser uploads for protected sites
When a linked media file is deleted ask ask, keep, or delete (only if unused). Videos still in use are never deleted without asking.
WooCommerce gallery / position / tab / hover on / after images / on / on
schema.org VideoObject on filter videooptimizer_schema

Constants:

  • VIDEOOPTIMIZER_API_TOKEN
  • VIDEOOPTIMIZER_API_BASE_URL, VIDEOOPTIMIZER_EMBED_BASE_URL (staging)

Filters:

  • videooptimizer_capability
  • videooptimizer_api_base_url, videooptimizer_embed_base_url
  • videooptimizer_schema
  • videooptimizer_core_video_options
  • videooptimizer_enqueue_early
  • videooptimizer_preload_poster
  • videooptimizer_cache_degraded_pages, videooptimizer_shared_post_types

Actions: videooptimizer_webhook, videooptimizer_purge_video.

Page caches: when videos change, the published posts that contain their uuid (blocks, shortcodes, Elementor data, WooCommerce product and variation videos) are purged in WP Rocket, W3 Total Cache, LiteSpeed Cache, WP Super Cache, Speed Optimizer (SiteGround) and the Cloudflare plugin, once at the end of the request and in a single call. The whole site is purged for videos in template parts, reusable blocks or widgets, videos linked to a media library item (core/video, [video], galleries and media widgets reference the attachment, not the uuid), videos on more than 100 pages, more than 20 changed videos at once, and when the API token changes. A whole-site purge runs at once, at most one per minute; others within that minute share one follow-up (WP-Cron; with DISABLE_WP_CRON run it from a system cron). LiteSpeed Cache queues purges made during cron or after output and sends them with the next response. Nothing is searched if no page cache is active; hook videooptimizer_purge_video( $uuid, $post_ids, $all ) to purge a custom cache or CDN ($uuid is '' for a site-wide purge that concerns no single video, such as a token change; $all is true whenever the whole site is purged). Pages with a processing video or any API failure except "not found" (temporary errors, rate limit, token or permission problems) are sent to page caches as uncacheable (DONOTCACHEPAGE; LiteSpeed Cache gets a 60 s TTL instead); deleted videos stay cacheable.

Lookup limit: without a usable ownership index (see "Video detail at scale" below), a video uuid (?vo_video=) or list cursor (?vo_cursor=) from the URL that is not cached yet costs one API call. Such lookups (and list pages with a new cursor, with or without the index) share a pool of 30 a minute for the whole site (setting "Video lookups per minute, whole site", 1 to 1000), and one client may use at most 10 of them a minute (setting "per visitor", 1 to 1000); beyond that the visitor sees "temporarily unavailable" for their own request (a page or post answers with status 503) and the pool is untouched. The client is REMOTE_ADDR (IPv6: its /64 prefix). Behind a proxy or CDN REMOTE_ADDR is the proxy, so return the visitor's address from the filter videooptimizer_client_ip (only from a header your proxy sets and only for requests that really came from it), the filter expects one address (of a comma-separated list the first entry is used). Example that trusts the CDN header only for requests from the CDN's own addresses (replace the list with your proxy's addresses):

add_filter( 'videooptimizer_client_ip', function ( $ip ) {
	$proxies = array( '198.51.100.10', '198.51.100.11' ); // Your proxy / CDN addresses.
	if ( in_array( $ip, $proxies, true ) && ! empty( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {
		return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CF_CONNECTING_IP'] ) );
	}
	return $ip;
} );

A video verified as yours is remembered for 24 hours (a change in VideoOptimizer or a webhook drops it), "not found" for five minutes.

Video detail at scale

A video detail page (?vo_video=<uuid>) must only show videos of your organization. Instead of one API call per unknown uuid, the plugin keeps an ownership index: a snapshot of every video of the token's organization (uuid, library, ready or not), built from GET /videos (100 per page, all libraries; 1,000 videos are 10 API calls). With a fresh, complete index a detail page needs no API call at all: a uuid in it is found, one that is not in it answers 404 (and noindex), so crawlers and random uuids cannot use up the lookup limit.

  • Refresh: a WP-Cron event every 15 minutes (setting "Index refresh interval", 5 to 1440 minutes), never inside a visitor's request. A first build is requested in the background as soon as the token is set. "Rebuild now" on the settings page and wp videooptimizer index build it at once; wp videooptimizer index --status shows the count, build time and whether it is complete. A build takes at most 20 seconds and 200 pages (20,000 videos); beyond that the index is incomplete: it still confirms the videos it holds, but an unknown uuid is verified with a per-uuid lookup (and the lookup limit) as before, and a warning is written to the PHP error log once a day. Only one build runs at a time; a failed build keeps the previous index, is logged (at most hourly) and its reason (for example a plan or permission message from the API) is shown on the settings page.
  • Sites with DISABLE_WP_CRON: WP-Cron does not run, so run the refresh from a system cron, for example every 15 minutes: */15 * * * * cd /path/to/wordpress && wp videooptimizer index --quiet (or wp cron event run --due-now every minute). The command exits with 0 when another build is already running. The API token needs the permission library:view (the list endpoint); without it the build fails and detail pages keep using per-uuid lookups. On multisite every site has its own settings, token, index and cron event: run the command per site (--url=<site>) or wp site list --field=url | xargs -I% wp --url=% videooptimizer index --quiet.
  • Freshness: an index older than twice the interval counts as missing (per-uuid lookups with the limit, a refresh is requested). The index is kept in the non-autoloaded option videooptimizer_ownership_index (about 50 bytes per video, so 10,000 videos are well below 1 MB), so an object cache flush does not drop it, and it belongs to one API token.
  • Updates in between: webhooks (video.ready and video.failed are what VideoOptimizer sends; video.deleted is handled should it ever arrive, so a video deleted outside WordPress leaves the index with the next refresh) and changes in the admin (upload, URL import, edit, delete, deleting or re-encoding a library) update the index at once. A video uploaded without a webhook is not in the index until the next refresh (up to the interval) and answers 404 until then (404 pages send no-cache headers; a page cache that ignores them may keep its own 404 lifetime); a "not found" verdict cached for it is replaced by the index as soon as it knows the video, otherwise it expires after five minutes.
  • Settings and uninstall: the interval and the two lookup limits are on the settings page (Video detail pages). Deactivating the plugin removes the cron events; deleting it removes the index option.

WP-CLI:

  • wp videooptimizer index [--status]
  • wp videooptimizer status
  • wp videooptimizer token set <token> / wp videooptimizer token delete
  • wp videooptimizer videos
  • wp videooptimizer send <attachment-id>…
  • wp videooptimizer sync
  • wp videooptimizer flush [<uuid>]

Player theme in the native player

The theme of the organization/library/video (VideoOptimizer app) is applied to the native player as far as the browser's own controls allow. Block attributes override it.

Theme key Native player
controls controls attribute; false only applies to videos that autoplay (muted), otherwise the visitor could not start them
autoplay, mutedStart autoplay (always muted) / muted start
loopButton loop
preload none stays none; auto and metadata become metadata for above-the-fold videos (native players never buffer segments before playback); deferred videos never preload. Only a prioritised background hero buffers eagerly
interactive: false pointer-events: none, no controls (unless the block sets controls explicitly), only for videos that autoplay directly
controls off (theme or controls="0") on a directly shown video a visible pause/play button (keyboard reachable, label switches "Pause video" / "Play video") in the bottom right corner of the video, also with interactive: false
fullscreenButton, playbackSpeed controlslist="nofullscreen noplaybackrate"
pictureInPicture disablepictureinpicture
accentColor --vo-player-accent (controls, focus ring)

Subtitles uploaded in VideoOptimizer appear as <track> elements (the video gets crossorigin="anonymous"); the viewer picks them in the browser's subtitle menu, the default track starts shown.

Other keys (controlBarBg, playButton*, bigPlayButton, qualitySelector, volumeControl, timeDisplay) have no native equivalent and are ignored; use the VideoOptimizer player for them.

Troubleshooting

Symptom Cause / fix
"VideoOptimizer is not connected yet" No token, or the WP salts changed. Enter the token again.
401 / "token is invalid" The token was revoked or has expired. Create a new organization token.
403 "plan limit" The trial allows 1 library and 20 videos. Upgrade, or delete unused videos.
Uploads/poster disabled for a library The library is delivery-only (media_managed: false).
A video shows the original file It is still processing. Webhook or cron will pick it up, or run wp videooptimizer sync.
A video is missing on the page Deleted in VideoOptimizer. Editors see a notice, visitors see nothing.
Media library transfer fails on a protected site Set Transfer method to Always upload from the browser.

How it works

  • src/Api/Client.php: the server-side API client (wp_remote_request):
    • bearer token, cursor pagination (at most 100 pages, stops if a cursor repeats)
    • one retry on 429 after at most 5 s
    • translated error messages
  • src/Rest/AdminController.php: REST proxy at /wp-json/videooptimizer/v1/* used by the admin app, the block editor, Elementor and the media library.
  • src/Render/*:
    • EmbedRepository caches the public GET /embed/{uuid}: 1 h when ready, 60 s while processing or after an error.
    • Renderer produces the markup for every editor.
    • Assets enqueues assets only where needed.
  • src/Media/*: attachment↔video mapping, server-side URL transfer, and a cron fallback that polls status.
  • src/Woo/*: meta box (product CRUD, HPOS-safe), gallery slides, product tab, hover previews.
  • src/Editor/*: blocks, shortcode, core/video replacement, Elementor.
  • assets/src/*: React UIs (@wordpress/components) and the vanilla frontend script. Built with @wordpress/scripts.

Development

composer install          # PHP dev tools (PHPUnit, PHPCS/WPCS, PHPStan)
npm ci                    # build tooling (@wordpress/scripts, Playwright)
npm run build             # or: npm run start (watch)
Command What it does
composer test PHP unit tests (Brain Monkey, no WordPress needed)
bash tests/bin/run-integration.sh Integration tests against a real WordPress + WooCommerce. Needs a WordPress install and a test database; see tests/wp-tests-config.php for the environment variables.
npm run test:unit Jest tests
npm run test:e2e Playwright E2E (admin, editor, frontend, axe) against a WordPress with the fake VideoOptimizer API, see below.
npm run test:e2e:live Read-only smoke tests against the real API and a site with demo content at WP_URL / WOO_URL.
composer lint / composer fix PHPCS (WordPress Coding Standards) + PHPStan level 8
npm run lint / npm run lint:fix ESLint + Stylelint
bash bin/i18n.sh Regenerate the POT, update de_DE, compile .mo + JS .json (needs WP-CLI)
bash bin/zip.sh Release ZIP → dist/videooptimizer.zip (honours .distignore)

readme.txt is the wordpress.org readme. CI (GitHub Actions) runs the unit tests on PHP 8.1–8.4, runs lint, builds the plugin, runs Plugin Check and the Playwright E2E suite (wp-env + fake API, about 5 minutes). On v* tags it attaches the ZIP to a GitHub release.

End-to-end tests

The E2E suite needs no VideoOptimizer account: tests/e2e/fake-api/server.js is a small local stand-in for the API (OpenAPI-shaped fixtures, a storage stub that returns an ETag, a tiny MP4 + HLS), and the test-only mu-plugin tests/e2e/mu-plugin/videooptimizer-e2e.php redirects requests for api.videooptimizer.eu to it while the option videooptimizer_e2e_api is set. The plugin code is untouched; its https and public-host checks still apply.

npm ci && npm run build
npx playwright install chromium
npx wp-env start                          # site on http://localhost:8889 (admin / password)
node tests/e2e/fake-api/server.js &       # fake API on :4710
bash tests/e2e/bin/wp-env-prepare.sh      # permalinks, German locale, fake token, option for the mu-plugin
WP_BASE_URL=http://localhost:8889 WP_USERNAME=admin WP_PASSWORD=password npm run test:e2e

The specs use @wordpress/e2e-test-utils-playwright (Admin, Editor, RequestUtils): admin smoke in English and German, library and video flows, upload against the stubbed storage, the rejected-token state, inserting and rendering every block, inline text editing, focal point, facade, lightbox, chapters, mini player, list to detail, unknown uuid, and axe-core scans (no serious or critical violations). node tests/e2e/live-smoke.js (workflow live-smoke.yml, nightly and on demand) creates a temporary library on the real API, uploads a tiny video, waits for ready and deletes the library again; it only runs when the repository secret VO_E2E_TOKEN exists.

License

MIT © ScaleCommerce, see LICENSE. Bundled third-party code is listed in THIRD-PARTY-NOTICES.txt (hls.js, Apache-2.0).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages