CodeCanyon

WP: An easy way to setup theme default content?

2333 posts
  • Grew a moustache for the Envato Movember competition
  • Community Moderator
  • Elite Author
  • Contributed a Blog Post
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 4-5 years
+8 more
dtbaker moderator says
Unfortunately the WP content import features are not doing it for me. So have any authors found a nice solution for the below in their themes?
  • Create default pages with demo content
  • Create default posts, categories, comments, with media and thumbnails assigned, etc..
  • Automatically setup all sidebar widgets with default settings
  • Automatically create menus and assign them to theme menu positions
  • Change wordpress reading settings to static front page

Ideally I would like a button called “Setup Demo Content” that does all the above automatically. Buyers can click this button after installing my theme and instantly receive a complete replicate of the demo website. Even better would be a button called “Remove Demo Content” that could remove any unchanged demo content, and return settings (eg: reading) to their pre-demo state (big ask!).

Anyone seen a plugin like this? Or know an author who does this in their themes?

Cheers!
dtbaker

163 posts Challenge accepted.
  • Microlancer Beta Tester
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 10 and 49 items
  • Austria
  • Has been a member for 4-5 years
  • Exclusive Author
  • Referred between 100 and 199 users
bloooming says

I haven’t seen a plugin doing that, you’ll have to write it yourself I’m afraid.

You can include the WordPress importer plugin into your theme, and call it programmatically.

It already does this:
  • Create default pages with demo content
  • Create default posts, categories, comments, with media and thumbnails assigned, etc..
  • Automatically create menus and assign them to theme menu positions

You’ll need a demo site where the importer fetches the media images from.

The remaining tasks can be done easily:

Change wordpress reading settings to static front page
This can be done with a simple update_option()
Automatically setup all sidebar widgets with default settings
Widgets are stored as a serialized array in the database, it’s not big deal to write a import function for that.
2333 posts
  • Grew a moustache for the Envato Movember competition
  • Community Moderator
  • Elite Author
  • Contributed a Blog Post
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 4-5 years
+8 more
dtbaker moderator says

ahh I didn’t know that could import menu’s too. last time I tried (a while back) it didn’t

yer thinking I’ll be writing an importer of my own.

321 posts
  • Microlancer Beta Tester
  • Sold between 5 000 and 10 000 dollars
  • Most Wanted Bounty Winner
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
kaaz says

good idea, this helped me too

2333 posts
  • Grew a moustache for the Envato Movember competition
  • Community Moderator
  • Elite Author
  • Contributed a Blog Post
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 4-5 years
+8 more
dtbaker moderator says

Yer just did this:

690 posts
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
  • Exclusive Author
  • Bought between 10 and 49 items
  • Poland
  • Referred between 10 and 49 users
pogoking says

Care to share the code? Also, how do you export widgets and menus?

2333 posts
  • Grew a moustache for the Envato Movember competition
  • Community Moderator
  • Elite Author
  • Contributed a Blog Post
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 4-5 years
+8 more
dtbaker moderator says

Menu’s are exported with the standard wordpress export (with posts, pages, etc..)

To export all the widget positions, and then the settings for each widget in these positions, use code similar to this:

$widget_positions = get_option('sidebars_widgets');
$widget_options = array();
foreach($widget_positions as $sidebar_name => $widgets){
    if(is_array($widgets)){
        foreach($widgets as $widget_name){
            $widget_name_strip = preg_replace('#-\d+$#','',$widget_name);
            $widget_options[$widget_name_strip] = get_option('widget_'.$widget_name_strip);
        }
    }
}
print_r($widget_positions);
print_r($widget_options);

Importing the widget settings once they have been exported is slightly trickier (trying not to overwrite any existing widget settings) but involves a bunch of update_option() calls similar to the above.

The menu’s are imported, but the actual menu assignment (the drop down on the left where you choose which menu goes where) does not get imported. To set the menu code do something like this:

// assign the menu named "Main Menu" to the primary nav area, assign the menu named "Footer Menu" to the footer nav area.
$menus = get_terms('nav_menu');
$save = array();
foreach($menus as $menu){
    if($menu->name == 'Main Menu'){
        $save['primary'] = $menu->term_id;
    }else if($menu->name == 'Footer Menu'){
        $save['footer'] = $menu->term_id;
    }
}
if($save){
    set_theme_mod( 'nav_menu_locations', array_map( 'absint', $save ) );
}

no time to release this as a plugin, but it would be a rather cool plugin to have (ie: ability to export/import menu and widget settings)

maybe I’ll get to release it one day after I clone myself.

690 posts
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
  • Exclusive Author
  • Bought between 10 and 49 items
  • Poland
  • Referred between 10 and 49 users
pogoking says

Thanks for the tips mate, I’ll definitely try this out in the future. I don’t think there is a need to release a plugin for this, it’d be better to contact the devs that work on the WordPress exporter / importer and help them instead. :)

1 post
  • Bought between 1 and 9 items
  • Has been a member for 1-2 years
finfort says
http://www.woothemes.com/theme-demo-content/

I need such thing for themeforest themes, anybody knows how to do this? anatoliy.ruchka@gmail.com

by
by
by
by
by