messageagency / ma-pantheon-image-proxy
Automatically fetches images from Pantheon origin when they don't exist locally during development
Package info
bitbucket.org/messageagency/ma-pantheon-image-proxy
Type:wordpress-plugin
pkg:composer/messageagency/ma-pantheon-image-proxy
Requires
- php: >=8.2
- composer/installers: ^1.0 || ^2.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-12-03 12:59:46 UTC
README
A WordPress plugin that automatically fetches images from Pantheon origin when they don't exist locally during development.
Features
- Automatic Detection: Only runs in local development environments (not on Pantheon)
- Smart Proxying: Only proxies missing images, checks local filesystem first
- Multiple Filters: Works with WordPress media functions and Timber image helpers
- Direct Request Handling: Handles direct URL requests to missing images
- Zero Configuration Required: Just activate and set your environment variable
- Performance: Caches proxied images with appropriate headers
Installation
Via Composer (Recommended)
composer require messageagency/ma-pantheon-image-proxy
Manual Installation
- Download the plugin
- Upload to
wp-content/plugins/ma-pantheon-image-proxy/ - Activate through the WordPress admin
Configuration
Add the following to your local .env file (not tracked in git):
PANTHEON_IMAGE_PROXY_ORIGIN=https://dev-yoursite.pantheonsite.io
You can use any Pantheon environment URL:
- Dev:
https://dev-yoursite.pantheonsite.io - Test:
https://test-yoursite.pantheonsite.io - Live:
https://live-yoursite.pantheonsite.io - Multidev:
https://multidev-name-yoursite.pantheonsite.io
Loading Environment Variables
This plugin expects the PANTHEON_IMAGE_PROXY_ORIGIN variable to be available in $_ENV. If you're using vlucas/phpdotenv, make sure your wp-config.php loads the .env file:
if (file_exists($root_path . '/.env')) {
$dotenv = Dotenv\Dotenv::createMutable($root_path);
$dotenv->load();
}
How It Works
The plugin automatically detects when you're running locally (not on Pantheon) by checking for the absence of the PANTHEON_ENVIRONMENT environment variable.
When active, it:
- Checks if an image exists locally in
wp-content/uploads/ - If the image doesn't exist, it proxies the request to your configured Pantheon origin
- Returns the image with appropriate headers and caching
The plugin hooks into multiple WordPress filters to catch images loaded through:
wp_get_attachment_url()wp_get_attachment_image_src()wp_calculate_image_srcset()(responsive images)- Timber
Image()helper (if using Timber)
Requirements
- PHP >= 8.2
- WordPress >= 6.9
- Local development environment (not on Pantheon)
PANTHEON_IMAGE_PROXY_ORIGINenvironment variable
Usage
Once configured, the plugin works automatically. No additional code or configuration is needed.
Example with Standard WordPress
// This will automatically proxy from Pantheon if image doesn't exist locally
echo wp_get_attachment_image($attachment_id, 'full');
Example with Timber
{# This will automatically proxy from Pantheon if image doesn't exist locally #}
<img src="{{ Image(post.thumbnail).src }}" alt="{{ post.title }}">
Disabling
To disable the plugin:
- Remove or comment out the
PANTHEON_IMAGE_PROXY_ORIGINvariable in your.envfile, or - Deactivate the plugin in WordPress admin
Why Use This Plugin?
When working on a local copy of a Pantheon-hosted WordPress site, you often don't have the full wp-content/uploads/ directory synced locally (it can be huge!). This plugin allows you to work with images seamlessly without downloading the entire uploads directory.
Development
Bitbucket Pipelines runs two checks on every pull request and on master, both on the minimum versions (PHP 8.2, WordPress 6.9):
- Lint:
composer validate --strict,php -l, and WordPress Coding Standards with the rules inphpcs.xml.dist. - Smoke test:
tests/smoke.shagainst a fresh WordPress install.
To run them on a local site with the plugin active:
phpcs --standard=phpcs.xml.dist # any WordPress Coding Standards 3 install
bash tests/smoke.sh # from the site's root, or set WP_PATH
The smoke test checks the URL filters, the switches that turn the proxy off, and direct requests fetched from a stand-in origin it starts with php -S on 127.0.0.1:8089 (SMOKE_ORIGIN_PORT changes the port). It creates and deletes an attachment, so run it on a local site only.
License
MIT