Git Product home page Git Product logo

uploads-by-proxy's Introduction

=== Uploads by Proxy ===
Contributors: pdclark
Author URI: http://pdclark.com
Tags: localhost, local, development, staging, uploads, media library, xampp, mamp, wamp, git, svn, subversion
Requires at least: 3.1
Tested up to: 4.7.4
Stable tag: 1.1.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

For local development: Automatically load images from the production version of wp-content/uploads if they are missing locally.

== Description ==

This plugin is meant to be used by developers who work on sites in a local development environment before deploying changes to a production (live) server. It allows you skip downloading the contents of `wp-content/uploads` to your local WordPress install. Instead, images missing from the uploads directory are loaded from the production server as needed.

= Setup =

In most cases, you should be able to activate the plugin and go. If the plugin does not work automatically, then you need to set the address of your live WordPress install in `wp-config.php`, like this:

     define('UBP_SITEURL', 'http://example-live.com/wordpress');

If you are on a staging server (not a local development environment) you may need to force the plugin to run with `define( 'UBP_IS_LOCAL', true );` in `wp-config.php`. Do not set this on a live site!


== Installation ==

1. Upload the `uploads-by-proxy` folder to the `/wp-content/plugins/` directory
1. In a local or staging development site, activate the Uploads by Proxy plugin through the 'Plugins' menu in WordPress
1. If your development site address is different than your live site address, or you are not using `WP_SITEURL`, set your live site address in `wp-config.php` like this: `define('UBP_SITEURL', 'http://example-live.com/wordpress');`

== Frequently Asked Questions ==

= Why would I want to use this? =

Maybe you work on a site with gigabytes of images in the uploads directory, or maybe you use a version control system like SVN or Git, and prefer to not store `wp-content/uploads` in your repository. Either way, this plugin allows you to not worry about the uploads folder being up-to-date.

= What is a production environment/site/server? =

"Production" is a term that's used to refer to a version of a site that is running live on the Internet. If you normally edit your site through the WordPress code editor or over FTP, you are making edits on the production server. Editing your site in this way risks crashing the site for your visitors each time you make an edit.

= What is a development environment/site/server? =

"Development" refers to a version of your site that is in a protected area only accessible to you. Programs like [MAMP](http://www.mamp.info), [WAMP](http://www.wampserver.com/), and [XAMPP](http://www.apachefriends.org/en/xampp.html) allow you run a copy of your WordPress site in a way that is only accessible from your computer. This allows you to work on a copy and test changes without effecting the live site until you are ready to deploy your changes.

= An image changed on my live server, but it didn't update locally. =

This plugin only goes into action when an image is missing on your local copy. When it runs, it copies the file into your local wp-content/uploads folder and doesn't run again. If you'd like to update an image with the production copy again, delete your local copy.

= What will happen if I enable this plugin on a live site? =

Nothing. The plugin only takes action if it detects it is on a local development environment.

= How does the plugin detect the difference between a production and development environment? =

The plugin only loads if the server address and browser address are both `127.0.0.1`. This should catch most local environments, such as MAMP, WAMP, and XAMPP.

If your local domain is the same as the remote domain, and automatic IP detection doesn't work, use the <code>ubp_remote_ip</code> filter to set IP address programatticaly. 

Example: <code>add_filter( 'ubp_remote_ip', function(){ return '12.34.56.789'; } );</code>

If you want to run the plugin on a staging server, or have some other situation where you want to force the plugin to run, set `define('UBP_IS_LOCAL', true);` in wp-config.php.

**Warning!** Do not force `UBP_IS_LOCAL` to `true` on a production site! If if have any 404 requests for images in the uploads directory, it will cause PHP to go into an infinite loop until Apache kills the process. This could make your site run very slowly.

= How does the plugin get around local DNS when production and development sites use the same domain? =

It asks one of several remote servers what *it* thinks the IP address of your production domain is, then uses that IP to request the missing image. The correct domain name is sent in headers so that virtualhosts resolve.

= What if I don't want my domain name sent to some third-party site? =

You can define your own server that will return an IP address when given a domain name. In your WordPress install, you would put this in a plugin or functions.php:

`add_filter('ubp_ip_url', 'ubp_ip_url', 10, 2);
function ubp_ip_url( $url, $domain ) {
    return 'http://yoursite.com/ip.php?domain='.$domain;
}`

**yoursite.com** would be replaced with your own site address, and **ip.php** would contain:

`<?php echo gethostbyname( $_GET['domain'] ); ?>`

= Where are those icons in the wordpress.org plugin header from? =

[Font Awesome](http://fortawesome.github.com/Font-Awesome)

== Changelog ==

= 1.1.3 =

* Fix: Remove hostnametoip.com from IP service providers.
* New: Add <code>ubp_remote_ip</code> filter to set IP address programatticaly. Usage: <code>add_filter( 'ubp_remote_ip', function(){ return '12.34.56.789'; } );</code>
* Notice: Only one of three IP address services is still available. If this last one goes down, the plugin will no longer support automatic live IP detection when local development environments use the same domain name as the live environment. If this happens, use the new  <code>ubp_remote_ip</code> filter to set your remote IP address.

= 1.1.2 =

* Fix: Resolve a warning output in debug environments. (Static function not declared as static.)

= 1.1.1 =

* Fix: Suppress notice that could keep image from displaying on first load when WordPress installed in root directory. Thanks [@justnorris](http://wordpress.org/support/topic/fixed-some-issues?replies=1).

= 1.1 =

* Auto-detect live URL in cases where `WP_SITEURL` is being set in `wp-config.php`.
* Change `UBP_LIVE_SITE` to `UBP_SITEURL` and match format to `WP_SITEURL`.
* Maintain legacy support for installs using `UBP_LIVE_SITE`.
* Add support for root directory installs mapping to subdirectory installs.
* Add support for subdirectory installs mapping to root directory installs.
* Add IPv6 localhost address when checking for local development environment.

= 1.0 =

* Initial public release.

== Upgrade Notice ==

* Fix: Resolve a warning output in debug environments. (Static function not declared as static.)
* Fix: Suppress notice that could keep image from displaying on first load when WordPress installed in root directory. Thanks [@justnorris](http://wordpress.org/support/topic/fixed-some-issues?replies=1).

uploads-by-proxy's People

Contributors

aaemnnosttv avatar mountainash avatar pdclark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

uploads-by-proxy's Issues

Doesn't work if the production/staging site is password protected

Hello,

I have added this to my local on different projects before it works fine if I am grabbing images from live sites, but if I am trying to get images from a production/staging server from my local computer, it doesn't work.

I believe this is because the production/staging server is username and password protected.

Is there a way to overcome these credentials (I have the logins) so I can call those images?

Kind regards

Not working

The extension doesn't seem to be working. Is it still compatible with the current release of WordPress?

I've defined 'UBP_SITEURL', 'UBP_LIVE_DOMAIN' and 'UBP_IS_LOCAL', but not getting anything to work.

Multisite support

Multisite support basically comes down to three things:

The allowed path filter

class-404-template.php#L92
UBP checks to see if the requested $path from $_SERVER['REQUEST_URI'] contains $uploads['basedir'] with ABSPATH stripped out. So, for example, when requesting an image:

/wp-content/uploads/2012/10/image.jpg

$uploads['basedir'] without ABSPATH on a single site is:
wp-content/uploads
which exists in the requested path, so it passes.

On multisite, the requested $path would be:
/files/2012/10/image.jpg

But $uploads['basedir'] would be something like:
/wp-content/blogs.dir/3/files/ (where "3" is a blog ID)

So they don't match up. The check needs to be revised to accomidate multisite uploads directory path rewrites.

Download Path

class-404-template.php#L41
When an image is found, it's downloaded and saved to the local uploads directory. The download method, like allow_path, makes the assumption that the path to save the image to matches the path the image was requested from. In multisite, this isn't the case.

For example, single site:
image requested from: http://site.com/wp-content/uploads/2012/10/image.jpg
image saved to: ABSPATH.'/wp-content/uploads/2012/10/image.jpg'

But multisite:
image requested from: http://site.com/subsite/wp-content/uploads/2012/10/image.jpg
image saved to: ABSPATH.'/wp-content/blogs.dir/3/files/2012/10/image.jpg'

And "subsite" could also be a subdomain (subsite.site.com), or a mapped domain name. (subsite.com)

*Changes in 3.5 *

Trac ticket #19235

I haven't tested Nacin's final version of this in the 3.5 betas, but I'm pretty sure it's slated for release. Basically, in 3.5, there they'll be using wp-content/uploads/sites instead of wp-content/blogs.dir. wp_upload_dir() should account for this, but it of course needs to be tested, and the solutions for #1 and #2 need to be agnostic to whether they're running on 3.4- or 3.5+

To test any of these, you'd need to comment out the hook for requiring multisite to activate. But maybe you already did that? I was surprised to hear you activated the plugin on a multisite at all. Did it let you do it on the master site?

Infinit redirect loop if filename contains Unicode characters

If filename from uploads directory contains Unicode characters, infinite loop will occur.
This happens on Windows, not sure for Linux.

To fix this, two things needs to be changed in class-404-template.php file.

In function get_local_path() replace line
$this->local_path = $requested_path;
with
$this->local_path = urldecode($requested_path);

Then, in function download() add snippet

if(strcasecmp(substr(PHP_OS, 0, 3), 'WIN') == 0){
    $abspath = iconv('UTF-8', 'WINDOWS-1252', $abspath);
}

before line
$saved_image = $wp_filesystem->put_contents.....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.