After synchronizing or cloning WordPress instance via WordPress Toolkit in Plesk, few URLs in target instance point to source WordPress instance

Follow

Comments

8 comments

  • Avatar
    Elijah Bozin

    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.

    0
    Comment actions Permalink
  • Avatar
    Ehud Ziegelman

    Hi Ivan Postnikov and Benjamin Wessel,

    Any news?

     

     

    0
    Comment actions Permalink
  • Avatar
    Ehud Ziegelman

    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($databaseor 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>

    0
    Comment actions Permalink
  • Avatar
    Ehud Ziegelman

    My continous investigation shows this may also be related to a WP security plugin logging WPML activity from both live and staging instances.

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    Hello Ben Rose

    Thank you for the feedback.

    The exact ETA will be available later. 

    0
    Comment actions Permalink
  • Avatar
    Ben Rose

    When will it be fixed? it's really a big workflow crasher.

    0
    Comment actions Permalink
  • Avatar
    Alex

    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.

     

     

    0
    Comment actions Permalink
  • Avatar
    Pavel Rozental

    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.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request