- Grew a moustache for the Envato Movember competition
- Community Moderator
- Contributed a Blog Post
- Author was Featured
- Item was Featured
- Won a Competition
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Has been a member for 4-5 years
- 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
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 pageThis can be done with a simple update_option()
Automatically setup all sidebar widgets with default settingsWidgets are stored as a serialized array in the database, it’s not big deal to write a import function for that.
- Grew a moustache for the Envato Movember competition
- Community Moderator
- Contributed a Blog Post
- Author was Featured
- Item was Featured
- Won a Competition
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Has been a member for 4-5 years
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.
- Microlancer Beta Tester
- Sold between 1 000 and 5 000 dollars
- Most Wanted Bounty Winner
- Bought between 10 and 49 items
- Exclusive Author
- Has been a member for 2-3 years
good idea, this helped me too
- Grew a moustache for the Envato Movember competition
- Community Moderator
- Contributed a Blog Post
- Author was Featured
- Item was Featured
- Won a Competition
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Has been a member for 4-5 years
Yer just did this: 
Care to share the code? Also, how do you export widgets and menus?
- Grew a moustache for the Envato Movember competition
- Community Moderator
- Contributed a Blog Post
- Author was Featured
- Item was Featured
- Won a Competition
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Has been a member for 4-5 years
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.
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. 
I need such thing for themeforest themes, anybody knows how to do this? anatoliy.ruchka@gmail.com
