Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide filter for filtering the image url. #17

Closed
Levdbas opened this issue Jul 29, 2021 · 5 comments
Closed

Provide filter for filtering the image url. #17

Levdbas opened this issue Jul 29, 2021 · 5 comments

Comments

@Levdbas
Copy link

Levdbas commented Jul 29, 2021

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.

@billerickson
Copy link
Owner

If the upload directory is changing, shouldn't that be reflected in wp_upload_dir()?

I'm working on a site right now with a non-standard uploads directory and this plugin is working fine with it. In wp-config.php I have: define( 'UPLOADS', 'images' );

@Levdbas
Copy link
Author

Levdbas commented Jul 30, 2021

Hi Bill,

I think this is because Bedrock changes the whole content dir instead of just the uploads dir. Config::define('CONTENT_DIR', '/app');

I currently manually implemented this hook to search/replace the /app/ part with /wp-content/ and then the plugin points to the right files on the production site.

@nielsverwaal
Copy link

Hi @billerickson, any idea's on how to do this?? Can you make Bedrock work with your plujgin without manually doing the things @Levdbas descibed above? (Which abviously takes costs a lot of time and effort)

@billerickson
Copy link
Owner

billerickson commented Sep 20, 2021

I've never used Bedrock before so am not sure what changes are required to make it compatible. If you can submit a pull request that fixes the issues in Bedrock, I'll merge it.

My understanding was that the code at the top of this thread fixed the location in Bedrock. If you just add that to a mu-plugin in your local environment (I think) no changes are required to the plugin.

Obviously we can't merge that code into the plugin as it would break images for all non-Bedrock environments.

@nielsverwaal
Copy link

Hi Bill, managed to solve it for this case, although I had to edit the plugin code.
Simple fix in function update_image_url( $image_url )
Before return $image_url; I added $image_url = str_replace("/app/", "/wp-content/", $image_url);
And it worked like a charm!

@Levdbas Levdbas closed this as completed Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants