Applicable to:
- Plesk for Linux
Symptoms
-
Production WordPress site contains links to staging site after synchronization of WordPress site via WordPress Toolkit, going to Domains > staging.example.com > Sync
-
The WordPress staging site has cache plugins and it might have a cache folder like
wp-content/cache
folder
Cause
The WordPress cache from the staging site was copied to the production site when the WordPress synchronization was performed via WordPress Toolkit.
Resolution
Click on a section to expand
-
Go to Tools & Settings > Scheduled Tasks > Add Task > Disable Active option > Task type: Run a command > System user: root:
-
Fill the Command field with the following and click Run Now to get the WordPress instance ID:
CONFIG_TEXT: DOMAIN='example.com'; /usr/sbin/plesk ext wp-toolkit --list | egrep $DOMAIN | awk '{print "ID: "$1"\nURL: "$8}'
* Where
example.com
is the affected domain -
If the WordPress instance is handled by WordPress Toolkit, the task executed will return the ID and the Website URL:
-
Fill the Command field with the following and click Run Now to clear cache from the WordPress instance:
CONFIG_TEXT: ID='4'; /usr/sbin/plesk ext wp-toolkit --clear-cache -instance-id $ID
* Where
4
is the WordPress ID of the affected instance -
Once the WordPress cache will be cleared via WordPress Toolkit, the following result will be shown:
-
Click on Cancel to don't save the Scheduled Task:
-
Connect to the server via SSH
-
Get the WordPress instance ID of the production site:
# DOMAIN='example.com'; plesk ext wp-toolkit --list | egrep $DOMAIN | awk '{print "ID: "$1"\nURL: "$8}'
ID: 4
URL: https://example.com -
Clear cache from the WordPress instance with the ID returned in previous step:
# plesk ext wp-toolkit --clear-cache -instance-id 4
Comments
2 comments
Hi Marc Vidal ,
The problems seems not to be ralted to cache as presented in the solution. I'm afraid clearing cache is NOT the solution.
See a simillar problem:
https://support.plesk.com/hc/en-us/articles/360015830933--BUG-After-synchronizing-or-cloning-WordPress-instance-via-WordPress-Toolkit-in-Plesk-few-URLs-in-target-instance-point-to-source-WordPress-instance
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>
Hi Marc Vidal ,
Please note I had to click CANCLE in order to get instance ID numbers, and that script did NOT finish running on its own.
Please sign in to leave a comment.