Plesk for Linux
kb: fixed
kb: bug
ext: wptk
ABT: Group A
Applicable to:
- Plesk for Linux
Symptoms
-
After cloning or syncing a WordPress instance, a few URLs in the target instance still point to the source WordPress instance.
-
On the source WordPress instance, the plugin WPML (WordPress Multilingual Plugin) or XTemos is installed and configured.
Cause
Product issue:
-
#EXTWPTOOLK-2413 "Cloning now should properly process links generated by WPML plugin."
Fixed in:- WordPress Toolkit 5.7.2 12 October 2021
Resolution
Please consider updating your server:
Workaround
If update is not possible for some reason you may try the following
workaround
Currently, no workaround is available to automatically fix the unmodified URLs.
To fix incorrect URLs after cloning or synchronizing an instance, update them in target WordPress instance manually.
Comments
8 comments
I was pointed here by Plesk support regarding a similar issue and thought I'd add what we've done in the meantime.
We've setup a temporary fix by using a combination of an SQL query to update the links on our PROD site and a plugin, Real-Time Find and Replace, that updates all of the links on the TEST site (our configuration is three stages, DEV->TEST->PROD).
Every time we copy content, we rerun the SQL query.
It's not a great solution, but we hope it'll keep us afloat until the fix comes.
Hi Ivan Postnikov and Benjamin Wessel,
Any news?
Hi Benjamin Wessel amd Ivan Postnikov ,
A code on comments of a Yoast Plugin article, may be a temp solution
https://developer.yoast.com/blog/relative-urls-issues/
<code>
<?php
$user
=
"username"
;
$password
=
"password"
;
$database
=
"database"
;
mysql_connect(localhost,
$user
,
$password
);
@mysql_select_db(
$database
)
or
die
(
"Unable to select database"
);
$oldurl
=
"dev.choiceomg.com"
;
$newurl
=
"www.choiceomg.com"
;
$query
=
"SELECT post_content, id from wp_posts where post_content LIKE '%$oldurl%'"
;
$result
= mysql_query(
$query
);
$num
=mysql_numrows(
$result
);
$i
=0;
while
(
$i
<
$num
) {
$id
= mysql_result(
$result
,
$i
,
"id"
);
$post_content
=mysql_result(
$result
,
$i
,
"post_content"
);
$post_content
= mysql_real_escape_string(preg_replace(
"/$oldurl/"
,
"$newurl"
,
$post_content
));
$q
=
"UPDATE wp_posts set post_content = '$post_content' where id = $id"
;
//var_dump($q);
mysql_query(
$q
);
$i
++;
}
$query
=
"SELECT guid, id from wp_posts where guid LIKE '%$oldurl%'"
;
$result
= mysql_query(
$query
);
$num
=mysql_numrows(
$result
);
$i
=0;
while
(
$i
<
$num
) {
$id
= mysql_result(
$result
,
$i
,
"id"
);
$post_content
=mysql_result(
$result
,
$i
,
"guid"
);
$post_content
= mysql_real_escape_string(preg_replace(
"/$oldurl/"
,
"$newurl"
,
$post_content
));
$q
=
"UPDATE wp_posts set guid = '$post_content' where id = $id"
;
//var_dump($q);
mysql_query(
$q
);
$i
++;
}
$query
=
"SELECT meta_id, meta_value from wp_postmeta where meta_value LIKE '%$oldurl%'"
;
$result
= mysql_query(
$query
);
$num
=mysql_numrows(
$result
);
$i
=0;
while
(
$i
<
$num
) {
$id
= mysql_result(
$result
,
$i
,
"meta_id"
);
$post_content
=mysql_result(
$result
,
$i
,
"meta_value"
);
// check if it's serialized
$post_arr
= unserialize(
$post_content
);
if
(
$post_arr
=== false)
$post_content
= mysql_real_escape_string(preg_replace(
"/$oldurl/"
,
"$newurl"
,
$post_content
));
else
{
// its unserializable, iterate through all of array and replace each item
foreach
(
$post_arr
as
$key
=> &
$item
) {
$item
= mysql_real_escape_string(preg_replace(
"/$oldurl/"
,
"$newurl"
,
$item
));
}
$post_content
= serialize(
$post_arr
);
}
$q
=
"UPDATE wp_postmeta set meta_value = '$post_content' where meta_id = $id"
;
//var_dump($q);
mysql_query(
$q
);
$i
++;
}
$query
=
"SELECT option_id, option_value from wp_options where option_value LIKE '%$oldurl%'"
;
$result
= mysql_query(
$query
);
$num
=mysql_numrows(
$result
);
var_dump(
$num
);
$i
=0;
while
(
$i
<
$num
) {
$id
= mysql_result(
$result
,
$i
,
"option_id"
);
$post_content
=mysql_result(
$result
,
$i
,
"option_value"
);
// check if it's serialized
$post_arr
= unserialize(
$post_content
);
if
(
$post_arr
=== false)
$post_content
= mysql_real_escape_string(preg_replace(
"/$oldurl/"
,
"$newurl"
,
$post_content
));
else
{
// its unserializable, iterate through all of array and replace each item
foreach
(
$post_arr
as
$key
=> &
$item
) {
$item
= mysql_real_escape_string(preg_replace(
"/$oldurl/"
,
"$newurl"
,
$item
));
}
$post_content
= serialize(
$post_arr
);
}
$q
=
"UPDATE wp_options set option_value = '$post_content' where option_id = $id"
;
mysql_query(
$q
);
$i
++;
}
</code>
My continous investigation shows this may also be related to a WP security plugin logging WPML activity from both live and staging instances.
Hello Ben Rose
Thank you for the feedback.
The exact ETA will be available later.
When will it be fixed? it's really a big workflow crasher.
Well, from WordPress environment tech standpoint, plesk's staging and syncing functions are useless. as far as I know, leaving serialized data without attention could be a source of problems as well.
I started looking for this issue, because I was working with a staging site lately and realized, that all links lead to the production site, and thanks god I saw that in time, because I was redirected to and working within the production site's wp-admin and since they are clones... it is hard to distinguish them. Huh, that could create a mess.
Hello Ehud Ziegelman,
Provided code replaces URL only in mysql database. Some plugins like "XTemos" store URL's not only inside mysql database but also have URL's inside cache and in different css files.
For this reason replacing URL inside mysql database is not enough to fix the issue.
Please sign in to leave a comment.