0

I have a large .xml (WXR) export from a historic WordPress site (6,000+ posts).

I have installed the WordPress Importer plugin, and I'm able to use it to import the file.

Whilst all posts' text gets successfully imported, zero images are imported. I think this may be because all of the original images attached to posts have changed remote location (the .xml file contains locations for the attached images, not the images themselves, of course).

The new location may be predictable through a pattern, however. Indeed, one of the site admin's last acts was to write a script that filters post bodies in the_content using regexes to dynamically rewrite image URLs as the new ones locations. Image locations referred to in post content are unchanged, they are just rewritten.

However, I don't want to leave the images on the server in this way. What I'm asking is, is it possible for me to hook/filter the WordPress Importer .xml import process, rewriting the image URLs at the point of import so that actual images import to my new site from true current locations?

Frankly, the structure of a WXR .xml file is cryptic. That's because a) the position containing image details seems to vary, and b) what the value holds is CDATA. I can deduce, however that the original image in question is the one prefixed below by "s:74:"

<wp:meta_value>
  <![CDATA[a:7:{
  s:7:"primary";
  s:91:"http://originalsite.files.wordpress.com/2012/06/screen-shot-2012-06-13-at-14-07-52.png";
  s:6:"images";
  a:2:{
   s:74:"http://originalsite.files.wordpress.com/2012/06/file-name-510-post.jpg";
   a:6:{
    s:8:"file_url";
    s:74:"http://originalsite.files.wordpress.com/2012/06/file-name-510-post.jpg";
    s:5:"width";
    s:3:"413";
    s:6:"height";
    s:3:"298";
    s:4:"type";
    s:5:"image";
    s:4:"area";
    s:6:"123074";
    s:9:"file_path";
    s:0:"";}
    s:91:"http://originalsite.files.wordpress.com/2012/06/screen-shot-2012-06-13-at-14-07-52.png";
    a:6:{
      s:8:"file_url";
      s:91:"http://originalsite.files.wordpress.com/2012/06/screen-shot-2012-06-13-at-14-07-52.png";
      s:5:"width";
      s:4:"1001";
      s:6:"height";
      s:3:"773";
      s:4:"type";
      s:5:"image";
      s:4:"area";
      s:6:"773773";
      s:9:"file_path";
      s:0:"";
    }
  }
  s:6:"videos";
  a:0:{
  }
  s:11:"image_count";
  s:1:"2";
  s:6:"author";
  s:5:"23601";
  s:7:"blog_id";
  s:8:"33319749";
  s:9:"mod_stamp";
  s:19:"2012-06-13 13:42:09";
}]]>
</wp:meta_value>
    </wp:postmeta>

The question is, (how) can I hook/filter the import process and, if so, how can I isolate and rewrite this URL?

I have explored using my WPAllImport plugin, which is great - but I feel the unpredictable position of the meta_value, coupled with the CDATA issue, pose problems to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.