Title: [Plugin: Blog Copier] [Patch] Replace both http and https URLs when copying posts
Last modified: August 20, 2016

---

# [Plugin: Blog Copier] [Patch] Replace both http and https URLs when copying posts

 *  [dzachary](https://wordpress.org/support/users/dzachary/)
 * (@dzachary)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-blog-copier-patch-replace-both-http-and-https-urls-when-copying-posts/)
 * (I didn’t see a Trac component for `blog-copier` so I’m submitting my patch here.)
 * In our case, our network had been changed at some point from using `http` to `
   https`. Because of that, post content existed with both schemes and the blog-
   copier plugin didn’t catch the former when performing the replace.
 * I’ve modified `BlogCopier->replace_content_urls()` to perform the replace twice,
   once for the current site-URL configuration and once for the alternate scheme.
   The patch was generated with `git format-patch` on my local repo so let me know
   if it doesn’t play nice with `patch -p3` or `svn` and I’ll generate a new one.
   The changes are pretty minor however, a few lines.
 * Thanks for your plugin! It saved me buckets of time. 🙂
 * > `
   >  diff --git a/wp-content/plugins/blog-copier/blog-copier.php b/wp-content/
   > plugins/blog-copier/blog-copier.php index f8be63e..cef76ee 100644 --- a/wp-
   > content/plugins/blog-copier/blog-copier.php +++ b/wp-content/plugins/blog-copier/
   > blog-copier.php @@ -363,9 +363,17 @@ if ( !class_exists('BlogCopier') ) { $
   > to_blog_prefix = $this->get_blog_prefix( $to_blog_id ); $from_blog_url = get_blog_option(
   > $from_blog_id, 'siteurl' ); $to_blog_url = get_blog_option( $to_blog_id, 'siteurl');-
   > $query = $wpdb->prepare( "UPDATE {$to_blog_prefix}posts SET post_content = 
   > REPLACE(post_content, '%s', '%s')", $from_blog_url, $to_blog_url ); - do_action('
   > log', $query, $this->_domain); - $wpdb->query( $query ); + + // Replace both
   > http and https URLs + $url_parts = parse_url($from_blog_url); + $scheme = strtolower(
   > $url_parts['scheme']); + $other_from_blog_url = ($scheme == 'http' ? 'https':'
   > http') . substr($from_blog_url, strlen($scheme)); + + foreach (array($from_blog_url,
   > $other_from_blog_url) as $target_blog_url) { + $query = $wpdb->prepare( "UPDATE{
   > $to_blog_prefix}posts SET post_content = REPLACE(post_content, '%s', '%s')",
   > $target_blog_url, $to_blog_url ); + do_action( 'log', $query, $this->_domain);
   > + $wpdb->query( $query ); + } }
   >  /**
   >  @@ -415,4 +423,4 @@ if ( !class_exists('BlogCopier') ) { global $BlogCopier;
   > $BlogCopier = new BlogCopier(); } -?> \ No newline at end of file +?> -- 1.7.7.1
 * [http://wordpress.org/extend/plugins/blog-copier/](http://wordpress.org/extend/plugins/blog-copier/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [dzachary](https://wordpress.org/support/users/dzachary/)
 * (@dzachary)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-blog-copier-patch-replace-both-http-and-https-urls-when-copying-posts/#post-2973852)
 * Well that didn’t format very nicely. 🙂 Let me know if you want it submitted 
   by other means.

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Blog Copier] [Patch] Replace both http and https URLs when copying
posts’ is closed to new replies.

 * ![](https://ps.w.org/blog-copier/assets/icon-256x256.png?rev=985730)
 * [Blog Copier](https://wordpress.org/plugins/blog-copier/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/blog-copier/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/blog-copier/)
 * [Active Topics](https://wordpress.org/support/plugin/blog-copier/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/blog-copier/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/blog-copier/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [dzachary](https://wordpress.org/support/users/dzachary/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-blog-copier-patch-replace-both-http-and-https-urls-when-copying-posts/#post-2973852)
 * Status: not resolved