New blog template copies posts but not images to new blogs.dir

I'm setting up a template for a new blog to use all the settings, plugins, posts et al for when a new blog gets created.

Everything gets applied to the new blog no problem, images within posts show fine because their src value is part of the text of the post but, the featured image for a post wont work.

Themes with sliders that use images uploaded to the media gallery or posts with thumbnails wont work on the new blog that was created from a template because those features read only the image name and use the magic of wordpress to change sub.domian.com/files/2010/06/30/file.jpg into sub.domain.com/wp-content/blogs.dir/blogid/files/2010/06/30/file.jpg

can the new blog template plugin also have an option to copy across the images found in blogs.dir/template_blog_id_num/year/day/ of the template blog to the new blogs blogs.dir/new_blog_id_num/year/day/ images folder(s)?

basically, if blog with id 2 was used as a template to create a blog with id 10 then everything in
blogs.dir/2/files/ would get copied to blogs.dir/10/files/

  • fiddyp
    • Site Builder, Child of Zeus

    Ok, so I've added a function to do this myself for now which works dandily (added it after the foreach in set_blog_defaults function).

    Do you imagine it will have this functionality or if there are many more additions to the core code before it becomes v1.0 ?

    I would like to add another option to the admin screen for 'copy template image folders' so I can put the copy files function in the foreach loop of set_blog_defaults by adding another case to the bottom of the switch block but, I think I would be better off waiting until either you add (a less clunky) way of doing it and/or version 1.0 is ready to be called ready (if you know what I mean) :slight_smile:

  • Ben
    • Design Lord, Child of Thor

    I am looking for an answer to this one too. I would like to have the image folders copied somehow for thumbnails etc.

    Not sure how you did it though. Over my head I guess.

    Was thinking of some type of cron job that copies the images to new folders dir folders as they are created.

  • fiddyp
    • Site Builder, Child of Zeus

    I needed the functionality for featured images and other images that aren't part of the theme that is getting copied over because a user may change the theme to another one that has featured images too and also, I wanted them to have access to a set of images that's used by one of the plugins as soon as they start their site.

    It didn't take much to add another case in the switch of set_blog_defaults function and add a checkbox to the admin settings to allow the images folder to also be copied, it helped to have easy to read code in the plugin!

    Its on a live site now and works just fine on the 10 or so blogs that have been created since so I'm happy :slight_smile:

  • fishnyc
    • New Recruit

    I'm trying to figure out the same thing. When I created a new site, the images that were in all the pages (there are no 'posts') are broken. All images were added to the template blog using the pages photo upload and appeared just fine in the gallery and template pages.

    The paths for the new sites images show the new sites domain but the images themselves weren't copied over to the "blogs.dir folder". Hence the broken images.

    I'm in a time crunch here from my client. I would love a tip to figure this out.

    Thanks!

    Fish

  • drmike
    • DEV MAN’s Mascot

    That would be something different actually if you're importing with a xml file and not the blog template plugin. If so, please open up a new thread on the topic. Are you using the built in xml importer from within wordpress? Is so, please note that in your new thread.

  • drmike
    • DEV MAN’s Mascot

    Just to throw this out since no one has mentioned it. Wouldn;t it be a better idea to keep those images in a central location? By duping them, you're using up hard drive space, especially if you have lots of signups that never get used.

  • fiddyp
    • Site Builder, Child of Zeus

    Aaron,

    so sorry, I've been away with the fairies working on stuff in my cave so I didn't see any replies until now.

    I'll incorporate the new update to my modded file and then send it over to you when I get back from business next week.

    Andy

  • Marty Thornley
    • Site Builder, Child of Zeus

    This is a version I am using. It does not have the option to move images, it just moves entire "files" directory of the template blog. I only use one template and definitely wanted to move the whole content folder so I didn't put the time into adding the checkbox. What it does is move the "blogs.dir/TEMPLATEID/files" folder into the "blogs.dir/NEWBLOGID/files" folder.

    So for anyone who wants to move the entire content with each template, here you go...

    This works for me and is in use on a live site, tested many times - but no warranties about it working for you. :slight_smile:

    Instructions....
    I did this as a plugin to the plugin so the original was barely touched. Somewhere around line 315 in blog_templates.php you should see a "restore_current_blog()". Directly before that, I placed this:

    $template_id = $template['blog_id'];
    do_action('blog_templates_do_copy_action_after',$template_id);

    Then you can rename the attached "blogtemplates-copy-content.txt" to be a .php and upload into 'mu-plugins' and it hooks in at the right place.

  • fiddyp
    • Site Builder, Child of Zeus

    thanks Marty! your solution seems to be less intrusive that all the edits I did to the original plugin file.

    sorry to the others,I forgot I was going to send the edits I did. I really should check back on these forums more often!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.