Skip to content

Hooks, Integrations, Queue & CLI

Media exposes 8 lifecycle and registry hooks, 13 lazily booted sibling integrations, background queue jobs, a daily maintenance schedule, and 7 trk/processwire-console CLI commands.

Hookable Methods (Media, InputfieldMedia & ProcessMedia)

Section titled “Hookable Methods (Media, InputfieldMedia & ProcessMedia)”
Hook Arguments & Return Timing What It Does
Media::registerDiskDrivers (DiskRegistry $registry): void After Registers custom storage drivers or Flysystem v3 disk adapters during disk discovery.
Media::registerStockProviders (StockMediaRegistry $registry): void After Registers custom Stock Media search and import providers.
Media::authorizePrivateAsset (MediaAssetItem $asset, User $user, array $context = []): bool After Authorizes Private Vault signed downloads; return true to grant access or false to deny.
Media::afterAssetUploaded (MediaAssetItem $asset, array $context = []): void After Fires after a new media asset is uploaded and indexed.
Media::afterAssetReplaced (MediaAssetItem $asset, array $context = []): void After Fires after an in-place file replacement increments ?v=<rev>.
Media::afterAssetDeleted (string $assetId, array $context = []): void After Fires after an asset is trashed or permanently deleted.
Media::afterAssetDownloaded (MediaAssetItem $asset, array $context = []): void After Fires after vault, rendition, bulk ZIP, or public share downloads.
Media::afterVariationPurged (MediaAssetItem $asset, string $presetHandle = ''): void After Fires after cached crop variations are purged (ideal for external CDN cache invalidation).
InputfieldMedia::translations (): array After Returns localized UI strings for the InputfieldMedia asset picker.
ProcessMedia::translations (): array After Returns localized UI strings for the Setup -> Media React workspace.

Authorize Private Vault Assets & Purge CDN Caches

Section titled “Authorize Private Vault Assets & Purge CDN Caches”
site/ready.php
<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Media\Entity\MediaAssetItem;
$wire->addHookAfter('Media::authorizePrivateAsset', function (HookEvent $event): void {
/** @var MediaAssetItem $asset */
$asset = $event->arguments(0);
/** @var User $user */
$user = $event->arguments(1);
if ((string) $asset->get('vault_scope') === 'charter-contracts' && $user->hasRole('charter-broker')) {
$event->return = true;
}
});
$wire->addHookAfter('Media::afterVariationPurged', function (HookEvent $event): void {
/** @var MediaAssetItem $asset */
$asset = $event->arguments(0);
$preset = (string) $event->arguments(1);
$event->wire()->log->save('media-cdn', "Purged variation {$preset} for asset {$asset->id}");
});

Optional Sibling Module Integrations (13 Modules)

Section titled “Optional Sibling Module Integrations (13 Modules)”

Isolated under site/modules/Media/src/Integration/<Target>/ and auto-booted lazily via Media::bootIntegrations() only when each target module is installed:

Module(s) Automatic Integration Behavior
Ai Registers AI image analysis (alt, caption, tags, credit) and text-to-image generation handlers
Headless Exposes published public assets, transform URLs, and responsive payloads (src, srcset, sources, sizes, lqip, dominantColor, focalCss) while strictly excluding private vaults and embargoed assets
Seo Hooks Seo::resolve to enrich SeoBag social previews with an immediate 1200x630 JPEG focus-point og_card crop and localized alt
Forms, Commerce, Account, Campaign, Tour, Charter, Packages, Contacts Register fail-closed PrivateVaultService owner policies authorizing module staff permissions and matching custom_meta.user_id owners; Campaign also rewrites public data-media-id email images to absolute <= 600px URLs
Blocks, Navigation Tag resolved caches with media:<uuid> dependencies and surgically invalidate them on file replacement or crop purge
  • Totoglu\Media\Queue\WarmPresetQueue: Background batch crop preset warming (preset, limit); dispatchable from Setup > Media > Crop Presets (mode=queue).
  • Totoglu\Media\Queue\SyncDiskQueue: Background remote disk synchronization (disk, prefix); dispatchable from Setup > Media > Disks & Tools (mode=queue).
  • Totoglu\Media\Schedule\MediaMaintenanceTask: Daily (03:30) scheduled task that prunes expired trash (when trash_retention_days > 0), cleans up stale chunked upload sessions and temporary ZIP archives (> 1h), and logs upcoming/expired licenses and pending-review/embargo summaries.

Run the background queue worker and system cron so queued crop warming, disk sync, and daily maintenance execute automatically:

Terminal window
# Background queue worker (run under Supervisor or systemd)
php vendor/bin/wire queue:work --tries=3 --sleep=3
# Crontab entry (runs MediaMaintenanceTask daily at 03:30)
* * * * * cd /var/www/aegeanvoyages.example && /usr/bin/php vendor/bin/wire schedule:run >> /var/log/pw-schedule.log 2>&1
  • Mocking Stock Provider HTTP Calls: Inject a closure transport into StockMediaService::setHttpTransport(?\Closure $transport) inside Pest/PHPUnit tests so stock media searches and imports never touch live external APIs.
  • 6-Locale Translation Packs: Bundled CSV packs (en, tr, de, fr, es, ru) live in site/modules/Media/languages/. Import the matching .csv file under Setup -> Languages -> [Language] -> Site Translation Files.

All commands run via php vendor/bin/wire <command> and support --dry-run and --json:

Command Options Description
media:import --template=, --field=, --disk=, --limit=200, --dry-run, --json Import ProcessWire Pageimage/Pagefile fields into centralized Media assets with SHA-256 and pHash deduplication
media:sync --disk=, --prefix=, --dry-run, --json Scan a configured storage disk prefix, index new files, and flag missing files
media:usage:reindex --dry-run, --json Rebuild entries_tbl_media_usage across Pages, Entries, and Tiptap fields
media:crops:warm --preset=, --pending, --limit=100, --dry-run, --json Pre-generate automatic crop presets or materialize pending delayed crops across public images (never overwrites is_manual = 1)
media:crops:clear --preset=, --disk=, --status=, --include-manual, --limit=500, --dry-run, --json Purge cached crop variations selectively (status: ready, pending, failed; preserves manual crops unless --include-manual is passed)
media:doctor --dry-run, --json Run health diagnostics on blueprints, Managed SQL Tables, disks, private vault guards, and image codecs
media:disk:test --disk=, --dry-run, --json Probe read/write connectivity for one or all configured storage disks

media:doctor reports missing AVIF or WebP support

Section titled “media:doctor reports missing AVIF or WebP support”

Check which PHP image extension is active under Setup > Media > Settings > Crops & Watermark (image_driver). Switching from GD to imagick or vips unlocks full AVIF, WebP, and PDF first-page cover generation.

Public template returns empty markup for an uploaded asset

Section titled “Public template returns empty markup for an uploaded asset”

Verify the asset’s Approval Status is approved and Embargo Until is blank or in the past. Media::resolvePublicAsset() and Media::renderResponsive() intentionally skip unpublished or embargoed assets.

Asset cannot be deleted (“Asset is in use”)

Section titled “Asset cannot be deleted (“Asset is in use”)”

delete_policy defaults to block to prevent broken links. Open the Asset Inspector to view every Page, Entry, or Tiptap reference, remove or replace the reference (or use Duplicate Merge), or switch delete_policy to warn under Settings > Storage & Disks.

Delayed crops return 404 on a custom web server

Section titled “Delayed crops return 404 on a custom web server”

Confirm that ProcessWire’s standard 404 routing (ProcessPageView::pageNotFound) handles missing files inside site/assets/files/media/, or run php vendor/bin/wire media:crops:warm --pending to materialize pending variations in batch.

Next steps