WordPress.org

Forums

Blog Copier
[Patch] Replace both http and https URLs when copying posts (2 posts)

  1. dzachary
    Member
    Posted 2 years ago #

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

  2. dzachary
    Member
    Posted 2 years ago #

    Well that didn't format very nicely. :) Let me know if you want it submitted by other means.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Blog Copier
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic