Wp client side media processing

From Lonsdale201/wp-agent-skills · View interactive version

Wp client side media processing is an AI agent skill from the GitHub repository Lonsdale201/wp-agent-skills. Implement or audit compatibility with the WordPress 7.1 browser-side media pipeline. Covers wp_is_client_side_media_processing_enabled, wp_client_side_media_processing_enabled, REST media create/sideload/finalize, generate_sub_sizes, convert_format, client-side image resizing and conversion, metadat

How to use this skill

Skill file

WordPress Client-side Media Processing

WordPress 7.1 can resize, compress, rotate, convert, and create image derivatives in the browser before files are finalized on the server. Treat this as a second execution path, not as a transparent optimization: server image-editor hooks may not run, attachment metadata can be generated in stages, and the block editor may receive a Document-Isolation-Policy header.

When to use this skill

Model both processing paths

| Path | Processing location | Important consequence |

|---|---|---|

| Server fallback | GD/Imagick on the server | Traditional server image hooks run. |

| WP 7.1 client path | Browser, then REST sideload/finalize | Some server-only hooks never run; metadata arrives in stages. |

Do not feature-detect by version alone:

$client_media_available = function_exists( 'wp_is_client_side_media_processing_enabled' )
    && wp_is_client_side_media_processing_enabled();

The core function defaults to enabled only in a secure context: HTTPS, localhost, or a .localhost host. The wp_client_side_media_processing_enabled filter can override it. A browser can still fall back because of unsupported capabilities or a failed client operation.

Keep upload integrations path-independent

Prefer hooks that describe the completed attachment contract rather than a particular editor implementation. Make metadata filters deterministic and idempotent:

add_filter(
    'wp_generate_attachment_metadata',
    static function ( array $metadata, int $attachment_id, string $context ): array {
        $metadata['myplugin'] = array(
            'version' => 1,
            'source'  => wp_get_attachment_url( $attachment_id ),
        );

        return $metadata;
    },
    10,
    3
);

On the client path, the filter can run once for the initial create and again with $context === 'update' when /finalize applies the browser-produced files. Never bill, send a webhook, enqueue a unique job, or append duplicate data merely because this filter fired. Guard side effects with durable state and make retries safe.

Hooks tied to server image editing, including wp_image_editors, image_memory_limit, and image_make_intermediate_size, do not describe the client path and may not fire. Do not use them as the only place to enforce a security policy or business invariant.

Respect the REST workflow

The standard create route accepts these WP 7.1 parameters:

When client processing is enabled, core also registers:

These are authenticated core endpoints with attachment edit/upload checks, bounded schemas, size-name validation, upload-directory pinning, and file provenance validation. Do not reproduce the flow with a permissive custom endpoint. Do not trust client-supplied filenames, dimensions, MIME types, or metadata in your own routes.

New response fields include missing_image_sizes, filename, filesize, and edit-context exif_orientation. Request only the fields needed and handle filesize: null.

Preserve core image filters

The browser pipeline maps core policy into client behavior. Continue to use the established filters when they express the desired rule:

Test both paths. A PHP filter that accepts a filename or MIME type may be evaluated at a different stage, and a filter with hidden side effects is unsafe.

Handle editor isolation deliberately

For supported Chromium versions, the block editor can send:

Document-Isolation-Policy: isolate-and-credentialless

Core adds crossorigin="anonymous" to relevant cross-origin media/script/style tags in the isolated editor response. Consequences:

Do not globally disable client processing to hide one incompatible asset. First make the asset CORS/CSP-safe or load it only where needed. Use the enablement filter only as a deliberate site compatibility escape hatch.

External media and replacement

Do not fetch arbitrary remote images in the isolated browser. Use the url parameter on the core media create endpoint so WordPress performs a server-side, SSRF-checked HTTP request. For plugin-owned remote imports, apply the same URL validation, capability, MIME, size, timeout, and provenance controls described in wp-file-upload-security.

When an API exposes file replacement, treat it as an update of the attachment's complete file/metadata graph. Do not overwrite a path directly and leave stale derivatives or cache entries.

Test matrix

Run at least:

  1. HTTPS client path and forced server fallback;
  2. JPEG/PNG plus HEIC/HEIF where the browser supports it;
  3. EXIF-oriented image and big-image downscaling;
  4. custom registered image sizes and output-format filters;
  5. failed/interrupted sideload followed by retry/finalize;
  6. metadata filters firing more than once without duplicate side effects;
  7. external image URL, invalid/private URL, and CORS-restricted asset;
  8. block editor with the production CSP and third-party scripts.

Critical rules

Cross-references

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.