billerickson / be-media-from-production Goto Github PK
View Code? Open in Web Editor NEWUses local media when it's available, and uses the production server for rest.
License: GNU General Public License v3.0
Uses local media when it's available, and uses the production server for rest.
License: GNU General Public License v3.0
Could you add a filter that accomodates for multisite installs, a la:
https://stackoverflow.com/questions/35781410/wordpress-multisite-wp-upload-dir-wrong
When switching from a default WordPress installation to a Bedrock based WordPress install or vice versa, the upload folder location changes. It would be nice if there would be a filter in the update_image_url() method where you can filter the image path.
Then things like this are possible.
add_filter(
'be_media_from_production_image_url',
function ($image_url) {
return str_replace("/app/", "/wp-content/", $image_url);
}
);
let me know your thoughts.
The v1.7.0 update didn't seem to have any changelog in the repo. I recall there previously was one, though I didn't go digging for it. It would be great to get that updated, especially to clarify the new branding/plugin co-owner.
Thanks for the great plugin!
@graylaurenm or anyone else, have you found a filter that we could use to target images in the editor? At some point in a recent WordPress update, BE Media from Production stopped updating the URLs of these images. They still work correctly on the frontend.
WordPress 5.4.2. Plugin 1.6.0.
I have a cover block with the following content stored in the database (I've changed the url for privacy):
(I disabled the comments so that they show here)
<! -- wp:cover {"url":"https://staging.example.com/wp-content/uploads/2020/08/bar-mitzvah-israel.jpg","id":7879} -- > <div class="wp-block-cover has-background-dim" style="background-image:url(https://staging.example.com/wp-content/uploads/2020/08/bar-mitzvah-israel.jpg)"><div class="wp-block-cover__inner-container"><! -- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -- > <p class="has-text-align-center has-large-font-size">This image is from the staging site.</p> <! -- /wp:paragraph -- ></div></div> <! -- /wp:cover -- >
The file has been uploaded to the staging site only. It is not on the production site.
I added some error_log() calls to the local_filename() function.
function local_filename( $url ) { error_log( "local_filename: url = " . $url ); $upload_locations = wp_upload_dir(); error_log( "upload_locations: " . var_export($upload_locations, true) ); $local_filename = str_replace( $upload_locations[ 'baseurl' ], $upload_locations[ 'basedir' ], $url ); error_log( "local_filename: return = " . $local_filename ); return $local_filename; }
and this is what I see in the debug.log file:
[05-Aug-2020 21:24:32 UTC] local_filename: url = https://staging.example.com/wp-content/uploads/2020/08/bar-mitzvah-israel.jpg) [05-Aug-2020 21:24:32 UTC] upload_locations: array ( 'path' => '/home/example/staging.example.com/wp-content/uploads/2020/08', 'url' => 'https://staging.example.com/wp-content/uploads/2020/08', 'subdir' => '/2020/08', 'basedir' => '/home/example/staging.example.com/wp-content/uploads', 'baseurl' => 'https://staging.example.com/wp-content/uploads', 'error' => false, ) [05-Aug-2020 21:24:32 UTC] local_filename: return = /home/example/staging.example.com/wp-content/uploads/2020/08/bar-mitzvah-israel.jpg)
It seems to be doing the right substitution but note that the incoming $url has a closing round bracket at the end.
This appears to be from the background-image style.
Is this a possible bug in the cover block's rendering code?
Do you have any ideas where would I look for that?
Does this make it that uploading images goes to the server and not the local?
Or it just shows images already in the system as remote?
We are using a remote DB and are trying to find a way that if a dev uploads via the local url it gets added to the production server.
I'm currently using this plugin on a site where I need to use media from a staging site that is behind HTTP Auth (i.e., the little popup browser window that asks for a username and password).
I was pleased to figure out that you can make this work with this plugin as-is list this:
That gets you the media from example.org where the auth username is "user" and the password is "password".
It seems like this might be worth quickly documenting (maybe in a FAQ in the readme)? Happy to submit a PR if you'd like :)
Hi,
Awesome plugin... ty.
I wanted to try to troubleshoot and see why image links are broken when using ACF Flexible Content as a page builder. I am not sure if you're aware of that workflow and if so, had any hints where to look?
https://wptips.dev/diy-page-builder-with-acf/
Cheers~
Hi Bill,
I just saw that you've released version 1.5 that includes constants. Could you release this version on the WordPress repository as well? To automate the process of publishing a new version on github and publishing it on the WP repo could be automated with a tool like: https://github.com/10up/action-wordpress-plugin-deploy
First of all, thanks for the awesome plugin. So helpful.
I've installed this on a new client's site where I'm taking over support of an existing site where the old developer has gone away.
The old developer has a bit of an odd wp-config.php
and one of the things it does is:
define('WP_CONTENT_URL', "http://{$_SERVER['SERVER_NAME']}");
and his directory structure reflects this.
BE-Media-from-Production doesn't work in this setup.
At the very least, line 196 reads:
if( strpos( $url, 'wp-content/uploads' ) ) {
and should probably be changed so that it matches the WP_CONTENT_URL
if( false !== strpos( $url, WP_CONTENT_URL . '/uploads' ) ) {
(Note that we could now get a 0 from strpos
and so we need the type-specific comparison)
You may also want to test for, and use if necessary, the UPLOADS constant (though, unlike WP_CONTENT_URL, this doesn't seem to be set by default, and will need to be tested for)
If an image exists locally and is output with a srcset attribute, it fails the local_image_exists check, so the plugin replaces the URLs in the srcset with the production URL.
It looks like this is because the [image_attr](https://github.com/billerickson/BE-Media-from-Production/blob/master/be-media-from-production.php#L156)
method passes the srcset value to the image updater, but the local image check is expecting a URL, and the srcset will be a string such as:
http://local.example.test/wp-content/uploads/2019/05/tim-foster-264461.jpg 4599w, http://local.example.test/wp-content/uploads/2019/05/tim-foster-264461-300x206.jpg 300w, http://local.example.test/wp-content/uploads/2019/05/tim-foster-264461-768x526.jpg 768w, http://local.example.test/wp-content/uploads/2019/05/tim-foster-264461-1024x702.jpg 1024w
which will not return true for the file existing.
Actually, I think all that needs to happen is to change line 159 to this:
$attr['srcset'] = $this->update_image_url( $attr['src'] );
(passing just src
to the updater instead of srcset
... this fixed the issue for me locally.
Love this functionality. I'm installing it on a number of sites, and this is going to let me not have to maintain so much space on my tiny little mac for larger sites.
I wonder if it would be possible to add functionality for the wp_get_attachment_url function in addition to the ones already supported (wp_get_attachment_image_src, wp_get_attachment_image_attributes, wp_prepare_attachment_for_js, the_content); this obviously could be used for images, but my use case is actually video files that we're pulling in via ACF to add background video.
This is how it's being pulled in currently:
https://gist.github.com/jonschr/224d56a40c9f7e5931355a65018e1b44
Hi Bill,
I love the plugin and almost use it in every project. We all love automating things such as plugin installs. Many will use composer and wpackagist to include plugins in our projects. But then the plugin has to be in the main WP repository. Is that something you are planning on doing? Another option would be to add an composer file to this repository so we could use something like:
composer config repositories.repo-name vcs https://github.com/billerickson/BE-Media-from-Production composer require billerickson/BE-Media-from-Production:master
This is needed for compsoser to work because right now composer trows an error:
[Composer\Repository\InvalidRepositoryException] No valid composer.json was found in any branch or tag of https://github.com/billerickson/BE-Media-from-Production, could not load a package from it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.