Skip to content
프로젝트

billerickson/BE-Media-from-Production

GitHub에서 보기

소개

Uses local media when it's available, and uses the production server for rest.

기타 프로젝트

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
+1
in 7 days
+1
in 15 days
+1
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

BE Media from Production

Contributors: billerickson,magicroundabout
Requires at least: 4.3 Tested up to: 6.8
Stable tag: 1.13.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Uses local media when available, and uses the production server for the rest.

Description

When redesigning a website with a large uploads directory, you might not need all those uploads in your development or staging environment, but you also don't want to see broken images throughout the site.

This plugin lets you use the production server for missing media. Define the production URL using a constant BE_MEDIA_FROM_PRODUCTION_URL or filter be_media_from_production_url.

In all cases, if a local file exists, it will be used in preference to the remote file.

On WordPress 6.2+, images served from the configured production uploads URL use referrerpolicy="same-origin" so production hosts do not reject requests referred by a preview site. This covers content images, attachment images, and avatars without changing local or unrelated image policies.

Attachment URL lookups

On WordPress 6.7+, plugins calling attachment_url_to_postid() can resolve this plugin's production uploads URLs to local attachment IDs. This includes exact attachment filenames, standard -WIDTHxHEIGHT image sizes, and originals of -scaled attachments. Fallback matches must be recorded in the attachment's metadata; arbitrary size names and file extension conversions are not guessed.

Resolution runs only when another caller requests an attachment ID. Normal media URL rewriting performs no additional database lookups. Each new recognized path uses one attachment-file query, with metadata accessed only to validate fallback matches. Successful results and misses are cached for the current request, separately for each site's uploads location. There is no persistent cache or media-directory scan.

Only the configured production uploads prefix is handled, using the same be_media_from_production_local_site_url mapping as outgoing URLs. Local URLs, unrelated origins, and earlier lookup-filter results retain their existing behavior. Older WordPress versions continue serving production media without reverse URL resolution.

Installation

Once the plugin is installed, add the following constant to wp-config.php with your production URL.

define( 'BE_MEDIA_FROM_PRODUCTION_URL', 'https://www.billerickson.net' );

Alternatively, you can use the filter in your theme's functions.php file, a core functionality plugin, or a mu-plugin:

add_filter( 'be_media_from_production_url', function() {
	return 'https://www.billerickson.net';
});

Installation via WP-CLI and constants

wp plugin install https://github.com/billerickson/be-media-from-production/releases/latest/download/be-media-from-production.zip --force --activate
wp config set BE_MEDIA_FROM_PRODUCTION_URL https://www.billerickson.net --type=constant

Using with WP Migrate

WP Migrate is my preferred tool for pushing/pulling databases between environments. The media files functionality allows you to transfer media between environments along with the database.

When redesigning a website, I keep all the media on my development server and push up new media uploads along with the database.

Set up a "push" profile to push your local database to the development server. Make sure "Media Files" is checked and select "Compare, then upload".

Set up a "pull" profile to pull the development database locally. Do not include media in your pull. Any missing media will be handled by BE Media from Production.

관련 프로젝트 살펴보기

불러오는 중…