[Plugin: Blog Copier] [Patch] Replace both http and https URLs when copying posts
-
(I didn’t see a Trac component for
blog-copierso I’m submitting my patch here.)In our case, our network had been changed at some point from using
httptohttps. 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 withgit format-patchon my local repo so let me know if it doesn’t play nice withpatch -p3orsvnand 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
The topic ‘[Plugin: Blog Copier] [Patch] Replace both http and https URLs when copying posts’ is closed to new replies.