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

Follow

Comments

6 comments

  • Avatar
    Ben Rose

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

    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
    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
    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
    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