Image shortcode / Upload type URL problem
Hi,
As developers, we are working on local servers with development URLs, and we have deployment scripts that automatically replace our development URLs with the testing or production URLs.
For example, loc-mysite.org will be automatically replaced with mysite-org everywhere in the database when I deploy on a production server.
It seems that with the image shortcode, the / characters are escaped with \\ in the page builder code that is saved in the database.
Because some of the URLs in the builder code are escaped / encoded, they are not replaced correctly with the db replace script.
It's working fine when adding an image with the text block shortcode for example.
Code sample :
[media_image image="{"attachment_id":"84","url":"\\/\\/dev.loc.com\\/mysite\\/web\\/app\\/uploads\\/2015\\/03\\/circle-riz.png"}" width="" height="" link="" target="_self" _array_keys="{"image":"image"}" _made_with_builder="true"][/media_image]
In this example dev.loc.com/mysite/web/ should be replaced, but since it is escaped as dev.loc.com\\/mysite\\/web\\/, the db replacement is not working.
This problem occurs with the image shortcode, but also with any "upload" option type used in the shortcodes we are creating.
What do you think?
For info, we are using this db replacement script : https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
Hello,
Same problem here.
A workaround this issues would be to change the views everywhere the upload type is used. (ex: media_image shortcode views)
Instead of using:
$image = $atts['image']['url'];
We could use:
$image = wp_get_attachment_url($atts['image']['attachment_id']);
But it's not really elegant (performance). It's one more call for nothing and then there is no point to record the url in the post.
I think this url problem should be solve but if not, would it be possible to change the image shortcode?
Hi,
The solution is to add multiple replace scenarios. I mean, not only from localhost/my-theme/wp-content/uploads/3/45.jpg to test.com/wp-content/uploads/3/45.jpg, but also the scenarios with backslashes. Here are all our replace scenarios: https://github.com/ThemeFuse/Unyson-Backup-Extension/commit/5c848b1d229489ac6f586a515fe846fdefc3cb66
Sure I recommend to use the normal Unyson import method, as l this staff is done automatically.
Hello,
Sorry but I don't really understand your answer. I don't want to deal with multiple replace scenarios. I think the site url should be the same everywhere on the database and not different only in one place.
Anybody that use a plugin or a software that deal with it might have this kind of problems.
Is there some problems with my solution? https://github.com/Negative-Network/Unyson-PageBuilder-Extension/commit/131515e6df7ea9a404872a6f5f12167028496a40
When the post/page builder content it saved, it is not saved in the post_content, but in post meta, and wordpress at the moment has the problem of removing slashes from meta value. At the moment this is the only solution to save the data in database.
@flody, about your solution, I didn't test it.
Hi @GheorgheP ,
Any news about this? Will you test my solution?
Hi, We will investigate this, at the moment we are in lack of time and cannot provide a final answer.
Hello @GheorgheP ,
Sorry to ask you but is it possible to have a estimation of the time we can expect it to be integrated? We need it for few projects that are going live soon… Just to know if I need to find an other solution.
Thanks.
Hi,
Sorry for big delay.
I cannot give you a estimation time, as we are working now on other more important things.
As for bringing to live the projects, why do not use the normal export/import option?
Same problem for me.
I'm using this tool: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
to replace old-dir\\/folder to new-dir but still no luck.
Use the "Backup & Demo Content Install" to import demo content, it will replace the urls correctly.
Also this will be implemented soon https://github.com/ThemeFuse/Unyson-Backups-Extension/issues/23